Light sensor module (LDR) with TinkerPie
A light-dependent resistor: street lights, sunrise alarms.
| Type | Analog sensors |
|---|---|
| Connect to | P10-P13 |
| Gives | 0-100 % (bright = high) |
| Simulator | Yes: a control appears under the simulated board |
How it works
An LDR (light-dependent resistor) has a material whose resistance falls when light shines on it. The module puts it in a voltage divider, so brighter light gives a higher reading.
How to wire it
Plug the module's A0 / OUT into P10 (or P11-P13 when Wi-Fi is off), VCC to 3.3 V, GND to GND.
Code
In blocks: Accessories category in TinkerPie Studio. As code:
// JavaScript
sensors.lightSensor(Pin.P10)
// Arduino C++
sensors::lightSensor(Pin::P10) Good to know
- Gives a relative level (0-100 %), not lux.
- Reacts in a fraction of a second.
- Use thresholds, for example "below 30 % turn the lamp on".
Projects with the Light sensor module (LDR)
Similar modules
- Potentiometer (knob)
- Soil moisture sensor
- Sound sensor module
- Gas / smoke sensor MQ-2
- Air quality sensor MQ-135
- Rain drop sensor
- Water level sensor
- Force sensor (FSR)
More projects to try
Questions
Can I try the Light sensor module (LDR) without buying one?
Yes. In TinkerPie Studio the simulator shows a control for it under the board, so you can test your program before you build it.
How do I make a night light with an LDR?
Read the light level in a forever loop. If it is lower than your threshold, switch the LED on; otherwise switch it off. Try it in the Night light project.