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. }