//filename: ESP32 WiFi test and temperature monitor test(2022.11.25)
/*
PIR sensor tester
*/
int ledPin = 13; // choose the pin for the LED
int inputPin = 2; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input
Serial.begin(9600);
}
void loop() {
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
if (pirState == LOW) {
// we have just turned on
Serial.println("Motion detected!");
// We only want to print on the output change, not state
pirState = HIGH;
}
} else {
digitalWrite(ledPin, LOW); // turn LED OFF
if (pirState == HIGH) {
// we have just turned of
Serial.println("Motion ended!");
// We only want to print on the output change, not state
pirState = LOW;
}
}
}
/*
#include "WiFi.h"
const char ssid[]="張俊隆 的 iPhone"; //修改為你家的WiFi網路名稱
const char pwd[]="0922909128"; //修改為你家的WiFi密碼
void setup() {
// put your setup code here, to run once:
//Show ESP32 connected
Serial.begin(115200);
Serial.println("Hello, Vincent's ESP32!");
WiFi.mode(WIFI_STA); //設置WiFi模式
WiFi.begin(ssid,pwd);
/*
//當WiFi連線時會回傳WL_CONNECTED,因此跳出迴圈時代表已成功連線
while(WiFi.status()!= WL_CONNECTED){
Serial.print(".");
delay(1000);
}
}
*/
/*
void loop() {
// put your main code here, to run repeatedly:
int EnableResultD2 = digitalRead(2);
int PhotoResistorRresultD4 = digitalRead(4);
//read enable and photo resistor signals
Serial.print("Enable ON: ");
Serial.println(EnableResultD2);
Serial.print("Photo resistor ON: ");
Serial.println(PhotoResistorRresultD4);
delay(1000);
// if ( resultD2 >= 1)
if ( ( PhotoResistorRresultD4 == 0 ) && (EnableResultD2 == 1 ) )
{
Serial.println("Alert!");
//digitalWrite(12, HIGH); //set buzzer ON
tone(22, 300, 250); // Plays 300Hz tone for 0.250 seconds
}
if ( PhotoResistorRresultD4 == 1 )
{
Serial.println("Safe.");
}
}
*/