starter kit/Sensing/13. A light sensor and a divider
Sensing · 13 of 16

A light sensor and a divider

The light sensor is a resistor whose value falls as light reaches it. A meter reads voltage, not resistance in a live circuit, so a second resistor turns the change into a voltage. Then a transistor turns that voltage into a lamp that comes on when it gets dark.

You need the transistor circuit working, one light sensor, a 10 kΩ and a 4.7 kΩ resistor, a 220 Ω resistor, a red LED and the meter. The numbers here come from a typical small light sensor, not from yours: the listing does not name the part, so measure yours and use that.

A resistor that listens to light

The light sensor is almost certainly a photoresistor, the brown disc with a wavy track on its face. The track is a light-sensitive material, and light that reaches it frees charge carriers, so current finds an easier way through. In the dark the resistance is huge, a megohm or more. In bright light it falls to a few hundred ohms.

What the light does to the sensor
Light on the sensor
Or any level between300 lux
Light
300 lux
Resistance, illustrative
1.32 kΩ
Condition
daytime indoors, away from the window
Strong light frees so many carriers that the track conducts well. The resistance is a few hundred ohms: not zero, and it stops falling as fast, but a hundred times lower than in the dark. These numbers are a typical small sensor's, not yours: measure yours.

The direction is not in doubt. The size is: a part from another batch can be a few times higher or lower. That is why the first thing to do is measure.

Measure the sensor

Take the sensor out of any circuit, so nothing else is in parallel with it, and power off. Set the meter to resistance and put one probe on each leg. The legs have no polarity, so either way round is right.

  • Cover it with your hand, shutting out the light: write the reading down.
  • Room light, uncovered: write it down.
  • Phone torch a few centimetres from the disc: write it down.

Expect the dark reading to be hundreds of times the torch one. A reading that stays near one value whatever you do means the part is not what this article assumes: go back to a part with no label.

From a resistance to a voltage

A meter on a live circuit reads voltage most easily, and an LED does not care about resistance at all, only about the voltage on its base. So put the sensor in a voltage divider: a fixed resistor from the plus rail to a middle point, the node, and the sensor from the node to ground. The node sits at the sensor's share of the rail.

In the dark the sensor is large, takes most of the rail, and the node is high. In the light the sensor is small and the node falls toward zero.

The fixed resistor decides where on the light scale the node moves most. The output is half the rail when the sensor equals the fixed resistor, so choose a fixed resistor near the geometric mean of your dark and torch readings: multiply them, take the square root. The kit's values are 100 Ω, 220 Ω, 1 kΩ, 4.7 kΩ, 10 kΩ and 1 MΩ; take the nearest. For the sensor modelled here, 10 kΩ is nearest.

Choose the fixed resistor
The fixed resistor, from the rail to the node
Light on the sensor30 lux
Sensor, illustrative
8.3 kΩ
Node reads
2.18 V
Half the rail at
24 lux
With 10 kΩ on top, the output is half the rail at about 24 lux, in the middle of the light a room actually has. The curve is steep where you will use it, so the meter can tell dark, dim and bright apart. This is the choice.

Build the divider

Seat the sensor and the resistor like this, with the power module on its 5 V side. The rail is about 4.8 V, so everything below is calculated with that.

Circuit five, with the meter on it
Light on the sensor
Sensor, illustrative
1.32 kΩ
Meter reads
0.56 V
Current in the loop
424 µA
Bright room: the sensor is about 1.32 kΩ here (yours will differ), so it takes 12 % of the rail and the meter reads 0.56 V. The loop carries 424 µA, far too little to warm anything. Darker light, bigger sensor resistance, higher reading.
  1. A jumper from the plus rail to column 1, row a.
  2. The 10 kΩ from column 1, row c to column 5, row c.
  3. The sensor's legs in column 5, row d and column 7, row d.
  4. A jumper from column 7, row b to the minus rail.

Measure the divider

Meter on DC volts, black lead on the minus rail, red lead on column 5, which is the node. First measure the rail with the same probes on the rail pins, because the node is a share of whatever the rail really is.

  • Covered: close to the rail, 4.5 to 4.9 V.
  • Room light: between the two. On the modelled sensor it sits near 0.5 V in a bright room and near 2 V in a dim one.
  • Torch: close to zero, a few tenths of a volt at most.

Write the three down against your three resistances. Check one with Ohm's law: the node should equal the rail times the sensor over the sum of the two resistors, within the meter's error.

