Light sensors – reading in a “range” of values

Note – we suggest you go through the previous post on magnetic reed sensors before doing this one, but if you’re comfortable then feel free to jump right in! To get into more advanced sensors, we need to handle a few electronic components. Here are the main building blocks

Electronics Prototyping Board (or “Breadboard”, because the “holes look like bread”). Evidently, electrical engineers are hungry people, that looks nothing like bread.

Wires, components etc. get plugged in to each of the holes. The breadboard makes it very easy to connect things to each other – each vertical column of 5 is connected to each other and only to each other. So if you wanted to connect a “resistor” in series with a “light-dependent resistor”, it could look like this:

and then I could connect this to something else by adding some wires, like this:

This circuit is called “voltage divider” circuit (youtube it if interested in the details! Briefly, a voltage divider will generate a voltage at the middle pin that changes, depending on the “resistance” values. Since the light-dependent resistor changes resistance levels with the amount of light, the voltage at that middle pin also changes with light). And we can measure the changing voltage with the m5stickc.

To complete the circuit, connect the yellow wire to GND, the red wire to 3V3(which stands for 3.3V), and the purple wire to G36/G25. Inside the orange casing, this socket is connected to two pins – pin 36 AND pin 25, and we need to program it to only “read” values from one at a time.

Note, your wires might be different colours, and that’s fine!!!

Load up this light-dependent resistor (LDR) program – here’s an image of what’s in the program:

This program essentially says “Ignore pin 25”, and “Tell me what value shows up on pin 36”. Pin 36 is specialized to convert an “analog voltage” – a voltage that varies, into a numerical value that can then be digitally displayed. Change the light around the light-dependent resistor and see what values you get on the screen!

Challenge questions!

  • What range of values can you achieve under various lighting conditions at home?
  • Sound your buzzer when it gets too dark!
  • Put up a picture on the screen. Can you change your screen brightness to compensate for the local lighting levels? This is *exactly* the system that most smart phones use – a built-in sensor measures ambient light, and then uses that information to make the screen more comfortable.