#include <Arduino.h>
#include <WiFi.h>
//https://youtu.be/_Plz2Gli6fs?si=PcsjwK1NGo8e_ct0 data to wpp
//#define WIFI_NETWORK "My Network"
//#define WIFI_PASSWORD "nicertry"
//#define WIFI_TIMEOUT_MS 20000
// //void connectToWiFi(){
// Serial.println("Connecting to WiFi");
// WiFi.mode(WIFI_STA);
// WiFi.begin(WIFI_NETWORK, WIFI_PASSWORD);
// unsigned long startAttemptTime = millis();
// while(WiFi.status() != WL_CONNECTED && millis() - startAttemptTime < WIFI_TIMEOUT_MS){
// Serial.print(".");
// delay(100);
// }
// if(WiFi.status() != WL_CONNECTED){
// Serial.println("Failed!");
// //else
// }else{
// Serial.print("Connected!");
// Serial.println(WiFi.localIP());
// }
//}
int pirdata = 3; // pir D is connected to D15
int pirstate = LOW; // assuming no motion
int value = 0; // to read pin status
int led = 13;
void wifiConnect(){
Serial.print("Conectando-se ao Wi-Fi");
WiFi.begin("Wokwi-GUEST", "", 6);
while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.print(".");
}
Serial.println(" Conectado!");
}
void setup() {
Serial.begin(115200);
//connectToWiFi();
wifiConnect();
Serial.println("Presence Sensor Program is Running!");
pinMode(led, OUTPUT);
pinMode(pirdata, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
//ledF();
//copiado
presence();
}
void ledF(){
int x = 0;
for (x; x<2; x++) {
digitalWrite(13, HIGH);
delay(2000);
digitalWrite(13, LOW);
delay(2000);
}
}
void presence(){
value = digitalRead(pirdata);
if (value == HIGH) {
digitalWrite(13, HIGH);
Serial.println("PRESENCE DETECTED!");
delay(3000);
digitalWrite(13, LOW);
pirstate = LOW;
Serial.println("PRESENCE NO MORE DETECTED!");
delay(10000);
if (pirstate == LOW) {
Serial.println("Nothing!");
pirstate = HIGH;
}
}
}