Introduction: Automated Desk Lamp (with ARDUINO and HC-SR04)hjh

About: I love all things related to electronics . Follow me for awesome instructables. Arduino ,linkit one, pro mini etc. familiar with these microcontrollers .

HELLO...........................AADABH...........................NAMASTE.............

THIS PROJECT IS VERY USEFUL .BY THIS WE COULD BE FREE OF OUR PARENTS CHARGE WHEN WE LEAVE OUR ELECTRONIC APPLIANCES ON AND THEN THEY GET ON........... ON US..........

WHAT IT IS::

IN THIS PROJECT THE ELECTRONIC APPLIANCE IS A LAMP .............

WHEN YOU WILL SIT ON YOUR DESK THE LAMP WILL ILLUMINATE AND WHEN YOU WILL LEAVE YOUR DESK IT WILL TURN OFF

PLEASE VOTE FOR ME IN THE CONTEST

Step 1: PARTS

THIS PROJECT REQUIRES VERY FEW PARTS

1. ARDUINO UNO or NANO/1

2. HC-SR04(ULTRASONIC SENSOR)

3. USB CABLE

4. ARDUINO INSTALLED IN YOUR COMPUTER(1.0.6 OR ABOVE)

5. JUMPER WIRES

6. ANY ELECTRICAL APPLIANCE(I am using a desk lamp)

7. 9V battery

8.BATTERY HOLDER

9. SWITCH

10. BREAD BOARD

Step 2: CODE

const int trig = 2;

const int echo = 3;

const int relay = 4;

long duration, distanceCm;

int limitCm = 15;

void setup() {

Serial.begin(9600);

pinMode(relay, OUTPUT);

}

void loop() {

pinMode(trig, OUTPUT);

digitalWrite(trig, LOW);

delayMicroseconds(2);

digitalWrite(trig, HIGH);

delayMicroseconds(5);

digitalWrite(trig, LOW);

pinMode(echo,INPUT);

duration = pulseIn(echo ,HIGH);

distanceCm = microsecondsToCm(duration);

Serial.print(distanceCm);

Serial.print("CM");

Serial.println();

void checkLimit();

delay(100);

}

void checkLimit(){

if(distanceCm < limitCm){

digitalWrite(relay,HIGH);

}else{

digitalWrite(relay,LOW); }

}

long microsecondsToCm(long microseconds)

{

return microseconds / 29 / 2;

}

THE INO FILE IS GIVEN BELOW FOR EASE(YOU CAN DOWNLOAD IT)

Step 3: UPLOADING THE PROGRAM

1. INSERT YOUR ARDUINO IN YOUR LAPTOP

2.A POP UP WILL COME WHICH WILL SHOW SOMETHING LIKE ...................ARDUINO ON COM3 OR COM1

3. REMEMBER THE COM NUMBER

4.NOW OPEN ARDUINO WINDOW AND FOLLOW THE STEP TOOLS>ARDUINO>SELECT ARDUINO V YOU ARE USING EG. ARDUINO NANO && DO

TOOLS>PORT>SELECT THE COM NUMBER REMEMBERED BY YOU!

5. ON LEFT SIDE OF COMPILE BUTTON THERE IS A UPLOAD ICON CLICK IT

UpLoAdInG..............................

Step 4: CONNECTIONS

1. OPEN YOUR LAMP AND TAKE ANY WIRE ARISING FROM THE BATTERY OF IT EITHER + OR - . I PREFER +

2. CUT IT

3. CONNECT ONE END OF WIRE TO RELAY NORMALLY OPEN PIN

4. AND CONNECT ANOTHER TO THE RELAY COMMON PIN

5. WHEN YOU WILL NOW SWITCH ON YOUR LAMP IT WOULDN'T GLOW

6. CONNECT THE RELAY POWER PINS IN YOUR ARDUINO THROUGH WIRE AT THE PIN 4 OF ARDUINO

7.CONNECT +&- OF HC-SR04 TO +5 VOLT PIN OF ARDUINO AND - TO GND RESPECTIVELY

8.CONNECT THE TRIG PIN OF HC-SR04 TO PIN 2 OF ARDUINO AND ECHO PIN TO PIN 3 OF ARDUINO

ALL CONNECTIONS MADE BY JUMPER WIRE AND FEMALE HEADER

Step 5: FINAL TOUCH

1.PUT YOUR HC-SR04 IN THE CHAIR (refer picture)

2.POWER YOUR ARDUINO

3.I REFER YOU TO PUT A SWITCH WHILE POWERING YOUR ARDUNO

NOW WHEN YOU WILL SIT ON YOUR CHAIR THE LAMP WILL ILLUMINATE

THANK YOU

BYE

PLS VOTE

Step 6: PROS AND COS

PROS

1.RIGHT SITTING POSTURES //sdauiudiiasdiaduiaud9a8ud98u

2.SAVES BATTERY

3. AUTOMATIC

4. USES ARDUINO UNO HENCE NO NEED FOR EXTRA IC'S

5.SIMPLE TO MAKE

COS

1. DELICATE(IF I USE TO OUCH MY ARDUINO IT SHUTS DOWN AND I HAVE TO RESTART IT)

2. NOT WIRELESS

Metal Contest

Participated in the
Metal Contest

Home Automation

Participated in the
Home Automation

Bedroom Contest

Participated in the
Bedroom Contest