Monday, March 23, 2015

Automatic Night Lamp Using Arduino


component required. 1. arduino uno 2. light dependent resistor, 3. 15 k resistor 4. 330 ohm resistor 5. jumpers 6. breadboard automatic night lamp is an electronic circuit which turn itself on at night time and turns off at day time. the sensor used here is called ldr. the resistance value of ldr increases in night time and decreases in day time.
steps -> use 15k resistor and LDR as voltage divider circuit ..ie one end of ldr and resistor are connected to each other in series in breadboard -> connect +5 volt of arduino to the remaining end of 15 k resistor -> connect ground of arduino to the remaining end of the LDR -> connect the joint of LDR and Resistor to the A0 of the arduino which is analog to digital converter of the arduino -> connect a led anode to the 13 pin of digital i/o of arduino -> connect the arduino to your PC and open arduino ide -> write the following code to you arduino ide and upload it to your arduino ...(check the proper com port) int sensePin=0;
int ledPin=13;
void setup()
{analogReference(DEFAULT);
pinMode(ledPin,OUTPUT);
Serial.begin(9600);
}
void loop()
{Serial.println(analogRead(sensePin));
delay(10);
int val=analogRead(sensePin);
if(val>500)
digitalWrite(ledPin,HIGH);
else
digitalWrite(ledPin,LOW);
}
now cover your ldr and see what happens ..the led should glow..and again uncover ldr,then light should turn off. if so , your automatic night lamp is complete. sometimes it doesnot work properly. in this condition open serial monitar..then check the value... again cover the ldr and check the value.. then modify the code just by changing the value in line if(val>500) between the two values while covering and uncovering.. thank you ...

No comments:

Post a Comment