Microbit Sensors & Circuits
Advanced
45 mins
215 points
What you need:
  • Chromebook/Laptop/PC
  • Microbit
  • Crocodile clips
  • Some fruit & vegetables

Microbit Fruit and Veg Piano

In this project we will conduct electricity through your body and some fruit and veg to make your Microbit play some music!

1 - Introduction

Did you know that your body can conduct electricity? In fact lots of things can conduct electricity, some better than others.

In this project we're going to create an electrical circuit using your body and some fruit and vegetables (which also can conduct electricity) to make your Microbit create some music.

Don't worry this is safe to do, as the amount of electricity we'll be using is very, very low.

Never play with or do experiments with high powered electricity such as plugs and power outlets. This level of electricity is actually dangerous!

2 - What you need

For this project you will need:

  1. A microbit 
  2. 4 Crocodile clips
  3. 4 pieces of fruit or vegetables such as bananas, apples, carrots etc.

3 - Create a new Microbit project

Go to the makecode.microbit.org website and create a new project.

4 - Program Pin 0

Microbits have 3 "pins" on them (P0, P1 & P2) that can be used with the GND (ground) pin to create circuits. In a later step we will be attaching the crocodile clips to these pins but for now lets add some come to program what will happen when the circuit is completed.

Add the following code to program P0. You can choose any note or icon you want.

basic.forever(function () {
    if (input.pinIsPressed(TouchPin.P0)) {
        music.playTone(262, music.beat(BeatFraction.Quarter))
        basic.showIcon(IconNames.Happy)
    }
})

5 - Program Pin 1

Add the following code to program P1. You can choose any note or icon you want, just make them different to P0 and P2.

basic.forever(function () {
    if (input.pinIsPressed(TouchPin.P0)) {
        music.playTone(262, music.beat(BeatFraction.Quarter))
        basic.showIcon(IconNames.Happy)
    }
    if (input.pinIsPressed(TouchPin.P1)) {
        music.playTone(392, music.beat(BeatFraction.Quarter))
        basic.showIcon(IconNames.Angry)
    }
})

Join our club 😃

To view the remaining 5 steps and access hundreds of other coding projects please login or create an account.

Copyright Notice
This lesson is copyright of . Unauthorised use, copying or distribution is not allowed.
🍪 Our website uses cookies to make your browsing experience better. By using our website you agree to our use of cookies. Learn more