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.
What You’ll Need:
BBC micro:bit (V1 or V2)
Elecfreaks Smart Home Kit (Breakout board, Rainbow LED strip, and Noise sensor)
Micro-USB Cable
MakeCode Editor (online at https://makecode.microbit.org/#editor)
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
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
lightvariable to the value of the light sensor.Set the
noisevariable to the value of the noise sensor.The "If" Statement: If
lightis less than a certain threshold (e.g., 50) ANDnoiseis greater than 78dB, then turn the LEDs on.The Timer: Use a
pauseblock for 10,000ms (10 seconds) so the light stays on while you walk through the room, then turn it off.
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.
Adaptation: The Dynamic Sound-Reactive Light
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




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