Let’s learn to use an LDR sensor or photoresistor with BBC micro:bit.
This is a very simple project. We are going to print “BRIGHT” in the inbuild LED matrix of the micro:bit if there is light in the room or else “DARK” will be printed.
Hardware Required
Circuit
- Connect one of the terminal of LDR to the pin 0 of the micro:bit.
- Then connect the other terminal of the LDR to the 3v of micro:bit.
- Finally, connect a 10k resistor in-between ground of the micro:bit and the pin 0.
Block Code
- Go to this link to download the code https://makecode.microbit.org/_itqDVvhv2aVC
- Or you can use the JavaScript code below.
- Maybe you have to adjust the value 1000 according to your LDR.
JavaScript Code
basic.forever(function () { if (pins.analogReadPin(AnalogPin.P0) <= 1000) { basic.showString("DARK") } else { basic.showString("BRIGHT") } })
Video
To buy electronic components order from UTSOURCE
why do we need the 10k resistor?
The article “LDR with BBC micro:bit” provides a concise and informative guide to using an LDR (Light Dependent Resistor) with the BBC micro:bit. The title clearly indicates the topic, making it easy for readers interested in microcontroller projects involving light sensing. The content likely explains the setup, connections, and coding required to interface an LDR with the micro:bit board. This article appears to offer practical insights for beginners and enthusiasts looking to experiment with sensor-based projects using the micro:bit platform.