Introduction: Controlling Home Lights With Computer by Using Arduino Mega 2560.
Now a days, technology is spread all around us. We use many gadgets which are a part of technology in our daily routine. This project is generally based on technology in which we control home lightening with our personal computer by sitting around the computer rather than go to a specific room and switch off the lights. We can ON or OFF our home lights by giving commands to our Arduino board which is programmed with a certain code in which all the parameters are defined( i.e which light is operated with which code etc.).
We use Arduino mega 2560 board which contain ATmega2560 microcontroller. Programming for this microcontroller is written generally in C++ language. This language is easy to understand as compared to other high level languages. We make a code in which we define our all parameters and make a suitable condition or a fix variable by giving that specific variable as INPUT to the board through computer runs the board to make a decision of selecting the state of light source (ON/OFF).
Step 1: Requirements
For this Projects we generally require the following components:
1) Arduino Mega 2560 board.
2) one 5mm Red led.
3) one 5mm Green led.
4) one 5mm Blue led.
5) Computer with Arduino IDE software. Download software Here
6) Breadboard and Jumper wires.
Step 2: Circuit Diagram
Make the connection on your breadboard as shown in circuit diagram:
Step 3: Source Code
Open Arduino IDE software in your Computer and make a code as
int led = 8; // red led is named as led and connected at pin 8 to the board
int led1= 9; // Green led is named as led1 and connected at pin 9 to the board
int led2= 10; // Blue led is named as led2 and connected at pin 10 to the board
int ledStates;
int ledState;
void setup() {
pinMode(led, OUTPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
Serial.begin(9600);
}
void loop() {
if (Serial.available() >0)
{
char ledStates = Serial.read(ledState);
}
if( ledState == '0'){
digitalWrite(led, HIGH);
}else{
digitalWrite(led, LOW);
} if (ledState == '1') {
digitalWrite(led1, HIGH);
} else {
digitalWrite(led1, LOW);
}
if (ledState == '2')
{
digitalWrite(led2, HIGH);
}else {
digitalWrite(led2, LOW);
}
}
Step 4: Serial Monitor
Upload this code to your arduino mega 2560 board and open the serial monitor window as shown in the image:
Attachments

Participated in the
Microcontroller Contest 2017
3 Comments
6 years ago
You should really add resistors for the LED's.
Also, your source code has errors, setting the pinmode for the same pin 3 times and omitting led1 and led2.
Lastly, this is hardly controlling any home lights, you're toggling LED's and as such I find the title misleading.
Reply 6 years ago
Thanks for your suggestions.
I make my source code correct , i was just an type error.
and this a module how you can operate your home lights . i represents the light of three different rooms with three seperate led's.
You can control your home lights with same source code with adding some relays and relay driver ic.
Thanks
6 years ago
Nice. One step closer to a fully automated smart house.