A lamp that comes on in the dark

The node is high in the dark and low in the light, which is the right way round for a lamp. Feed it to the base of the S8050 from the transistor article through a 4.7 kΩ resistor. No pull-down is needed here: the sensor itself, small in the light, holds the base low.

Circuit six, on the breadboard
Light on the sensor
Node, unloaded
2.18 V
Into the base
165 µA
Through the LED
12 mA
Dim room: the sensor is large, the node is 2.18 V and the base gets 165 µA. That asks for more collector current than the 220 Ω lets flow, so the transistor is saturated and the LED is as bright as this circuit makes it, about 12 mA. The rail is 4.8 V.

Keep the divider where it is and add, in the lower half:

  1. A jumper from column 5, row e across the centre channel to column 5, row f.
  2. The 4.7 kΩ from column 5, row j to column 10, row j.
  3. The S8050, flat face towards you, in column 9, row h (emitter), column 10 (base) and column 11 (collector). Check the order with the meter's diode mode, as the last article showed.
  4. A jumper from column 9, row i to the lower minus rail.
  5. The LED: the long leg in column 12, row f and the short leg in column 11, row f.
  6. The 220 Ω from column 12, row g to column 16, row g, and a jumper from column 16, row h to the lower plus rail.

A soft switch

Cover the sensor and the LED lights. Uncover it and it goes out. But slide the light level slowly through the middle and the LED does not snap: it dims.

How soft the switch is
The fixed resistor on the divider
Light on the sensor30 lux
LED current now
12 mA
Full on below
91 lux
Off above
240 lux
The lamp goes from off to full on over about 0.4 of a decade of light: from 240 lux down to 91 lux. That is steep, but it is a ramp, not a step. A transistor amplifies a base current; it does not compare two voltages. Change the fixed resistor and the ramp slides along the light axis, but it does not get sharper. A comparator chip would.

A transistor amplifies a current. It does not compare two voltages. The base current rises smoothly as the node passes about 0.65 V, and the collector current follows, so the LED fades over about half a decade of light. That is good enough for a night light and wrong for anything that must switch cleanly. A chip made to compare two voltages would.

Measure the lamp

With the lamp built, check each state.

  • Covered: the LED is on. The node reads close to the rail. Across the 220 Ω you should read about 2.8 V, which is 12 mA by Ohm's law. Across the transistor's base and emitter, the meter reads about 0.65 V.
  • Room light: the LED is off or very dim. The node is under 0.65 V, so no base current flows.
  • In between: shade the sensor slowly. The LED fades, and the node passes through the base's 0.65 V on the way.

Then change the fixed resistor to the next kit value up and down and find the brightness at which the lamp switches. The bigger one switches in a darker room, the smaller in a brighter one.

When it does not work

The LED never comes on, even with the sensor covered.

Measure the node with the meter while the sensor is covered. It should be close to the rail. If it is, the divider works and the fault is in the transistor half: check the jumper that carries the node across the centre channel, the 4.7 kΩ on the base, the flat face of the transistor and which way round the LED is. If the node is low, the sensor is shorted: both its legs are in one strip.

The LED is on all the time, in the light as well.

A sensor that is not making contact leaves the node connected only to the rail through the 10 kΩ, so the node reads the rail and the transistor is on. Press the legs in, or move them to fresh holes. The same happens if the jumper from the sensor's far leg to the minus rail has come out. Measure the node: in a lit room it should be under half a volt.

The reading drifts, or takes a second or two to settle after I move my hand.

Photoresistors of this kind are slow. They follow light in a fraction of a second but can take seconds to settle after bright light, so the reading creeps. Wait for it to stop before writing a number down. Mains-powered lamps also flicker a little, which the sensor averages out.

The lamp comes on at the wrong light level for my room.

Change the fixed resistor. A bigger one moves the switch point to a darker room, a smaller one to a brighter room: the output is half the rail when the sensor equals the fixed resistor. Take the sensor's resistance in the light level where you want the lamp to switch, and use the kit resistor nearest to it.

Where this goes next

The temperature sensor is the same idea with a different cause: a resistor that changes with heat instead of light.

A thermistor and a divider →

Edit this page — content/books/estkit/a-light-sensor-and-a-divider.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

Ask a question ↗

Electronics Starter Kit, Breadboard, Power Module and Components

Loading discussions…

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Modules and blocks on the forum →