arduino + photoresistor + led
i spent a little time last night playing with arduino and i thought i’d share this little experiment i put together.
Arduino + Photo Resistor + LED from Joshua McGinnis on Vimeo.
here’s the source:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | /* * Power LED on Dark by Joshua McGinnis * * This basic example uses a photo resistor to determine * whether light is present or not. If it is not, an led * will be set to high. * * http://www.joshuamcginnis.com */ int photoPin = 1; // designate pin 1 as the analog in for the photo resitor int val = 0; int ledPin = 13; // designate pin 1 as the analog in for the photo resitor void setup() // run once, when the sketch starts { Serial.begin(9600); pinMode(ledPin,OUTPUT); // set the pin pinMode(photoPin,OUTPUT); // set the pin } void loop() // run over and over again { val = analogRead(photoPin); // set val equal to the resitor input if(val == LOW) { // if nothing from photo resistor (low light), turn on led digitalWrite(ledPin, HIGH); delay(500); } else { digitalWrite(ledPin, LOW); } Serial.println(val); } |
Enjoy this Post?
Spread the word by promoting this post on FaceBook and Twitter.

Very cool stuff man… I just got my arduino trying to see all the different things people are doing with them..
-ril3y
http://www.synthetos.com
Hello, I copied and pasted your code above into the IDE and recieve this error:
In function ‘void setup()’:
error: ‘ledPin2′ was not declared in this scope
Do we need to initialize an “ledpin2″ like you did for ledPin?
pinMode(ledPin2,OUTPUT); // set the pin
should be
pinMode(photoPin,OUTPUT); // set the pin
thanks!
Its called a protoSheild not a borduino….but a borduino may be another name……
you really should have a current limiting resistor on your LED — (see how bright it gets in your demo video). Try something in the range of 330ohms or so to prevent damage to your board. that, or use pwm.