4. Music and colour

Music and colour

In this exercise, we will experiment with the LED lights and the music notes of our mBot.

As we already learnt in the exercise first blocks.


You will learn

  • To combine different functions of the mBot.
  • The RGB colour system in more detail.
  • How to use variables to programme your mBot.

Open the mBlock programme on your computer, switch on your mBot and connect it.


Check the steps in "execute". Answer the following questions:

  • Which steps should I follow?
  • Which steps can I take?
  • How much time do I need?
  • What tools do I need?


Perform the steps one by one. Have you forgotten how to do it? Look at the hints or download the solution.




Do you know what a theremin is? This musical instrument has existed since 1929 and produces different notes depending on the musician's hand position.
Create a theremin playing different notes depending on how far or how close your hand is to the ultrasonic sensor.


Programme your mBot to play the song: “Brother John”.


A colourful keyboard piano

The music

Now we will change your computer keyboard into a piano.


If key ‘A’ is pressed, we want to hear a C4. Can you programme this?


Make sure you have a complete piano. You can, for example, play "Brother John” with the keyboard!

It is not a lot of extra work to also link the other keys to the right note. To save you some time, you can always right-click on a group of blocks. If you click 'Duplicate’, the group will be copied.

The colours

Now, we want to change your mBot into a colourful piano. Depending on the note, the lights will light up another colour.

Which colour? That's up to you! We have chosen red for the lowest note. A higher tone will gradually become a little more blue.

piano met kleur

Make sure you put the blocks for the colours and the notes in the right order. If not, it will not produce the desired result.


a)    In order to perfect your piano, make sure that the light is off after you have played the tone. Will you give it a try?  

b)    On a real keyboard, you can press a key in order to play a certain tune.  Will you give it a try?



An RGB light can emit a red, green or blue colour, which can shine between 0 (off) and 255 (maximum light).  However, you already knew that!  By mixing these three colours, you can pretty much conjure up any colour. 

RGB wielrgb

In this challenge, we will start off with the colour red and gradually turn it into green or blue.  


We must receive feedback from the lamps: after all, we have to know what state they are in at different times.  We can achieve this by creating variables. 


Look back at the project you just made. Ask yourself the following questions:

  • Does the programme work like I expected?
  • What is working well?
  • What is not working well?
  • How can I do things differently?


Click on the links below to download the solutions: