Skip to content

kasuncsb/Smart-Lamp

Repository files navigation

Smart Lamp Controller

WiFi-enabled smart lamp controller

Smart Lamp Screenshot

Arduino Code:

  • mcu_smartlmp.ino - Main code (recommended)
  • mcu_smartlmp_optimized.ino - Performance optimized version

Control Scripts:

  • lamp_control.bat - Windows batch script
  • lamp_control.sh - Linux/Mac shell script
  • lamp_control.py - Python script (cross-platform)

🔄 Code Versions

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

💻 Control Scripts

After setup, control your lamp easily with these scripts:

Windows (Command Prompt)

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 menu

Linux/Mac (Terminal)

chmod +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 menu

Python (Cross-platform)

pip 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

🌟 Features

  • 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)

🛠️ What You Need

  • ESP8266 board (NodeMCU recommended) - $2-3
  • 5V relay module - $2
  • Buzzer (piezo speaker) - $1-2
  • Jumper wires - less than $1
  • Any AC lamp

🔌 Wiring

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)

⚠️ AC VOLTAGE IS DANGEROUS - Get professional help if unsure!

🚀 Setup

1. Install Arduino IDE

  • 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)

2. Configure WiFi

Open mcu_smartlmp.ino and change:

const char* ssid = "YOUR_WIFI_NAME";
const char* password = "YOUR_WIFI_PASSWORD";

3. Upload Code

  • Connect ESP8266 via USB
  • Select correct Port in Tools → Port
  • Click Upload (→ button)

4. Find IP Address

  • Open Tools → Serial Monitor (9600 baud)
  • Press Reset on ESP8266
  • Note the IP address shown

5. Access Interface

Open web browser and go to the IP address from step 4.

� Troubleshooting

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

⏰ Alarm System

The smart lamp now includes a comprehensive alarm system:

Setting Alarms

  • 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)

Alarm Features

  • 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

Control Scripts - Alarm Commands

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_alarm

Shell 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_alarm

Windows 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_alarm

📄 License

MIT License - Free to use and modify

About

Make your table lamp smart!

Resources

License

Stars

Watchers

Forks

Contributors