#include <WiFi.h>
// Replace with your network credentials
const char* ssid = "Wokwi-GUEST";
const char* password = "";
// Set the GPIO pins for the relay and LED
const int relayPin = 4;
const int ledPin = 5; // You can choose any available GPIO pin
void setup() {
// Initialize Serial Monitor
Serial.begin(115200);
// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
// Set the relay and LED pins as outputs
pinMode(relayPin, OUTPUT);
pinMode(ledPin, OUTPUT);
// Turn off the relay and LED initially
digitalWrite(relayPin, HIGH);
digitalWrite(ledPin, HIGH);
// Print ESP32 local IP address
Serial.println(WiFi.localIP());
}
void loop() {
// Your automation logic here
// For example, you can turn on the relay and LED
digitalWrite(relayPin, LOW);
digitalWrite(ledPin, LOW);
delay(1000); // Keep the relay and LED on for 1 second
// Then turn off the relay and LED
digitalWrite(relayPin, HIGH);
digitalWrite(ledPin, HIGH);
delay(1000); // Keep the relay and LED off for 1 second
}