The Micro:Bit Yo-yo
In this instructable we'll create a micro:bit based yo-yo! A yo-yo is a great toy for children, promoting hands-eye coordination and helping them develop their motor skills. With the micro:bit yoyo, we enhance sensory feedback, both visual and auditory: We use the built-in accelerometer to detect motion and light up the micro:bit's display as well as play a pitched tone varying analogue to the yo-yo's measured acceleration.
It's also a great way to teach children the concepts of acceleration, rotational motion and, at a second level, frequencies and sine wave sound generation.
Supplies
For the micro:bit yo-yo you'll need:
- A micro:bit.
- A JST-PH 2.0 Male Connector Cable (this is the standard cable that connects to the micro:bit's power input).
- A CR2032 battery or any other button battery with nominal 3V voltage.
- A string of ~110cm length and ~1.5mm diameter. You'll want to have some different strengths/diameters/materials available to find out which one fits better to your yo-yo.
- A 3D printed yo-yo (model provided) or any one you can source from other materials, provided that it can house the micro:bit along with the cable and the battery.
3D Printing the Yo-Yo
You can see, tinker and download the 3 printable parts needed to assemble the yo-yo in Tinkercad:
Keep in mind that both sides of the completed yo-yo should have roughly the same weight, so that you get a well balanced and, consequently, well behaved yo-yo. To this purpose, I used 20% infill to print side A (the one housing the micro:bit) and 30% infill for side B and for the axis. This combination worked for me, but you may want to try different infills depending on your printing material and your printer settings. Disclaimer: I tried and discarded a couple of designs before reaching the current one, so there was a lot of trial and error in the process!
To assemble it, just put the axis in the holes of both sides so that it come level with the outer surface each side. The distance between the two sides on the assembled yo-yo should be small (4mm) just enough for the string to enter and wrap around the axis.
You can already put a string to it and give with the half-finished yoyo a try!
Programming the Micro:bit
Before mounting the micro:bit on the yo-yo, there is some programming to be done! You can copy the provided .hex file directly to the board or copy the code to mu-editor and compile it from there.
from microbit import * import math import music fullImg = Image( 5, 5, bytearray( [ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9] ), ) display.show(fullImg) display.on() while True: a = accelerometer.get_values() strength = math.sqrt(a[0] ** 2 + a[1] ** 2 + a[2] ** 2) if strength > 2000: display.on() music.pitch(int(strength), duration=-1, wait=False) else: display.off() music.stop() sleep(1)
What does the code do?
Simple! We continuously poll the accelerometer for the current measured acceleration in all axes. We compute from the 3 axes the acceleration vector length ("strength"). When resting, the micro:bit's accelerometer should always measure 1g (the earth's gravity) equaling to strength == 1023, so we're looking for significantly larger accelerations when the yo-yo is rotating. In the code, the threshold is set to 2000, just shy of 2g (=2047) - by default the micro:bit can measure up to 2g. When this threshold is exceeded, we light up the display and play a sound with frequency equal to the measured acceleration value (that is, between 2 and 2,05kHz). If acceleration is below this threshold, we just switch everything off.
The code is simpler than it sounds ;-) You can modify it yourself or even have your class make suggestions for further interesting yo-yo effects.
Downloads
Mounting the Micro:bit
Fix the loose ends of the JST-PH 2.0 Male Connector Cable on the two poles of the CR2032 with some insulation tape or masking tape. Before attaching the connector end to the board's power supply make sure that you got the polarities right: The micro:bit can get a lot of beating, but reverse polarities are not the best thing that can happen to a circuit board!
Stick the battery into the round recess that lies below the board's place, then trace the cable in the semicircular trough and finally place the micro:bit. You can use some double-sided tape to fix everything into place.
That's it! You can now learn some tricks with your new Micro:bit Yo-yo!
The CR2032 lasts for at least a couple of hours of playing. In the future I may add a switch so that I don't have to remove anything when I want to turn the yo-yo off.
If you make this, I would love to hear your feedback!