17. Lesson 14 Ambient Light#

../../_images/NkZTTdv.jpg

17.1. Introduction#


In our blog micro:bit Experiment 04: Photocell — Elecfreaks mirco: bit Starter Kit Course”, we had connected a photocell externally to sense the light. Actually, micro:bit has integrated a light detection device internally. Today we are going to use the internal light sensor to do an experiment. We will light a rainbow LED ring when the light in the outer environment is comparatively dark.

17.2. Component List#


Hardware:#

  • 1 x micro:bit Board

  • 1 x Micro-B USB Cable

  • 1 x micro:bit Breadboard Adapter

  • 1 x Transparent Breadboard - 83 * 55 mm

  • 1 x 8 RGB LED RainbowLED Ring

  • n x Breadborad Jumper Wire 65pcs Pack

Tips: If you want all components above, you may need Elecfreaks micro:bit Starter Kit .

../../_images/W4tseua.jpg

17.3. Major Component Introduction#


You might be curious about how micro:bit senses light without any light sensor. Let’s see a paragraph about display on micro:bit website:

The display is a 5x5 array of LEDs. It is connected to the micro:bit as a 3x9 matrix. Runtime software repeatedly refreshes this matrix at a high speed, such that it is within the user persistence of vision range, and no flicker is detected. This LED matrix is also used to sense ambient light, by repeatedly switching some of the LED drive pins into inputs and sampling the voltage decay time, which is roughly proportional to ambient light levels.

../../_images/1JzFZG3.jpg

That’s really amazing! Except for its light emitting ability, micro:bit can sense light!Because LEDs are so commonly used as light emitters it is easy to forget that they are fundamentally photodiodes, and as such are light detectors as well.The function may be implemented with no additional hardware cost if incorporated in the LED driver circuit.

17.4. Experimental Procedure#


Hardware Connection#

Connect your components according to the picture below:

  • Connect the signal wire of the LED ring to the P0 port of the breadboard adapter.

../../_images/fKgQRoW.jpg

After connection, we can see:

../../_images/Hacl6BL.jpg

Software Programming#

Click to open Microsoft Makecode, write the following code in the editor.(https://makecode.microbit.org/)

../../_images/JHZUvh2.png

Add Package#

Click “Advanced”in the choice of the MakeCode to find more choices.

../../_images/smtcNoB.png

Click “Extensions”, search “neopixel”in the dialog box and then download the “neopixel”.

../../_images/umQwUC2.png

Program as the picture shows:#

../../_images/AZCjDfR.png

Details for the code:#

  • 1.Set P0 port as the output of the ring signal and set the color mode to RGB.

../../_images/ZlZCHyZ.png

  • 2.When the light level received by micro:bit is lower than 10, the ring lights on in many colors.

../../_images/XoTAOIf.png

Reference#

Links:https://makecode.microbit.org/_Cxo28oDKjLyY

You can also download the links directly:

17.5. Result#


When in darkness, the LED ring will be turned on; while in brightness, the LED ring will be turned off.

../../_images/F9B9ySD.gif

17.6. Exploration#


If we want to rotate the rainbow color after the ring is illuminated, then how to design circuit and program?

17.7. FAQ#