The circuit in question is designed to control multiple AC loads, including LED bulbs and fans, using an ESP32 microcontroller and a 5V 8-channel relay module. The ESP32 is programmed to interact with the relays, which in turn switch the connected loads. The circuit also includes manual control through rocker switches for each relay channel, providing both automated and manual control capabilities. The system is powered by a 240V power source, which is stepped down to 5V using an adapter to power the ESP32 and the relay module.
/**********************************************************************************
* TITLE: ESP RainMaker + Manual Switch control 8 Relays using ESP32
* (Real time feedback + no WiFi control)
* by Tech StudyCell
**********************************************************************************/
#include "RMaker.h"
#include "WiFi.h"
#include "WiFiProv.h"
// ... (initialization and setup code omitted for brevity)
void setup() {
// Set the Relays GPIOs as output mode
pinMode(RelayPin1, OUTPUT);
pinMode(RelayPin2, OUTPUT);
// ... (additional setup code omitted for brevity)
// Configure the input GPIOs
pinMode(SwitchPin1, INPUT_PULLUP);
pinMode(SwitchPin2, INPUT_PULLUP);
// ... (additional setup code omitted for brevity)
// Write to the GPIOs the default state on booting
digitalWrite(RelayPin1, !toggleState_1);
digitalWrite(RelayPin2, !toggleState_2);
// ... (additional setup code omitted for brevity)
// ... (RainMaker initialization and setup code omitted for brevity)
}
void loop() {
// ... (loop code omitted for brevity)
manual_control(); // Function to handle manual switch control
}
// ... (additional functions and callbacks omitted for brevity)
The provided code snippet is part of a larger program that runs on the ESP32 microcontroller. It initializes the GPIO pins connected to the relay module and the manual switches, sets their default states, and includes a loop function that continuously checks for manual switch activations to control the relays. The full code includes additional setup for the ESP RainMaker platform, which allows for remote control and monitoring of the relays over WiFi.