My Cart:

0 item(s) - £0.00
You have no items in your shopping cart.

0

Guide For Automatic Headlights For :MOVE mini

With the nights beginning to get darker we need to ensure the :MOVE mini can continue to explore its surroundings by coding some automatic headlights, so that no matter what time of day or the ambient light levels, :MOVE mini can still find its way.

automatic headlights for move mini microbit main

The idea was to see if we could use the micro:bit’s light sensors to detect when its surrounding become more gloomy and then use this to turn on the ZIP LEDs as well as having them glow brighter as light levels drop further. You can find a link to the completed code at the foot of this resource.

 

What you will need:

You will need to install the Neopixel blocks in the MakeCode Editor for this one but don't worry as it barely takes a second! Simply click on the Advanced options on the left hand side of the coding menu. At the bottom of the new panel there will be an option to add package, type in the Neopixels then click on the package and you are all set.

 

Automatic Headlights For :MOVE mini:

 

We need to write a code that will:

  • Turn the ZIP LEDs on and off and dim or brighten them depending on the surroundings.

automatic headlights for move mini microbit

The on-start section is defining the ZIP LEDs on the Servo:Lite board, all nice and straight forward here. It also creates our first variable of the code namely “pixel array”. This is simply the variable to describe the LEDs we are using.

The Forever loop contains the bulk of the code and continually checks the light level and alter the variable we have entitled “headlights” which sets the brightness of the ZIP LEDs. Both the light level and the brightness of the LEDs we are using in the pixel array can be set from 0 to 255.

So, to set the brightness we first have the micro:bit detect the light level and minus this from 255 to reach the value of “headlights”. Then the micro:bit works out if we need to have the LEDs on or not. The 'else if' statement at the bottom ensures that if the light levels are rated at 85 or above the ZIP LEDs will be switched off again for all that energy saving goodness.

If it is dark however we use the headlights value to set the brightness of the LEDs. If this brightness is so low that it would cause a flicker (around the 44-47 mark) then the code uses a loop to ensure that the LED brightness is always above a set value.

The other thing you might notice is that the “else if” statement turns the LEDs off again at a higher threshold than when they are switched on, this is again to reduce the flickering of the LEDs.

 

Downloads:

You can either produce the code yourself, using the screengrabs above as a guide or download the zip file below which contains the code for the head lights. Once you unzip the file you can either drop it straight onto microbit in file explorer or drop it into the MakeCode Editor for tweaking/viewing.

 

Note: The code and LED Matrix respond better to natural light than artificial and some tweaking may be required to make them work more effectively in your surroundings.

Electronic Project Kits
← Previous Post Next Post →

Leave a Reply