Component: Photoresistor

Objectives and Overview

This lesson introduces the photoresistor component. The potentiometer is a commonly used analog input component.

Lesson Objectives

  • Become familiar with the photoresistor component and explain how it’s used for analog input.
  • Understand and explain how the Arduino map() function is used with the photoresistor.

The Photoresistor

You’ve worked with analog input with the potentiometer component. In this project, use a new analog input component called a photoresistor.

Photoresistors are similar to potentiometers in that they are both types of variable resistors and that they can be used in projects as analog inputs. The values of a photoresistor are based on the ambient light, where the amount of resistance decreases as the intensity of ambient light increases.

The photoresistor has only two pins instead of the three on the potentiometer. You’ll need to create a voltage divider circuit to use the photoresistor. You don’t need to worry about how to calculate such a circuit from scratch, as most projects that require one will provide guidance on how to create one.

The photoresistor will be used to gather analog input in a similar way that the potentiometer did. Instead of changing the resistance by turning a knob, the level of ambient light will change the resistance amount produced by the photoresistor.

The photoresistor has two pins and has a white colored top with red “squiggly” lines running across the head. Here is a picture of a photoresistor:

Closeup of a photoresistor component

The polarity of the legs doesn’t matter – there isn’t a positive or negative leg like the LED. However, you’ll need to make sure that you’re building out the circuit correctly as the voltage divider circuit setup is precise.

Project: LED Nightlight

The best way to understand the photoresistor is to jump into a project that uses it! You’re going to make a nightlight: an LED that turns on once the photoresistor registers that the room is dark.

Supplies

Reminder: The 10k Ohm resistor is the brown/black/orange resistor. Here is an image:

10k Ohm resistor (brown/black/orange)
  • Uno and breadboard
  • Jumper wires
  • (New!) Photoresistor
  • 10k Ohm resistor for the Photoresistor
  • LED circuit supplies:
    • LED and 220 (or 560) Ohm resistor

Steps

Use this breadboard diagram as your guide:

Circuit diagram of a voltage divider circuit with a photoresistor and breadboard

The connections are the same as the potentiometer project, except in this the photoresistor replaces the potentiometer. On the broadboard diagram, this box represents the photoresistor:

Photoresistor circuit diagram symbol

Circuit

  • Connect the 5V of the Arduino to the + rail of the breadboard.
  • Connect the GND of the Arduino to the – rail of the breadboard.
  • Attach the photoresistor to the breadboard. The legs of the photoresistor are the same so you don’t need to worry about which leg is which, you just need to make sure that they’re connected as shown on the breadboard.
  • Place the 10kOhm resistor between the power rail and the top leg of the photoresistor.
  • Place 1 jumper wire between the 10kOhm resistor and the top leg of the photoresistor. Connect this jumper wire to the A0 pin on the Arduino board. This is the voltage divider circuit.
    – Look at the breadboard row where the top leg of the photoresistor is connected. Your board should have the 10kOhm resistor going from the power rail to the row with the top of the photoresistor in it, and then next would be the jumper wire that is connected to A0, and then finally the top leg of the photoresistor.
  • Use 1 jumper wire to connect the ground rail to the bottom leg of the photoresistor.

Sketch

You can run the same sketch as you did for the potentiometer! This works because the photoresistor is sending output to the A0 analog input on the Arduino. The only difference is that the values are being sent from the photoresistor instead of the potentiometer. If you’re having any difficulties, double-check to make sure that you’ve placed the photoresistor correctly and that it’s connected to A0 on the Arduino.

New Commands

None! This project introduced a new component with no additional code for the sketch. This demonstrates how you’re able to use a variety of components once you become comfortable with the core Arduino setup.