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