Skip to main content

Using Elecfreaks microbit Smart home kit

Build a Voice-Activated Smart Night Light: A Micro:bit IoT Project for the Home and Classroom

Whether you’re a student looking for a cool weekend project, a parent wanting to spark a child’s interest in engineering, or a STEM maker exploring Internet of Things (IoT) concepts, the Elecfreaks Micro:bit Smart Home Kit http://bit.ly/43ooJF is a fantastic gateway.

Smart home technology isn’t just for big tech companies; it’s something you can prototype right on your dining room table. In this post, we’re refining a project that mimics real-world smart building technology: a Voice-Activated Night Light.

Why Build a Smart Night Light? (Project Motivation)

In the world of professional engineering, the primary goal is often resource efficiency. We don’t just want lights that turn on; we want 'intelligent' systems that minimize energy waste. By building a light that triggers only when it is both dark and detects a presence (noise), students learn the basics of conditional automation.

This project introduces the concept of environmental 'triggers' and demonstrates how hardware can 'decide' to save power based on its surroundings—a key pillar of sustainable IoT design and green energy solutions.


A close-up photograph of a BBC micro:bit inserted into an Elecfreaks Sensor:bit breakout board,


What You’ll Need:


Step 1: Setting Up the Environment

Before coding, you need to tell MakeCode how to talk to the Smart Home sensors.

1. Open a new project at MakeCode for micro:bit

2. Click on Advanced, then Extensions.

3. Search for "smarthome" and select the official Elecfreaks library. This adds custom blocks designed specifically for the kit's light and sound sensors.







