Micro:bit Experiment 14: Ambient Light —???Elecfreaks Mirco:bit Starter Kit Course

Micro:bit Experiment 14: Ambient Light —???Elecfreaks Mirco:bit Starter Kit Course

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.

Component List:

Hardware:

1 x Micro:bit Board

1 x Micro-B USB Cable

1 x Microbit Breadboard Adapter

1 x Transparent Breadboard - 83 * 55 mm

1 x 8 RGB Rainbow LED Ring

1 x Breadborad jumper wire 65pcs pack

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

Software:

Microsoft Makecode Online Editor

Major Component Introduction

You might be curious how micro:bit senses light without any light sensor. Let'seea 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.

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.

Hardware Connection

Please complete hardware connection according to the picture below.



After connection, you will see:


Programming

Open Microsoft Makecode, write your code in the edit area. I would like to suggest you program by yourself first. Of course, you can see the whole program in the link below. Just click Edit, and then Download, you can download code into micro:bit directly.

Code Explanation

Light Level Find the light level (how bright or dark it is) where you are. The light level 0 means darkness and 255 means bright light. The micro:bit measures the light around it by using some of the LEDs on the LED screen. Clear Set the color value of all RGB LED beads to be 0. Note: Use LED as a light sensor is not sensitive. It requires comparatively brighter light so that light level can change.

Result:

When in darkness, the ring illuminated; while in brightness, the ring extinguished.

1


Question:

If we want to rotate the rainbow color after the ring was illuminated, then how to design circuit and program? We look forward to your comments and further discussions.

Relative Readings:

Start Your Micro:bit Programming Trip Micro:bit Experiment 01: LED Scroller —— Elecfreaks Micro:bit Starter Kit Course Micro:bit Experiment 02: Button —— Elecfreaks Mirco:bit Starter Kit Course Micro:bit Experiment 03: Trimpot —— Elecfreaks Mirco:bit Starter Kit Course Micro:bit Experiment 04: Photocell —— Elecfreaks Mirco:bit Starter Kit Course Micro:bit Experiment 05: RGB LED —— Elecfreaks Mirco:bit Starter Kit Course Micro:bit Experiment 06: Self-lock Switch —— Elecfreaks Mirco:bit Starter Kit Course Micro:bit Experiment 07:Temperature Sensor —— Elecfreaks Mirco: bit Starter Kit Course Micro:bit Experiment 08:Servo —— Elecfreaks Mirco: bit Starter Kit Course Micro:bit Experiment 09:Buzzer —— Elecfreaks Mirco: bit Starter Kit Course Micro:bit Experiment 10: Motor —— Elecfreaks Mirco: bit Starter Kit Course Micro:bit Experiment 11: Rainbow LED Ring —— Elecfreaks Mirco: bit Starter Kit Course Micro:bit Experiment 12: Accelerometer —— Elecfreaks Mirco: bit Starter Kit Course Micro:bit Experiment 13: Compass —— Elecfreaks Mirco: bit Starter Kit Course