π‘ Mobile-Controlled Light using Arduino & Python π±π A Smart Room Automation Project by Piku Mandal
π¨βπ About the Project Hi! Iβm Piku Mandal, a 1st year B.Tech Electrical Engineering student at Ghani Khan Chowdhury Institute of Engineering And Technology (GKCIET), Malda.
This is my mini-project titled βAutomated Roomβ, where I control a relay-connected light using a mobile phone via a custom web interface built using Python Flask, with no Bluetooth or Wi-Fi module required.
π― Objective To remotely switch ON/OFF a room light using a mobile phone browser, where the phone sends the signal to a laptop server, and the laptop forwards that signal via USB serial to the Arduino, which controls the light using a relay module.
π οΈ Components Used Arduino Uno
Relay Module
Mobile Phone (with Wi-Fi)
Laptop (running Flask + Python)
USB cable (Arduino to laptop)
π Step 1: Connect Relay/LED to Arduino Use the following pin connection for the relay module:
nginx
Copy
Edit
Relay IN β Arduino Pin 8
Relay VCC β 5V
Relay GND β GND
You can connect a 220V light bulb to the relay using the COM and NO terminals.
π¨βπ» Step 2: Upload Arduino Code Upload this code to your Arduino using the Arduino IDE:
cpp Copy Edit String voice;
void setup() { Serial.begin(9600); pinMode(8, OUTPUT); // Relay or LED pin digitalWrite(8, LOW); }
void loop() { if (Serial.available()) { voice = Serial.readStringUntil('\n'); voice.trim(); // Remove newline/space
if (voice == "ON") {
digitalWrite(8, HIGH); // Light ON
} else if (voice == "OFF") {
digitalWrite(8, LOW); // Light OFF
}
} } β Step 3: Python Flask Web Interface Save the following code as web_arduino_control.py on your laptop:
python Copy Edit from flask import Flask, request, render_template_string import serial
arduino = serial.Serial('COM3', 9600)
app = Flask(name)
HTML = """
<title>Automated Room - Piku Mandal</title> <style> body { background: #f2f2f2; font-family: Arial, sans-serif; text-align: center; padding-top: 50px; } .container { background: white; display: inline-block; padding: 30px; border-radius: 20px; box-shadow: 0 0 20px rgba(0,0,0,0.1); } h1 { color: #007acc; margin-bottom: 10px; } h2, h3 { margin: 5px 0; } button { font-size: 24px; padding: 15px 30px; margin: 20px; border: none; border-radius: 10px; background-color: #007acc; color: white; cursor: pointer; } button:hover { background-color: #005f99; } </style>@app.route("/", methods=["GET", "POST"]) def control(): if request.method == "POST": cmd = request.form["command"] arduino.write((cmd + '\n').encode()) return render_template_string(HTML)
if name == "main": app.run(host="0.0.0.0", port=5000) β Step 4: Run the Project
- Install required Python libraries: bash Copy Edit pip install flask pyserial
- Replace COM3 with your actual Arduino port (like COM4).
- Run the server: bash Copy Edit python web_arduino_control.py π± Step 5: Control from Your Phone Connect your mobile and laptop to the same Wi-Fi network.
On your laptop, check your IP address using:
nginx Copy Edit ipconfig (on CMD) Open browser on mobile and go to:
cpp Copy Edit http://:5000 Example: http://192.168.1.5:5000
Tap "Turn ON Light" or "Turn OFF Light" to control the bulb in real-time!
π Conclusion This project showcases a low-cost, easy-to-build smart room automation system using Arduino and Python, without needing expensive modules or IoT devices.
π‘ Want to expand it? You can add:
Fan control
Multiple rooms
Google Assistant integration
Voice input via mobile
π Credits Project by: π¨βπ Piku Mandal π 1st Year, B.Tech in Electrical Engineering π« Ghani Khan Chowdhury Institute of Engineering and Technology (GKCIET) π Semester 2