An ESP32-based intelligent relay control system with web interface, scheduling capabilities, and real-time monitoring. This versatile automation system can control up to 4 relays independently through a responsive web dashboard, physical switches, or automated schedules.
- 4-Channel Relay Control: Independent control of 4 separate relays for appliances or devices
- Responsive Web Interface: Modern, mobile-friendly dashboard accessible from any device on your network
- Real-Time Updates: WebSocket-based live relay status updates without page refresh
- Physical Switch Override: 4 manual switches with debouncing for direct relay control
- LED Status Indicators: Individual LED for each relay showing current state
- Recurring Schedules: Set up schedules with:
- Specific days of the week (Monday-Sunday)
- Custom on/off times
- Enable/disable functionality
- Up to 10 schedules stored in EEPROM
- Temporary Schedules: One-time schedules that auto-expire after execution
- Flexible on-time, off-time, or both
- Perfect for temporary overrides without affecting recurring schedules
- Multiple temporary schedules per relay
- NTP Time Synchronization: Automatic time sync from NTP servers (IST timezone configured)
- Persistent Storage: Schedules saved to EEPROM, survive power cycles
- Event Logging: Comprehensive logging system with timestamps stored in LittleFS
- System events
- Relay state changes
- WiFi connection status
- Error notifications
- Error Detection & Recovery:
- Visual LED blinking on system errors
- Automatic error detection for WiFi and time sync failures
- Manual error clearing via web interface
- Watchdog Timer: Automatic system restart on hang/freeze
- Dual-Core Processing: Optimized task distribution across ESP32 cores
- Core 0: Network and web server operations
- Core 1: Relay control and scheduling logic
- Basic Authentication: Password protection for web interface
- IP Whitelist: Configure allowed IP addresses for access without password
- Secure Access Control: Two-layer security approach
- ESP32 development board
- 4-channel relay module (active LOW trigger)
- 4 push buttons/switches (for manual control)
- 4 LEDs with appropriate resistors (status indicators)
- Power supply (5V recommended)
- Breadboard and jumper wires (for prototyping)
| Component | GPIO Pin | Description |
|---|---|---|
| Relay 1 | GPIO 13 | First relay control (Socket 1) |
| Relay 2 | GPIO 12 | Second relay control (Socket 2) |
| Relay 3 | GPIO 14 | Third relay control (Socket 3) |
| Relay 4 | GPIO 27 | Fourth relay control (Socket 4) |
| Switch 1 | GPIO 26 | Manual control button 1 |
| Switch 2 | GPIO 25 | Manual control button 2 |
| Switch 3 | GPIO 33 | Manual control button 3 |
| Switch 4 | GPIO 32 | Manual control button 4 |
| LED 1 | GPIO 18 | Status indicator for Relay 1 |
| LED 2 | GPIO 19 | Status indicator for Relay 2 |
| LED 3 | GPIO 22 | Status indicator for Relay 3 |
| LED 4 | GPIO 23 | Status indicator for Relay 4 |
- Arduino IDE 1.8.x or later, or PlatformIO
- ESP32 board support installed
Install the following libraries:
- WiFi (Built-in with ESP32)
- WebServer (Built-in with ESP32)
- WebSocketsServer by Markus Sattler
- ArduinoJson by Benoit Blanchon (version 6.x)
- EEPROM (Built-in)
- LittleFS (Built-in with ESP32)
- TimeLib by Paul Stoffregen
- Ticker (Built-in with ESP32)
-
Clone the Repository
git clone https://github.com/Armaan4477/Smart-Board-Control.git cd Smart-Board-Control -
Configure WiFi Credentials
Open
automation/automation.inoand update:const char* ssid = "Your_WiFi_SSID"; const char* password = "Your_WiFi_Password";
-
Configure Authentication (Optional)
Update login credentials:
const char* authUsername = "admin"; const char* authPassword = "12345678";
-
Configure IP Whitelist (Optional)
Add your device IP addresses to bypass authentication:
const std::vector<String> allowedIPs = { "192.168.1.100", // Your PC "192.168.1.101", // Your Phone };
-
Upload to ESP32
- Select your ESP32 board from Tools > Board
- Select the correct COM port
- Click Upload
-
Monitor Serial Output
- Open Serial Monitor at 115200 baud
- Note the assigned IP address
- Connect to the same WiFi network as the ESP32
- Open a web browser and navigate to:
http://[ESP32_IP_ADDRESS] - Login with configured credentials (if not on whitelist)
- Individual Control: Toggle each relay ON/OFF with dedicated buttons
- Real-Time Status: See current state of all relays
- Visual Feedback: Color-coded buttons (green=ON, red=OFF)
- Current time in HH:MM:SS format
- Current day of the week
- Current date (DD/MM/YYYY)
- Auto-updates every second
- Main Schedules: View and manage recurring schedules
- Temp Schedules: View and manage temporary one-time schedules
- Logs: View system event logs
- Clear Errors: Reset error states
- Navigate to "Main Schedules" page
- Click "Add New Schedule"
- Configure:
- Relay number (1-4)
- On time (HH:MM)
- Off time (HH:MM)
- Days of week (select multiple)
- Enabled status
- Click "Add Schedule"
- Schedule automatically saves to EEPROM
- Navigate to "Temp Schedules" page
- Click "Add Temporary Schedule"
- Configure:
- Relay number (1-4)
- On time (optional)
- Off time (optional)
- Click "Add"
- Schedule executes once and auto-deletes
- Press any switch to toggle corresponding relay
- Debounce delay: 800ms to prevent accidental triggers
- Works independently of web interface
- Override schedules when manually activated
- Navigate to "Logs" page
- View chronological list of events:
- System startup
- WiFi connection status
- Relay state changes
- Schedule executions
- Error conditions
- Maximum 18 log entries stored
Error Indicators:
- All LEDs blink simultaneously (1 second interval)
- Error status visible in web interface
Clearing Errors:
- Click "Clear Errors" button on main page
- Or navigate to
/error/clear - LED blinking stops
- System resumes normal operation
GET /- Main control dashboardGET /mainSchedules- Regular schedules management pageGET /tempschedules- Temporary schedules management pageGET /logs- System logs viewer
GET/POST /relay/1- Control Relay 1GET/POST /relay/2- Control Relay 2GET/POST /relay/3- Control Relay 3GET/POST /relay/4- Control Relay 4GET /relay/status- Get all relay states (JSON)
GET /schedules- Get all regular schedules (JSON)POST /schedule/add- Add new regular schedulePOST /schedule/update- Update existing scheduleDELETE /schedule/delete- Delete scheduleGET /temp-schedules- Get temporary schedules (JSON)POST /temp-schedule/add- Add temporary scheduleDELETE /temp-schedule/delete- Delete temporary schedule
GET /time- Get current system time (JSON)GET /logs/data- Get system logs (JSON)GET /error/status- Get error status (JSON)POST /error/clear- Clear error stateGET /favicon.png- Dashboard favicon
Default: IST (Indian Standard Time, UTC+5:30)
const long gmtOffset_sec = 19800; // Adjust for your timezone
const int daylightOffset_sec = 0; // Daylight saving offsetconst char* ntpServer = "pool.ntp.org"; // Change if neededconst unsigned long watchdogTimeout = 10000; // 10 secondsconst unsigned long DEBOUNCE_DELAY = 800; // 800msconst int MAX_SCHEDULES = 10; // Adjust as needed- Verify SSID and password are correct
- Check if ESP32 is within WiFi range
- Look for "WiFi connection failed" in serial monitor
- System will indicate error with blinking LEDs
- Ensure internet connectivity
- Check NTP server accessibility
- Verify timezone settings
- Error will be logged and LEDs will blink
- Check wiring connections
- Verify relay module is powered
- Test with physical switches first
- Check relay module trigger type (active HIGH/LOW)
- Verify time is synced correctly
- Check schedule is enabled
- Confirm correct days of week selected
- Ensure on/off times are valid
- Confirm ESP32 IP address
- Check if device is on same network
- Try accessing from different browser
- Clear browser cache
- Microcontroller: ESP32 (dual-core, 240MHz)
- Memory:
- EEPROM: 512 bytes (schedule storage)
- LittleFS: Used for log storage
- Network: WiFi 802.11 b/g/n
- Web Server: Port 80 (HTTP)
- WebSocket: Port 81
- Relay Control: Active LOW trigger
- Input Voltage: 5V DC (via USB) or 3.3V (depending on board)
- Maximum Current per Relay: Depends on relay module (typically 10A @ 250VAC)
Smart-Board-Control/
├── automation/
│ └── automation.ino # Main firmware file
├── README.md # This file
└── LICENSE # MIT License
setup()- Initialize hardware, WiFi, and web servermainLoop()- Core 1 task (relay control, scheduling)secondaryLoop()- Core 0 task (network operations)checkSchedules()- Evaluate and execute regular schedulescheckTemporarySchedules()- Evaluate temporary schedulescheckPushButton[1-4]()- Handle physical switch inputshandleRelay[1-4]()- Web interface relay control handlers
- Electrical Safety: Relays can control high voltage AC devices. Ensure proper insulation and wiring.
- Load Ratings: Do not exceed relay module specifications
- Cooling: Ensure adequate ventilation for ESP32 and relay module
- Isolation: Use optocoupler-based relay modules for electrical isolation
- Enclosure: House the system in a proper enclosure when controlling AC loads
- Testing: Test thoroughly with low-voltage devices before deploying with AC loads
This project is licensed under the MIT License. See the LICENSE file for details.