Introduction
As the holiday season approaches, there’s no better way to combine festive cheer and technology than with a singing and dancing Santa cap. This project uses a Microbit V2, Python code, and a few additional components to create an interactive hat that responds to loud sounds by playing “Jingle Bells” and dancing. Here’s how you can make your own.
On last year, I posted an article explaining BBC’s Micro:bit, where I showcased a tech Christmas tree built with a Micro:bit., You can take a look https://wisecodes.venuthomas.in/2023/11/05/microbit-board-for-learning-programming-for-children/
Materials Needed
To get started, you’ll need the following materials:
- Microbit V2
- Santa cap
- Small servo motor
- Jumper wires
- Battery pack
- Pencil
- Computer with access to the [Python or Blocks editor](https://makecode.microbit.org/)
Step-by-Step Guide
- Setting Up the Microbit
First, make sure your Microbit V2 is connected to your computer. You can use the Python editor (makecode.microbit.org) to write and edit your code. - Writing the Python Code
Here’s a Python script to make your Santa cap sing “Jingle Bells” and dance with a servo motor when a loud sound is detected:
def rotateServo():
global angle
# Random angle between 10 to 170 degrees
angle = Math.random_range(10, 170)
# Move the servo to the random angle
pins.servo_write_pin(AnalogPin.P1, angle)
angle = 0
jingleBells = ["e4:4", "e4:4", "e4:8", "e4:4", "e4:4",
"e4:8", "e4:4", "g4:4", "c4:4", "d4:4", "e4:8",
"f4:4", "f4:4", "f4:4", "f4:4", "f4:4", "e4:4",
"e4:4", "e4:4", "e4:4", "e4:4", "d4:4", "d4:4",
"e4:4", "d4:8", "g4:8"]
# Set initial position for the servo
pins.servo_write_pin(AnalogPin.P1, 90)
def on_forever():
if input.sound_level() > 128:
# Play the Jingle Bells melody
music.begin_melody(jingleBells, MelodyOptions.ONCE)
for index in range(len(jingleBells)):
# Rotate the servo
rotateServo()
# Reduced the pause to make the servo rotate faster
basic.pause(250)
# Reset servo position after melody
pins.servo_write_pin(AnalogPin.P1, 90)
basic.forever(on_forever)
- Connecting the Servo Motor to the Microbit using jumper wires. Attach the power and ground wires of the servo motor to the 3V and GND pins, respectively, and the signal wire to PIN 1 (AnalogPin.P1).
- Attaching the Microbit and Servo Motor to the Santa Cap using the provided straps (see above video).
- Let’s make your Santa cap a fun and interactive toy! First, attach the Microbit and the servo motor to the Santa cap. Then, attach the servo motor’s arm to a pencil to make it dance. Make sure everything’s secure and the Microbit is easy to reach for programming.
- Next, power up your Microbit with a battery pack. Attach the battery pack to the Santa cap.
- Now, let’s get coding! Edit the Python script on the Python editor (https://makecode.microbit.org/) and download the code file. Upload the file to your Microbit V2 using your computer. Once the code is uploaded, the Santa cap will play “Jingle Bells” and dance whenever you make a loud noise.
Your interactive Santa cap is all set to spread joy and laughter! This project is a great way to mix holiday cheer with tech. Enjoy the smiles and happiness it brings to everyone around you.
Micro:Bit’s Blocks looks like:
