The light-dependant resistor (LDR) is a type of input device, which can be used to monitor light levels. Its resistance changes depending on the amount of light. The lower the light level, the higher the resistance.

One end needs to be connected to a + output either from the battery pack or the Crumble and then the other end needs to be connected to an I/O pad (A, B, C or D).

Note: Don’t forget you will need to add batteries.

Screeny Shot 9 Nov 2017, 11.42.17

This is the block that is used to monitor the amount of electricity that will flow to the Crumble. When the LDR’s resistance is high, the analogue value will be low, and when the resistance is low, the value will be high.

Screeny Shot 9 Nov 2017, 11.43.02

In this block of code, we are checking the ‘light level’ by setting it to a variable (t). If the level drops below 190, we will turn all the Sparkles to white. Otherwise we will turn all of the Sparkles off.

This is how the code looks when run on the Crumble.

Where next?

There are loads of great projects that can be completed using an LDR, from a nightlight, to an automatic Halloween decoration!