WiFi-enabled smart lamp controller
Arduino Code:
mcu_smartlmp.ino- Main code (recommended)mcu_smartlmp_optimized.ino- Performance optimized version
Control Scripts:
lamp_control.bat- Windows batch scriptlamp_control.sh- Linux/Mac shell scriptlamp_control.py- Python script (cross-platform)
mcu_smartlmp.ino (Recommended)
- Easy to understand
- Standard Arduino functions
- Perfect for beginners
- Full-featured web interface
mcu_smartlmp_optimized.ino (Advanced)
- Faster performance
- Memory optimized
- For advanced users
After setup, control your lamp easily with these scripts:
lamp_control.bat 192.168.1.100 on # Turn on
lamp_control.bat 192.168.1.100 off # Turn off
lamp_control.bat 192.168.1.100 timer 30 # 30 min timer
lamp_control.bat # Interactive menuchmod +x lamp_control.sh # Make executable
./lamp_control.sh 192.168.1.100 on # Turn on
./lamp_control.sh 192.168.1.100 timer 60 # 1 hour timer
./lamp_control.sh # Interactive menupip install requests # Install dependency
python lamp_control.py 192.168.1.100 on # Turn on
python lamp_control.py 192.168.1.100 status # Check status
python lamp_control.py # Interactive menu- WiFi control via web browser
- Timer function (1 minute to 12 hours)
- Alarm system with real-time clock sync
- Buzzer alerts with customizable patterns
- Mobile-friendly interface with responsive design
- Quick timer presets (1m, 5m, 30m, 1hr)
- Real-time countdown display
- Alarm snooze functionality (5-minute intervals)
- EEPROM persistence for alarm settings
- NTP time synchronization (UTC+5:30 for Sri Lanka)
- Auto-reboot safety (12-hour intervals)
- ESP8266 board (NodeMCU recommended) - $2-3
- 5V relay module - $2
- Buzzer (piezo speaker) - $1-2
- Jumper wires - less than $1
- Any AC lamp
ESP8266 NodeMCU → 5V Relay Module → Buzzer
──────────────────── ───────────────── ─────────
VIN (5V) → VCC
GND → GND → GND
D1 (GPIO5) → IN
D7 (GPIO13) → → Positive (+)
Relay Module → Lamp
───────────── → ────
COM → Live wire (from wall)
NO → Live wire (to lamp)
- Download from arduino.cc
- Add ESP8266 board: File → Preferences → Additional Board Manager URLs:
http://arduino.esp8266.com/stable/package_esp8266com_index.json - Tools → Board → Boards Manager → Install "esp8266 by ESP8266 Community"
- Select: Tools → Board → NodeMCU 1.0 (ESP-12E Module)
Open mcu_smartlmp.ino and change:
const char* ssid = "YOUR_WIFI_NAME";
const char* password = "YOUR_WIFI_PASSWORD";- Connect ESP8266 via USB
- Select correct Port in Tools → Port
- Click Upload (→ button)
- Open Tools → Serial Monitor (9600 baud)
- Press Reset on ESP8266
- Note the IP address shown
Open web browser and go to the IP address from step 4.
WiFi won't connect:
- Check credentials are correct
- Ensure 2.4GHz network (ESP8266 doesn't support 5GHz)
- Move closer to router
Can't upload code:
- Check USB cable and drivers
- Try different COM port
- Hold FLASH button during upload
Relay doesn't work:
- Verify wiring connections
- Check relay power LED
- Test with multimeter
- Use appropriate voltages - 3V VCC 3.3V VIN signal or 5V VCC 5V VIN (via logic level converter)
Can't access web page:
- Check IP address in Serial Monitor
- Ensure device on same WiFi network
- Try different browser
The smart lamp now includes a comprehensive alarm system:
- Web Interface: Use the "Alarm" tab to set date/time
- Command Line: Use control scripts with alarm commands
- Real-time Sync: Automatically syncs with NTP servers
- Timezone: Configured for UTC+5:30 (Sri Lanka)
- Date & Time: Set specific alarm date and time
- Lamp Control: Option to turn lamp on when alarm rings
- Buzzer Alerts: Audio alerts with customizable patterns
- Snooze Function: 5-minute snooze intervals
- Auto-stop: Automatically stops after 13 rings (1 hour)
- Persistence: Alarm settings saved to EEPROM
Python:
python lamp_control.py 192.168.1.100 set_alarm 2024-01-15 07:30
python lamp_control.py 192.168.1.100 stop_alarm
python lamp_control.py 192.168.1.100 snooze_alarmShell Script:
./lamp_control.sh 192.168.1.100 set_alarm 2024-01-15 07:30
./lamp_control.sh 192.168.1.100 stop_alarm
./lamp_control.sh 192.168.1.100 snooze_alarmWindows Batch:
lamp_control.bat 192.168.1.100 set_alarm 2024-01-15 07:30
lamp_control.bat 192.168.1.100 stop_alarm
lamp_control.bat 192.168.1.100 snooze_alarmMIT License - Free to use and modify
