#define BLYNK_TEMPLATE_NAME "Oxygen LevelMonitor"
#define BLYNK_AUTH_TOKEN "qIR3zPs4DzSKptB9gKiDT_HariCQDBBS"
#define BLYNK_TEMPLATE_ID "TMPL3QMH7weTO"
// Include necessary libraries
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <HardwareSerial.h>
// WiFi credentials
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
// Pin configuration
const int pirPin = 15; // Digital pin to which the PIR sensor is connected
int pirValue = 0; // Variable to store the sensor value
BlynkTimer timer; // Blynk timer object
void setup() {
Serial.begin(115200); // Initialize serial communication at 115200 baud
// Connect to Blynk
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
// Set a timer to call sendData every 2 seconds
timer.setInterval(2000L, sendData);
// Set PIR pin as input
pinMode(pirPin, INPUT);
Serial.println("Hello, ESP32!"); // Print a message to indicate the setup is complete
}
void sendData() {
pirValue = digitalRead(pirPin); // Read the digital value from the PIR sensor
// Debugging information
Serial.print("PIR value: ");
Serial.println(pirValue);
Blynk.virtualWrite(V0, pirValue); // Send the sensor value to Blynk
// Check if the sensor value indicates motion and control the LED
if (pirValue == HIGH) {
Serial.println("Motion detected. Turning LED ON.");
Blynk.virtualWrite(V2, 255); // Turn on the virtual LED (255 is the maximum value for the LED widget)
} else {
Serial.println("No motion detected. Turning LED OFF.");
Blynk.virtualWrite(V2, 0); // Turn off the virtual LED
}
}
void loop() {
Blynk.run(); // Run Blynk
timer.run(); // Run the timer
}