Introduction: Controlling Home Lights With Computer by Using Arduino Mega 2560.

About: M.Sc Physics, B.Ed, B.Sc.

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:

Microcontroller Contest 2017

Participated in the
Microcontroller Contest 2017