have you ever wondered about the possibility of an
AUTOMATIC LIGHTING SYSTEM? the ability to lighten up your home via
a trigger (not a conventional switch)?
ever went out and forgot to turn off those lights? (ooops, more bills)
anyway, for today's class, we will be addressing just that: the ability to
control your lighting system with a light-dependent resistor (LDR)
YEEEEAAAAHHHHHHHHHH!!!!
"how does it work"? quite simple
the LDR is sensitive to light and comes on when it senses light, and turns
off automatically when there is darkness... "THIS IS AWESOME"
SO WHAT DO WE NEED?
* arduino board+cable
* breadboard
* 220 ohm resistor
* 10k resistor
* LED
* light-dependent resistor
* jumper wire
think...create...repeat
HERE'S THE SKETCH
/* using an ldr to off and ON an led connected to pin 3 of the arduino...
AUTHOR: ANIEROBI PETER
DATE: 4/23/2014
www.hub360.blogspot.com
*/
int ldr =0; //ldr connected to analog pin 0
int led = 3;// led connected to pin 3
int x;
void setup(){
pinMode(ldr,INPUT);
pinMode(led,OUTPUT);
}
void loop(){
x= analogRead(ldr); // read ldr and store in varible x
if(x<100)
{
digitalWrite(led,HIGH); // turn on led when ldr is covered
}
else if(x>100)
{
digitalWrite(led,LOW);//off led when ldr is exposed to light
}
}
THIS IS WHAT YOUR CONNECTION SHOULD LOOK LIKE
VOILA!!!
BE SEEING YOU SOON. TILL THEN,
THINK...CREATE...REPEAT
No comments :
Post a Comment