Photoresistor controlling LED

With a photo resistor you can control something from your Arduino board depending on light intake. The following circuit shows how to connect your photo resistor to the Arduino board and read the values.

  1. int ledPin = 3;
  2. int photocellInput = 0;
  3.  
  4. void setup()  {
  5.   pinMode(ledPin, OUTPUT);
  6. }
  7.  
  8.  
  9. void loop()  {
  10.  
  11.   photocellInput = (analogRead(0)/4); // Divides input 0-1023 to resemble to 0-255
  12.  
  13.   analogWrite(ledPin, photocellInput);  
  14.   // The delay can be change to get the desired dimming effect
  15.   delay(20);                            
  16. }

2 thoughts on “Photoresistor controlling LED

Leave a Reply to Ali Cancel reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>