//when motion is detected light will be on in a room or else the light will be off.
#include <WiFi.h>
const char* ssid = "Wokwi-GUEST";
const char* password = "";
const int relayPin = T4; // Pin connected to the relay module
const int motionSensorPin = T4; // Pin connected to the motion sensor
void setup() {
Serial.begin(115200);
pinMode(relayPin, OUTPUT);
pinMode(motionSensorPin, INPUT);
// Connect to Wi-Fi
Serial.println();
Serial.println("Connecting to WiFi");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
// Check for motion
bool motionDetected = digitalRead(motionSensorPin);
if (motionDetected) {
// Turn on the relay to activate home automation
digitalWrite(relayPin, HIGH);
Serial.println("Motion detected! Turning on lights.");
delay(5000); // Simulate lights being on for 5 seconds
digitalWrite(relayPin, LOW);
Serial.println("Lights turned off.");
}
delay(1000); // Check for motion every second
}