杏吧原创

How to use a BBC micro:bit to make a sound-activated mirror ball

A BBC micro:bit program and a sound sensor will get the party started. Here's how to make a disco ball that automatically spins when music plays

New stuff you need

Continuous rotation servo

Sound sensor

micro:bit edge connector (optional)

Mirror ball

THIS week, it is time to get down and boogie, because we will be making an automated mirror ball. It will require two power sources, because components, like everything from evil geniuses to artists, crave power of different kinds in differing amounts.

Say you have a motor that needs at least 5 volts. The micro:bit board we have been using as the brain of our circuit needs only 3V. As we saw for LEDs, supplying more can cause damage. So if you want your micro:bit to control a motor, you can鈥檛 just wire them both to a heftier power source and hope.

Take your servo. It should have three wires: red, brown and yellow, ending in sockets. Connect the red wire to the positive power rail on your breadboard, and the brown wire to the negative or ground rail (blue), then connect the 9V battery to the rails to power your servo (you might need to cut a crocodile wire so one end can poke in the breadboard). The micro:bit has its usual 3V battery. Here is the important part: connect the ground rail to the micro:bit ground. Linking the grounds ensures both parts of the circuit cooperate.

Connect the yellow servo wire to pin 0 and finally add the sound sensor. To do this, connect 鈥渧cc鈥 to the micro:bit鈥檚 3V pin, 鈥済nd鈥 to ground and 鈥渙ut鈥 to micro:bit pin 7. Pin 7 is the gold sliver to the left of pin 1. It is too skinny for croc clips so you can attach a wire with a blob of conductive paint or solder. Or I am using an edge connector, which lets your micro:bit slot into a breadboard with each pin to a row.

Plonk the mirror ball on the spinning part of the servo and glue it in place.

Now you are ready to code. For the sound detection, we need an 鈥渋f \<true\> then else鈥 block from the micro:bit editor鈥檚 鈥淟ogic鈥 tab. Clip it into 鈥渇orever鈥. Grab the 鈥0 = 0鈥 comparison out of the 鈥淟ogic鈥 tab too. Next, we want the advanced menu. Find 鈥淧ins鈥 and grab 鈥渄igital read pin鈥. This is going to check the output of the sound sensor. Stick it all together to make a line like 鈥渋f digital read pin p7 = 0鈥, which basically means 鈥渋f the sensor detects a sound鈥.

To move the mirror ball, you can use 鈥渟ervo write pin鈥 to control the motor. Writing a value of 0 will spin the motor at full speed in one direction, and writing 180 will spin it in the opposite direction. Nestle this under 鈥渋f鈥. Under 鈥渆lse鈥, stick another 鈥渟ervo write pin鈥 and type 90. This makes the ball stop when the music does.

. Put on some tunes, point a torch at the mirror ball and you have a high-tech disco. (The sound sensor should have a dial you can turn to change the sensitivity.)

There is a lot more your motor can do. How about a winch for teabags 鈥 with a temperature sensor for optimal dunking? Let us know what you come up with.

To download a printable version of this page click here

Thanks to Imperial College Advanced Hackspace for use of their facilities


For next week

Another continuous rotation servo

2 x wheels to fit servos

2 x long-arm limit switches

Battery box (to hold 4 x AA batteries)

Robot chassis or CD case

Next in the series

1 Introduction

2 Electric candle

3 Toast notifier

4 Desktop traffic light

5 Propeller car

6 Magic 8 Ball

7 Theremin

8 Sound sensitive disco ball

9 Robot rubbish sweeper
Connect two motors for a roaming robot

10 Biscuit bot

Projects so far and a full list of kit required are at
Email: maker@newscientist.com

Topics: Electronics