Code:
/**
* @brief Simple example to control two relays using ESP32
* @details This program demonstrates how to control two relays connected to GPIO40 and GPIO39
* of an ESP32 development board.
*
* Made by KinCony IoT: https://www.kincony.com
*/
// Define the GPIO pins for the relays
#define RELAY1_PIN 40 // GPIO40 for Relay 1
#define RELAY2_PIN 39 // GPIO39 for Relay 2
void setup() {
// Initialize the serial communication for debugging
Serial.begin(115200);
Serial.println("ESP32 Relay Control Example");
// Set the relay pins as output
pinMode(RELAY1_PIN, OUTPUT);
pinMode(RELAY2_PIN, OUTPUT);
// Turn off both relays at startup (assuming active LOW relays)
digitalWrite(RELAY1_PIN, HIGH);
digitalWrite(RELAY2_PIN, HIGH);
}
void loop() {
Serial.println("Turning ON Relay 1");
digitalWrite(RELAY1_PIN, LOW); // Activate relay 1
delay(1000); // Wait for 1 second
Serial.println("Turning OFF Relay 1");
digitalWrite(RELAY1_PIN, HIGH); // Deactivate relay 1
delay(1000);
Serial.println("Turning ON Relay 2");
digitalWrite(RELAY2_PIN, LOW); // Activate relay 2
delay(1000);
Serial.println("Turning OFF Relay 2");
digitalWrite(RELAY2_PIN, HIGH); // Deactivate relay 2
delay(1000);
}
1-output.zip (Size: 683 bytes / Downloads: 289)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:
1-output.ino.merged.zip (Size: 179.19 KB / Downloads: 309)
YouTube: https://www.youtube.com/c/KinCony
Online Store: https://shop.kincony.com
Alibaba Store: https://kincony.en.alibaba.com/
Online Store: https://shop.kincony.com
Alibaba Store: https://kincony.en.alibaba.com/

