Photocells (detect light)

Photocell basics

Photocells (photo resistors) are simple resistive sensors that respond to light. They are often referred to as CdS cells because they are made of Cadmium-Sulfide or LDRs, light-dependant resistors.

For me these are one of the most magical components in your kit.

Photocells are chicklet sized components with a squiggly surface that reminds me of beetle carapaces. They have two legs. You should be able to find several in your kit.

What to they want?

Photocells need light. They are most interesting in environments where light levels change.

Photocells are commonly found in household appliances, particularly nightlights. Almost every nightlight you encounter — especially cheap ones — will have a photocell inside of it. Check the nightlights out the next time you hit a dollar store.

Photocell Representations

Photocells are just fancy resistors so it should not come as a surprise that the base of the symbol is the familiar zigzag of a fixed resistor. The arrows indicate that light falls on the sensor surface. These arrows are the reverse of those found in the LED symbol where light is emitted. As a general rule, a pair of arrows in a symbol represent light. Their direction tell you how the light behaves.

Like fixed resistors, photocells can be placed in a circuit either way — they lack polarity.

Reminder — the symbols for most of the parts in your kit can be found on the back of your resistor color chart.

How do they work?

The resistance of a photocell is light dependant. A small amount of light falling on the surface leads to LARGE resistance. Large amount of light falling on the surface lead to small resistance. Because resistance gets big when light gets small and vice verse we call this an inverse relationship.

Let’s explore.

Parts required

  • breadboard
  • photocells
  • fixed resistor (1k, 10k)
  • single color LED

See it in Action

You can quickly get a sense of how a photocell works by setting up the following circuit.

Cover the photocell or shine light on it from a flashlight (shield the LED with your other hand or a piece of paper so you can see its behaviour when the flashlight is on).

When you cover the photocell its resistance goes up and the LED gets dimmer. When you shine a flashlight on the photocell the resistance drops and the LED gets brighter.

This is the same pattern we saw when we built multiple single LED circuits with fixed resistors of varying sizes and our fixed resistor color mix with RGB – big resistance == dim LEDs.

Photocell as Sensor

The circuit above is fun to play with but it has some limits. We don’t really know anything about the state of the photocell. It can only be wired like this to a low power device (not a motor). We can only have 1:1 relationships between the photocell and the LED. We have to uncouple the photocell from the LED to create more sophisticated experiences.

Let’s move beyond the simple example above and decouple the resistor and the LED electrically. This will allow us to use the photocell as a sensor. Later, we will rejoin them with words.

Understanding how a photocell responds to changing light can be quickly understood by plotting sensor values from analogRead() with the Arduino serial plotter.

Photocell as Analog Input

The circuit below is one of the classic examples of an analog input. Instead of placing the photocell in series with an LED we will will place it in series with a fixed resistor, thus creating a voltage divider.

We will connect the circuit to an Analog In (A0-A5) pin of our Arduino Uno.

pot schematic AI
Add Code

The following code reads the photocell and prints the values to the serial monitor or plotter.

Connect your photocell to pin A0, upload the code below.

Once uploaded, open the Serial Plotter (Tools–> Serial Plotter). You can view it in the Monitor too — but it harder to see the patterns.

// photocell_basic
// tangible
// basic analogRead with photocell circuit

int photocell = A0;
int brightness = 0;

void setup() {
  // put your setup code here, to run once:
   pinMode(photocell, INPUT);
   Serial.begin(9600);
}

void loop() {

  // put your main code here, to run repeatedly:
  brightness = analogRead(photocell);

  Serial.println(brightness);

  delay(10); // slow it down a little

}

Get the code on tangible github.

What to expect

The trace below is a screen cap from my serial plotter while running the above code. The relatively flat parts of the curve on the left and right are from moments when full room (ambient) light fell on the sensor.

The wobbly bit in the middle is from me quickly covering and uncovering the sensor.

Give it a try.

Going further

Ada fruit deep dive into the sensor with detailed info about photocell structure

Leave a Reply

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