How to make a guitar with a micro:bit ?

How to make a guitar with a micro:bit ?

Purpose

To make a guitar with a micro:bit and an ultrasonic sound sensor.

Materails

micro:bit x 1

Nezha expansion board x 1

Sonar:bit x 1

RJ11 wire x 1

Bricks x N

Assembly steps

Build a device as the picture shows:

Hardware Connections

Connect the sonar:bit to J1 port on Nezha expansion board.

Software programming

Go to MakeCode editor:(https://makecode.microbit.org/#editor)Add Wukong extension from the settings on the right upper conner.

Search with Planet X in the dialogue box and add it to the package.

Coding:

Drag “show icon” into the “on start” brick, save the detected value from the sonar:bit as “I” and judge if it’s between the setting ranges. If yes, set the buzzer to play the tones.

Code more with the slimar procedure and pause for 500ms.

Link:https://makecode.microbit.org/_Rv53CyYY03hg

Result

Change the tones of the micro:bit guitar from adjusting the distances from the bricks board to sonar:bit.