Step 2 "Calibration Phase" (The Scientist's Approach)

Before writing the final code, you must determine what "dark" and "noisy" actually look like in your specific environment. I recommend using these values as a starting point:

• Light Level: 50
• Noise Level: 78dB

The Experiment: To make this a true STEM lesson, create a small test script using the show number block to display the current light and noise readings on the micro:bit’s LED matrix. Close the curtains or clap your hands to see how the numbers change. This "Calibration Phase" teaches students the importance of environmental testing and ensures the smart light functions reliably in any room


Step 2: The Logic (The "Brain" of the House)

For this project, we need the micro:bit to make a decision based on two simultaneous conditions: (1) Is it dark? and (2) Is there noise?

Pro-Tip for Makers: To use the LED strip, you must "enable" the LED function on the micro:bit. In MakeCode, click the LED category, then click the [+] or "More" option to find the led enable block.

The Variables

Create three variables to keep your code clean:

  • light: To store the brightness reading.

  • noise: To store the sound level.

  • strip: To control your Rainbow LED.


Step 3: The Code

Logic Explanation: This code block acts as a continuous monitor for the room's environment. It uses a Boolean 'AND' operator to ensure the light only activates when the environment is both dark enough to be considered "night" and loud enough to suggest someone is present. The 10,000ms (10 second) pause serves as a sustain timer, keeping the path illuminated while you walk through the room so you aren't left in the dark the moment you stop making noise.

  • On Start: Initialise your LED strip to the correct pin (usually P1 in the Smart Home kit).

  • Forever Loop:  Set the light variable to the value of the light sensor.

    • Set the noise variable to the value of the noise sensor.

    • The "If" Statement: If light is less than a certain threshold (e.g., 50) AND noise is greater than 78dB, then turn the LEDs on.

    • The Timer: Use a pause block for 10,000ms (10 seconds) so the light stays on while you walk through the room, then turn it off.

Attach the microbit to the sensorbit


Making the voice activated light solution - the first activity follow the circuit in the book


To get "led enable" you will need to click in makecode like on LED option and then + to find it. You will also need to set up three variables light, strip and noise.
Here is the code
A screenshot of Microsoft MakeCode blocks showing a 'forever' loop containing an 'if' statement that checks if light level is less than 50 AND sound level is greater than 78

Only turns on the LED for 10 seconds when the light level is low and noise is above 78dB.


Adaptation: The Dynamic Sound-Reactive Light

l
adapted code
The circuit is the same.

Logic Explanation: In this version, we move from a binary "On/Off" switch to a direct data mapping. The code takes the numerical value from the noise sensor and applies it directly to the LED strip's brightness level. This creates a visual feedback loop where the light glows brighter as the room gets louder, effectively turning the LED strip into a physical "volume meter" for the room.

Troubleshooting Guide

• The Light Stays On Constantly: Your "Light Threshold" might be set too high. If the micro:bit thinks "50" is dark, but your room is naturally at "45," it will always trigger. Lower the number to 30 or 20 and test again.

• The Sensors Aren't Responding: Double-check your pins! The LED strip usually goes to P1 and the Noise sensor to P2. On the Sensor:bit, ensure the yellow wire (Signal) faces the "S" pin.

• LEDs are Flickering or Dim: The Rainbow LED strip is power-hungry. If it flickers, try using a battery pack (3x AAA) plugged directly into the Sensor:bit rather than relying on the computer's USB power.



Why This is Useful for STEM Learning

This project isn't just about making an LED blink; it teaches the fundamental pillars of modern engineering:

  • Sensor Integration: Understanding how machines "sense" the physical world.

  • Boolean Logic: Using "AND/OR" statements to create complex triggers.

  • Threshold Calibration: Students learn that "78dB" or "Light level 50" are variables they must test and adjust based on their specific environment (a great introduction to the scientific method!).


Final Thoughts

The Elecfreaks kit is a "cool set of components" that bridges the gap between screen-based coding and physical reality. Once you've mastered the voice-activated light, try adding the OLED display to show the noise level in real-time, or use the Servo to create an automatic door opener!

Ready to start? Head over to and start building your future home today.







All opinions in this blog are the Author's and should not in any way be seen as reflecting the views of any organisation the Author has any association with. Twitter @scottturneruon

Comments

  1. I came across DealPromoX a few days ago while searching for some working promo codes, and I was actually impressed. Most of the discounts listed there still work, and the site seems to be updated regularly. It’s definitely worth checking if you like finding good online deals.

    ReplyDelete

Post a Comment

Popular posts from this blog

Robot Software

In the previous blog posts for this 'series' "It is a good time...."  Post 1  looked at the hardware unpinning some of this positive rise in robots; Post 2  looked at social robots; Post 3  looked at a collection of small robots; Post 4 looked at further examples of small robots Robots, such as the forthcoming Buddy and JIBO, will be based some established open sourceand other technologies. Jibo will be based around various technologies including Electron and JavaScript (for more details see:  http://blog.jibo.com/2015/07/29/jibo-making-development-readily-accessible-to-all-developers/ ). Buddy is expected to be developed around tools for Unity3d, Arduino and OpenCV, and support Python, C++, C#, Java and JavaScript (for more details see http://www.roboticstrends.com/article/customize_your_buddy_companion_robot_with_this_software_development_kit ).  This post contin ues with some of the software being used with the smaller robots.  A number ...

Speech Recognition in Scratch 3 - turning Hello into Bonjour!

The Raspberry Pi Foundation recently released a programming activity Alien Language , with support Dale from Machine Learning for Kids , that is a brilliant use of Scratch 3 - Speech Recognition to control a sprite in an alien language. Do the activity, and it is very much worth doing, and it will make sense! I  would also recommend going to the  machinelearningforkids.co.uk   site anyway it is full of exciting things to do (for example loads of activities  https://machinelearningforkids.co.uk/#!/worksheets  ) . Scratch 3 has lots of extensions that are accessible through the Extension button in the Scratch 3 editor (see below) which add new fun new blocks to play with. The critical thing for this post is  Machine Learning for Kids  have created a Scratch 3 template with their own extensions for Scratch 3 within it  https://machinelearningforkids.co.uk/scratch3/ . One of which is a Speech to Text extension (see below). You must use this one ...

Scratch and web-cams in Scratch 3

Scratch 3 was launched on 2nd January 2019, so I wanted to know would Webcams still work with Scratch 3 as it did with Scratch 2. For example, in a previous post  Scratch, webcams, cats and explosions  the cat (Scratch) moved across the screen and a button burst when the object moved in the camera onto it.  Can the same thing be done in Scratch 3? The short answer is yes, but it is done slightly differently. The first change the video capture is not there in the blocks automatically; but is an extension that needs to be added. First, you need to add the extension blocks for video sensing. Go to the little icon at the bottom left of the screen (as shown below) this takes you to the extensions menu. Next, find the Video Sensing option and selected. The webcam, if enabled, with start automatically. A video sensing set of blocks is now in the list of block options.  The rest is very similar to doing this in Scratch 2. Moving ...