10. Case 07: Smart Remote Control Musical Light

Level: level auto_fit

10.1. Sender

Goal


Create a remote controller to control the living room’s musical light.

Background


What is the Smart Remote Control Musical Light?

Nowadays, different electronic furniture can also be controlled remotely. In this case, it illustrates the concept of remote control in Smart Home. The home owner can control the room atmosphere in the living room by pressing the remote. (Change of music and light)

Principle of Remote (Sender)

-Micro:bit includes the radio function, allowing two or more Micro:bit to form a group and communicate in a small area.
-In this case, this micro:bit sender (Remote) join group 1 with receiver. When we pressed the different button from micro:bit, it will send different message (mode) to another micro:bit so that the receiver will do the corresponding action.
-The message represent the mode which is “Funny”, “Exciting” and “Stop Music”.

pic_90

Sender

Part List

pic_90

Assembly step


N/A

Hardware connect


N/A

Programming(Makecode)


Step 1. Connect to radio group

  • In on Start, put a radio set group 1 to join the radio group 1 auto_fit

Step 2. Send message to group

  • Snap on button A pressed to editor

  • In on button A pressed, put a radio send string funny to send funny message to group 1 micro:bits

  • Repeat the steps with minor changes on the trigger button and string to create other message sender for excited and stop_music auto_fit


Full Solution

MakeCode: https://makecode.microbit.org/_JF0RtbVihXDD

You could also download the program from the following website:

Result


After loaded program to micro:bit,

When the press the button A, micro:bit sends the funny message to group 1.

auto_fit

When the press the button B, micro:bit sends the excited message to group 1.

auto_fit

When the press the button A and B, micro:bit sends the stop_music message to group 1.

auto_fit

Think


1. Other than press button, any other way to make the decision how to send the message?

10.2. Receiver

Goal


Create living room’s musical light which controlled by remote.

Background


Principle of Music and Light Player (Receiver)

When this Micro:bit receives the message from the another Micro:bit (Remote), it will use the buzzer to play a different tone or music, at the same time, the multi-color LED will be changed to have better ambience. There are 3 modes, one is enjoyable mode, another is exciting mode, the last one is Stop Music.

pic_100

Part List


pic_90

Assembly step


Step 1

In this case, build the “Big Style Model” as a home base.

pic_90

Step 2

To build a living room, put model E1 onto model A, align with the holes at model A and B3.

pic_90

Step 3

Attach the multi-color LED to the model B3 using M4*10mm screws and nuts. And the connecting wire should be bended to the hole nearby.

pic_90

Step 4

To build a sofa model. Put the model K3 to the two sides of model K1.

pic_90

Step 5

Put model K2 all together to the cardboard parts (K1-K3).

pic_90

Step 6

The sofa completed!

pic_90

Step 7

Place the sofa at the living room.

pic_90

Step 8

Put the model H as a decroration display on model B3.

pic_90

Step 9

Assembly completed!

pic_90

Hardware connect


  1. Connect the Multi-Color LED to P1

  2. Pull down the buzzer switch to bottom position

pic_80

Programming (MakeCode)


Step 1. Connect to radio group and initialize LED and music flag

  • Create a variable called mode

  • In on Start, put a radio set group 1 to join the radio group 1

  • Initialize Multi-Color LED by set strip to NeoPixel at pin P1 with 1 leds as RGB(GRB format)

  • Set the variable mode value to 0 by set mode to 0

auto_fit

Step 2. Examine the radio message and take action

  • Snap on radio received receivedstring block to editor

  • Put a nested if-else statement inside that block

  • In the first condition, use receivedstring = stop_music to filter out the stop_music message, change the mode flag variable to 0

  • In the second condition, use receivedstring = funny to filter out the funny message, change the mode flag variable to 1

  • In the third condition, use receivedstring = excited to filter out the excited message, change the mode flag variable to 2

auto_fit

Step 3. Make the change color function

  • Create two function called rainbow and flash

  • For each function, use strip show color XXX and pause(ms) XXX to fill in the pattern of color changes as you want

pic_90

Step 4. Change LED color by the flag

The color of LED should be change following by the flag

Flag Meaning
0 stop_music
1 funny
2 excited
  • Put a nested if-else statement inside the Forever

  • Use mode = 0 as the first condition

  • In the first if segment, that’s means stop_music, stop the playing sound by stop all sounds

  • Turn off the LED by strip show color black

  • Use mode = 1 as the second condition

  • In the second if segment, that’s means funny, stop the playing sound by stop all sounds, then play a funny music with start melody prelude repeating once

  • Execute the function to change to rainbow pattern by call Rainbow

  • Use mode = 2 as the third condition

  • In the third if segement, that’s means excited, stop the playing sound by stop all sounds, then play a excited music with start melody chase repeating once

  • Execute the function to change to flash pattern by call flash

auto_fit


Full Solution

MakeCode: https://makecode.microbit.org/_3PLEfo3pX5r4

You could also download the program from the following website:

Results


After loaded program to micro:bit,
When received the funny message, micro:bit will play the funny music and the light will show in rainbow mode.
When received the excited message, micro:bit will play the excited music and the light will show in flash mode.
When received the the stop_music message, micro:bit will stop the music and turn off the light.

auto_fit

Think


  1. Apart from the built in melody, can you make your own music melody?

  2. Can you control other hardware like a motor fan using radio control?