#define BLYNK_TEMPLATE_ID "TMPL6zTwVO0mY"
#define BLYNK_TEMPLATE_NAME "Smart Motion Detector 1"
#define BLYNK_AUTH_TOKEN "kXA7AzT1MObBxVnujgzjZghyXH9h3A2b"
#define pyroelectric 14
#define led_y 12 //Define the yellow led pin to 12
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include<DHT.h>
DHT Sensor(5,DHT22);
#define SCREEN_WIDTH 128 // OLED width, in pixels
#define SCREEN_HEIGHT 64 // OLED height, in pixels
// create an OLED display object connected to I2C
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
char auth[] = BLYNK_AUTH_TOKEN;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
//Change the virtual pins according the rooms
#define temp_vpin V0
#define humidity_vpin V1
// This function is called every time the device is connected to the Blynk.Cloud
// Request the latest state from the server
BLYNK_CONNECTED() {
Blynk.syncVirtual(humidity_vpin);
Blynk.syncVirtual(temp_vpin);
}
void setup() {
// Debug console
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
//--------------------------------------------------------------------
Serial.begin(9600);
pinMode(pyroelectric, INPUT);
pinMode(led_y, OUTPUT); //Set pin to output mode
Serial.begin(9600);
// initialize OLED display with I2C address 0x3C
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("failed to start SSD1306 OLED"));
while (1);
}
delay(2000);// wait two seconds for initializing
oled.clearDisplay(); // clear display
oled.setTextSize(1);// set text size
oled.setTextColor(WHITE);// set text color
oled.setCursor(0, 0); // set position to display (x,y)
oled.println("Good"); // set text
oled.println("Morning"); // set text
oled.display(); // display on OLED
}
void loop() {
delay(1000); //It takes 1000ms to wait for the device to read
float tempr = Sensor.readTemperature();
float humid = Sensor.readHumidity();
oled.print("Temp:"); // set text
oled.println(tempr); // set text
oled.print("Humd:");
oled.println(humid);
oled.display(); // display on OLED
delay(10);
oled.clearDisplay();
Blynk.virtualWrite(temp_vpin,tempr);
Blynk.virtualWrite(humidity_vpin,humid);
boolean pyroelectric_val = digitalRead(pyroelectric);
Serial.print("pyroelectric value = ");
Serial.println(pyroelectric_val);
delay(200);
if(pyroelectric_val == 1)
{
digitalWrite(led_y, HIGH);
}else{
digitalWrite(led_y, LOW);
}
oled.println("We welcome you to"); // set text
oled.println("WestFord University College"); // set text
oled.print("Temp:");
oled.println(tempr);
oled.print("Humid:");
oled.println(humid);
oled.display(); // display on OLED
delay(2000);
oled.clearDisplay();
oled.setCursor(0, 0);// set position to display (x,y
}