This project demonstrates how to control four relays using an ESP8266 (NodeMCU) and the Arduino IoT Cloud. Relays can be toggled locally via physical switches or remotely through a cloud-based dashboard.
Project website link https://electroiot.in/esp8266-4-relay-iot-control-with-arduino-cloud-push-buttons
- 🛠️ Local Control: Toggle relays with connected switches.
- 🌐 Remote Control: Use the Arduino IoT Cloud dashboard to manage relays online.
- 📶 WiFi Feedback: An LED indicates WiFi connectivity status.
- 🔄 Synchronized State: Updates from manual and remote operations are always in sync.
- ESP8266 (NodeMCU)
- 4-Channel Relay Module
- Push Buttons or Toggle Switches
- Power Supply
- Connecting Wires
- Relays:
- Relay 1: GPIO 5 (D1)
- Relay 2: GPIO 4 (D2)
- Relay 3: GPIO 15 (D8)
- Relay 4: GPIO 13 (D7)
- Switches:
- Switch 1: GPIO 0 (D3)
- Switch 2: GPIO 2 (D4)
- Switch 3: GPIO 14 (D5)
- Switch 4: GPIO 12 (D6)
Install the following libraries from the Arduino IDE Library Manager:
ArduinoIoTCloudArduino_ConnectionHandler
- Create a new "Thing" in the Arduino IoT Cloud.
- Add the following variables:
relay1(type:CloudSwitch)relay2(type:CloudSwitch)relay3(type:CloudSwitch)relay4(type:CloudSwitch)
- Link each variable to a toggle switch on the dashboard.
- Connect the ESP8266 to your computer.
- Upload the provided code after replacing WiFi credentials and Arduino IoT Cloud keys.
Follow the circuit diagram to connect relays, switches, and the ESP8266.
#define RelayPin1 5 // D1
#define RelayPin2 4 // D2
#define RelayPin3 15 // D8
#define RelayPin4 13 // D7
#define SwitchPin1 0 // D3
#define SwitchPin2 2 // D4
#define SwitchPin3 14 // D5
#define SwitchPin4 12 // D6
## 📜 **2. Cloud Integration**
CloudSwitch relay1;
CloudSwitch relay2;
CloudSwitch relay3;
CloudSwitch relay4;
## 📜 **3. Manual Control Logic**
void manual_control() {
if (digitalRead(SwitchPin1) == LOW) {
toggleState_1 = !toggleState_1;
digitalWrite(RelayPin1, !toggleState_1);
relay1 = toggleState_1;
}
// Repeat for other switches...
}
## 📜 **4. Remote Control Logic**
void onRelay1Change() {
digitalWrite(RelayPin1, relay1 ? LOW : HIGH);
}
## 🎥 **Demo**

---
## 💡 **Future Improvements**
1. Add feedback mechanisms for relay states (e.g., LEDs).
2. Expand to control additional devices.
3. Integrate scheduling for automation.
## 💡 📧 ** Contact Us **
📧 Contact Us
For any questions or feedback, feel free to reach out at: [email protected] and [email protected]# ESP8266-NodeMCU-4CH-Relay-Module