Mini "Guess the Number" Game Machine With Micro:bit

by tianli in Circuits > Microcontrollers

1147 Views, 0 Favorites, 0 Comments

Mini "Guess the Number" Game Machine With Micro:bit

GuessTheNumberExplained.jpg

Have you ever played "Guess the Number"? This is a very easy-to-build mini game machine that plays "Guess the Number" with you. We designed this DIY project to encourage physical play and help kids learn programming. It uses a MU Vision sensor to sense the number cards, through which the player will try to guess the random number that the machine has chosen.

The setup is all explained in this picture.

A MU vision sensor that can recognize printed number cards is connected to the Micro:bit via I2C bus. The two PCB boards and a speaker are held together using a stand built from LEGO technic pieces so that the camera is looking down at a 45 degree angle. Make sure there is nothing to block the camera view to the front of the Micro:bit where the player will present the number card to the machine.

Supplies


BBC micro:bit board ×1

Morpx MU Vision Sensor III ×1

LEGO Technic Pieces ×1 Pimoroni pin:bit ×1

Speaker: 0.25W, 8 ohms

Connecting the Wires

Connections.jpg

You will need to connect 6 wires. The speaker has two wires connecting to the "0" and "GND" pin of Micro:bit. The MU Vision sensor has 4 wires connecting to the I2C bus -- 3V, pin 19 (SCL), pin 20 (SDA)and GND.
In the picture, we just solder the wires to the Micro:bit contact pad. You can also use one of the breakout board for micro:bit to connect the wires.

The MU Vision Sensor III

DIPswitch.jpg

The MU Vision sensor is the main AI module that recognizes different number cards. It has I2C output port that can be used to connect to the Micro:bit (pin 19 and pin 20).
Note:

1. To connect to Micro:bit, the vision sensor's left DIP switch 2 need to set to "ON" to use the I2C mode.

2. The vision sensor is mounted upside down (the sensor connector facing toward player) so that when the player present the number card to the machine it is "frontal" from the player's point-of-view.

Programming Micro:bit Via Makecode

muvs.jpeg
muvs2.jpeg

You can program the machine using MakeCode. You can program the Micro:bit in both Javascript or in block code. To make it simple we use block programming to illustrate here.
1. Import the MUVisionSensorIII library By selecting "Advanced" -> "Extensions", and type "mu-opensource/MuVisionSensorIII-MakeCode" in the search box. Select the "Muvs" extension from the result.

You will now find the MuVisionSensor blocks like this

Initialize MU Vision Sensor

on_start.png
detect.png

2. Initialization of MU Vision Sensor in the on start block and set it to use I2C bus.

and Add Number Card algorithm.

Add Code to Process the Detection Result

for_loop.jpeg

In the Forever loop, add code to process the detection result from MU Vision Sensor.

Display the Result on the LED Matrix

LED.jpeg

We use a custom function to display the number recognition result.
Note: Since we placed the Micro:bit vertically, the number on the LED display need to be rotated by 90 degree.

Game Logic

game.jpeg

You can program micro:bit to give out a little hint for the secret number.

Add Life Bar

life.jpeg
life2.jpeg

You can also life to the game for a bit more fun. We use the left column of the LED matrix to display the "life bar"

Add Music

music.jpeg

That's it. Due to the space reason, not all code are shown in the figure above. You can find the full code here.

Summary

This tutorial teaches you how to build a mini game machine using Micro:bit and the MU Vision Sensor. With the help of visual recognition from the MU Vision Sensor, you can build many similar "physical play" games on the Micro:bit platform.