Photocells and Photoresistors

Today were going to go over detecting light using and photoresistor and how we can use this information to control something (for this example: LEDS)


The basic idea here is that we can wire the photoresistor in some way so that it creates a voltage divider.  We can then read resultant voltage with our development board.


1X Arduino Compatible Board

1X Jumper Wire Set

2X 220Ω Resistors


1X 10kΩ Resistor

1x Photoresistor



PWM LED: long leg digital- pin 9; short leg 220Ω resistor then to ground

On/off LED: long leg digital- pin 2; short leg 220Ω resistor then to ground


And finally you want to 1 end of the photoresistor to one leg of the 10kΩ resistor.  Now the other leg of the photoresistor connects to power, the other leg of the resistor connects to ground, and the center leg where they are tied together connects to A5.



We will be ultilizing very basic functions such as analog read, analog write (PWM), and digital write.



/*Simple program to show how to use a photo resistor to detect light
 * intesity.  This information can then be used to control an object.
 * In This case 2 LEDS.  1) as an on/off and 2) as a PWM dimming LED

int photoInput = A0; //declares pin as an analog pin 
float photoValue;    //variable used to store analog value 
float photoVoltage;  //analog signal converted into a voltage 
int pwmLED = 6;      //declares digital pin for PWM LED
int onOffLED = 2;    //declares digital pin for on off LED
float lightLimit = 2.5; //threshold to turn on/off LED

void setup() {

void loop() {
  Serial.print("DAC: ");
  Serial.print("     Voltage: ");






Leave a Reply

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