Print Go To MakeCode

Hummingbird Bit: MakeCode Lessons

Setup

Steps 1 2 3 4 5 6 7
Steps 1 2 3 4
Steps 1 2 3 4 5 6 7
Steps 1 2 3 4 5 6 7
Steps 1 2 3 4 5 6
Steps 1 2 3 4 5 6 7
Steps 1 2 3 4 5 6 7
Steps 1 2 3 4 5 6 7 8
Steps 1 2 3 4 5 6 7 8 9 10
Steps 1 2 3 4 5 6 7 8 9 10
Steps 1 2 3 4 5 6 7 8 9 10
Steps 1 2 3 4 5 6 7 8 9 10
Steps 1 2 3 4 5 6 7
Steps 1 2 3 4 5 6 7 8 9 10
Steps 1 2 3 4 5 6 7 8 9 10
Steps 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Steps 1 2 3 4
Steps 1 2 3 4 5 6 7 8 9 10
Steps 1 2 3 4 5
Steps 1 2 3
Steps 1 2 3 4 5 6
Steps 1 2 3 4
Steps 1 2 3 4 5
Steps 1 2 3 4 5 6
Steps 1 2 3 4 5 6 7

Setup

((vim videoid=iop23eq2m1 wl=0))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILLMakeCode_Humbit_Setup_1-768x432.jpg))

This module will cover how to create a MakeCode program for the Hummingbird Bit and how to download the program to the micro:bit.

Please note that there is no sound in these videos.

((vim videoid=ef10aonp3x wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILLMakeCode_Humbit_Setup_2-768x432.jpg))

Insert a micro:bit into your Hummingbird Bit Controller (you might need to push a little harder than you think!). The Hummingbird also needs a source of power, so connect it to the battery pack or AC power adapter. Connect your micro:bit to the computer with the USB cord. If you are using rechargeable batteries, check out this support article before using.

Note: MakeCode Bluetooth capability does not work reliably with our products. See our support article for more details.

Use this button to open the MakeCode Environment. These lessons show the Chrome browser. We recommend Chrome, but Makecode will work in most browsers. You can also go to makecode.microbit.org, click “Advanced” in the blocks menu, then click “+Extensions”, and search for the Hummingbird extension.

((vim videoid=l57k45zlg6 wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILLMakeCode_Humbit_Setup_4-768x432.jpg))

Minimize the micro:bit simulation (the image on the left) to make more room for your programs. This simulator does not work with the Hummingbird Bit.

Give your program a useful name. MakeCode will automatically save your project under this name.

((vim videoid=qn2qo1yddt wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILLMakeCode_Humbit_Setup_5-768x432.jpg))

Set your browser to ask you where to download files. This will make it easier to load your programs to the micro:bit.

((vim videoid=2r4pgfa4fl wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILLMakeCode_Humbit_Setup_6-768x432.jpg))

To get a sense of what it is like to load a program onto the micro:bit, click the purple Download button. Select the micro:bit as the download location. By default, MakeCode will send a smiley face to your micro:bit LED screen.

In addition to the programming tutorials on this page, we have a lot of other resources to help you work with with your Hummingbird Kit.

  • Our coding cards provide printable programming help for your students.
  • Our blocks document is a handy reference guide that lists all the Hummingbird blocks in MakeCode.
  • Our Build pages offer tutorials and inspiration for building your own robots and mechanisms.
  • Our free Professional Development course ties everything together in an online course you can watch at your own pace.

Sharing Files

Introduction

MakeCode automatically saves programs on the device that you are using. However, these programs may be deleted if your browser history is deleted. This module will describe ways to save a program more permanently or share it with another person.

Downloading a File

Instead of downloading a program’s .hex file to the Finch, you can download it to your computer or Chromebook. After clicking Download, select the location where you want to save the .hex file and click Save. You can then email the file, store it on a USB drive, or treat it as you would any other file.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2019/12/pasted-image-0-2020-07-10T123043.355-768x407.png))

Loading a File

To load a file that you have saved in a .hex file, click on the Home button in MakeCode. From the home screen, click on the Import button.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2019/12/pasted-image-0-2020-07-10T123206.999-768x290.png))

Click on Import File.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2019/12/pasted-image-0-2020-07-10T123211.944-768x349.png))

Click on Choose File and navigate to the file you saved. Select it and then click Go ahead! Your file will open in MakeCode.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2019/12/pasted-image-0-2020-07-10T123218.501-768x360.png))

Sharing a File

To share a file, click on the Share button in MakeCode

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2019/12/pasted-image-0-2020-07-10T123411.203-768x318.png))

Click Publish Project.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2019/12/pasted-image-0-2020-07-10T123419.366-768x339.png))

MakeCode will show you a link that you can share with others. Alternatively, you can also click Embed to see code to embed your project in a website.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2019/12/pasted-image-0-2020-07-10T123426.428-768x277.png))

Single Color LED

((vim videoid=pjsma2icnn wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILLBirdBlox_HumbitLED_1-768x432.jpg))

This module will show you how to use a single color LED with the Hummingbird Bit. A single color LED is a small light with two wires. The colored wire shows the color of the LED. The Hummingbird kit comes with red, green, and yellow LEDs.

Please note that there is no sound in these videos.

((vim videoid=g2zuhfsxvi wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILLBirdBlox_Humbit_LED_2-768x432.jpg))

Use the terminal tool to plug an LED into LEDS port 1 on the Bit. The colored wire should be connected to ‘+’ and the black to ‘-.’

((vim videoid=n6v25blqax wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/MakeCode_LED_3-768x432.jpg))

The Hummingbird LED block is used to control a single color LED. To use this block, set the port of the LED to 1, 2 or 3 (MakeCode defaults to port 1), and set the brightness of the LED from 0% to 100%.

((vim videoid=2qwhch1swg wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILLMakeCode_Humbit_LED_4-1-768x432.jpg))

The forever loop runs the Hummingbird LED block over and over. Since it sets the brightness to 100% each time, the light stays on at full brightness.

Reflect: What do you think would happen if you set the LED to 50% instead of 100%?

((vim videoid=9luz51aayq wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/MakeCode_LED_5-768x432.jpg))

Add a pause block, a second Hummingbird LED block, and a second pause block to the forever loop. The pause block stops the program for a number of milliseconds.

((vim videoid=pv0gul6rqj wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILLMakeCode_Humbit_LED_6-768x432.jpg))

Each time through the loop, the program turns the LED on, pauses, turns the LED off, and pauses again. The forever loop repeats this process over and over.

Reflect: What do you think would happen if the second pause block was not there?

((vim videoid=ho2gr1fe0c wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_LED_7-768x432.jpg))

Write a program that makes the LED blink faster.

Tri-Color LED

((vim videoid=h0qdorfxm4 wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILLMakeCode_Humbit_TriLED_1-768x432.jpg))

This module will show you how to use a tri-color LED with the Hummingbird Bit. A tri-color LED is a small light with four wires. The tri-color LED actually has three tiny lights inside it. One is red, one is green, and one is blue. You can combine different amounts of red, green, and blue light to make different colors.

Please note that there is no sound in these videos.

((vim videoid=zw64b5dzbn wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILLMakeCode_Humbit_TriLED_2-768x432.jpg))

Use the terminal tool to plug a tri-color LED into TRI-COLOR port 1 on the Bit. The red wire connects to ‘R,” the green to ‘G,’, the blue to ‘B,’ and the black to ‘-.’

((vim videoid=i8plquyp1v wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/MakeCode_TriLED_3-768x432.jpg))

The Hummingbird Tri-LED block is used to control a tri-color LED. To use this block, set the port of the LED to 1 or 2 (MakeCode defaults to port 1), and the amount of red, green, and blue from 0% to 100%.

((vim videoid=6blz16pu16 wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILLMakeCode_Humbit_TriLED_4-768x432.jpg))

The forever loop runs the Hummingbird Tri-LED block over and over. Since red is set to 100% each time and green and blue to 0%, the light is red.

Reflect: What do you think would happen if you set both red and blue to 100?

((vim videoid=ovr0p2wokd wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/MakeCode_TriLED_5-768x432.jpg))

Add a pause block, a second Hummingbird Tri-LED block, and a second pause block to the forever loop. The pause block stops the program for a number of milliseconds.

((vim videoid=6bqdhuw9jv wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILLMakeCode_Humbit_TriLED_6-768x432.jpg))

Each time through the loop, the program turns the LED red, pauses, turns the LED blue, and pauses again. The forever loop repeats this process over and over.

Reflect: How can you use a tri-color LED in a robot?

((vim videoid=06lmaisrq4 wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_TriLED_7-768x432.jpg))

Write a program that changes the color of the LED from purple to teal to green.

LED Screen

((vim videoid=hnbimvqsvj wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILLMakeCode_Humbit_LEDScreen_1-768x432.jpg))

In this module, you will learn to display icons and patterns on the micro:bit screen.

Please note that there is no sound in these videos.

((vim videoid=hrtgqh6uoi wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/MakeCode_LEDScreen_2-768x432.jpg))

Use the micro:bit Display block to display a small picture on the screen of the micro:bit. This pattern will make a happy face.

((vim videoid=ycwktu7leq wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILLMakeCode_Humbit_LEDScreen_3-768x432.jpg))

When the space bar is pressed, the micro:bit Display is set to the image you created. Since the display was never programmed to turn off, the image remains on the screen.

Reflect: How would you change this code to display a different image?

((vim videoid=379e5uswfs wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/MakeCode_LEDScreen_4-768x432.jpg))

Add a pause block, a second show icon block, and a second pause block to the forever loop. The pause block stops the program for a number of milliseconds.

((vim videoid=sww8270g33 wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILLMakeCode_Humbit_LEDScreen_5-768x432.jpg))

Each time through the loop, the program shows the first expression, pauses, shows the second expression and pauses again. The forever loop repeats this process over and over.

Reflect: How would you change the code to show 3 different expressions on the micro:bit?

((vim videoid=bjaq6w3ekg wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Screen_6-768x432.jpg))

Use the show leds block to create a program that show your very own animation.

Position Servo

((vim videoid=reu75i1uwz wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILLMakeCode_Humbit_PServo_1-768x432.jpg))

In this module, you will learn to use the position servo. The position servo is a motor that moves to a particular angle. The Hummingbird position servo can move to any angle from 0° to 180°.

Hummingbird Base Kit users have an FS90 Micro Servo that works the same as the servo in these modules.

Please note that there is no sound in these videos.

((vim videoid=xd24mimzj6 wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILLMakeCode_Humbit_PServo_2-768x432.jpg))

Plug in the position servo to SERVOS port 1 on the Bit. Make sure the black wire is aligned to ‘-,’ the red wire to ‘+,’ and the white wire to ‘S.’

((vim videoid=6mqe59r8dr wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/MakeCode_PServo_3-768x432.jpg))

The Hummingbird Position Servo block is used to control the position servo. To use this block, set the port of the servo to 1, 2, 3 or 4 (MakeCode defaults to port 1) and the angle from 0° to 180°.

((vim videoid=nlrrtf77b1 wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILLMakeCode_Humbit_PServo_4-768x432.jpg))

The forever loop runs the Hummingbird Position Servo block over and over, setting it to 90° each time.

Reflect: Why do you think the position servo moves once, then stops at 90°? Would the servo move if it was already at 90° before you start the program?

((vim videoid=v83ibtbpek wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/MakeCode_PServo5-768x432.jpg))

Add a pause block, a second Hummingbird Position Servo block, and a second pause block to the forever loop. The pause block stops the program for a number of milliseconds.

((vim videoid=5lmbh46p9u wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILLMakeCode_Humbit_PServo_6-768x432.jpg))

Each time through the loop, the program moves the servo to 90°, pauses, moves the servo to 180°, and pauses again. The forever loop repeats this process over and over.

Reflect: How would the movement of the servo change if the pause blocks were set to 300 ms instead of 1000 ms?

((vim videoid=xq50lq7to8 wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_PServo_7-768x432.jpg))

Write a program that makes the servo move to 3 different positions.

Rotation Servo

((vim videoid=qb6mazkkfk wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILLMakeCode_Humbit_RServo_1-768x432.jpg))

In this module, you will learn to use the rotation servo. The rotation servo is a motor that can rotate at different speeds.

The rotation servo is not included in the Hummingbird Bit Base Kit.

Please note that there is no sound in these videos.

((vim videoid=fo7hhwivex wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILLMakeCode_Humbit_RServo_2-768x432.jpg))

Plug in the rotation servo to SERVOS port 1 on the Bit. Make sure the black wire is aligned to ‘-,’ the red wire to ‘+,’ and the white wire to ‘S.’

((vim videoid=41gjndcrz6 wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/MakeCode_RServo_3-768x432.jpg))

The Hummingbird Rotation Servo block is used to control the rotation servo. To use this block, set the port of the servo to 1, 2, 3, or 4 (MakeCode defaults to port 1) and the speed from -100% to 100%.

((vim videoid=lg83p0ovbd wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILLMakeCode_Humbit_RServo_4-768x432.jpg))

The forever loop runs the Hummingbird Rotation Servo block over and over, setting it to 100% each time.

Reflect: What would happen if you set the speed of the Hummingbird Rotation Servo to -100% instead?

((vim videoid=japo5frudu wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/MakeCode_RServo_5-768x432.jpg))

Add a pause block, a second Hummingbird Rotation Servo block, and a second pause block to the forever loop. The pause block stops the program for a number of milliseconds.

((vim videoid=1ziesiyl4f wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILLMakeCode_Humbit_RServo_6-768x432.jpg))

Each time through the loop, the program turns the motor on, pauses, turns the motor off, and pauses again. The forever loop repeats this process over and over.

Reflect: What do you think would happen if you changed the speed in the second Hummingbird Rotation Servo block to 40 instead of 0?

((vim videoid=c6ts5exf3s wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_RServo_7-768x432.jpg))

Write a program that makes the servo spin counterclockwise quickly for 1 second, then clockwise slowly for 3 seconds.

Buzzer

((vim videoid=1czrsczcwn wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Buzzer_1-768x432.jpg))

This module will show you how to program the buzzer output on the Hummingbird Bit. The buzzer can be used to create different musical tones that come directly from the Hummingbird controller board. The range of the buzzer is Low C to High B, or 131 to 988 Hertz (Hz).

Please note that there is no sound in these videos.

((vim videoid=49cd782c7x wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Buzzer_2-768x432.jpg))

Drag out 3 play tone Middle C for 1 beat blocks from the Music folder and snap them into the Forever loop. Use the drop down menu on each block to select different notes. The range of the buzzer is Low C to High B, or 131 to 988 Hz.

Tip: Your browser will preview the tones through your computer’s speakers. Once you download the code, the sound will come through the board.

((vim videoid=nn2zd8gnom wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Buzzer_3-768x432.jpg))

The notes you’ve programmed will play for 1 beat, one right after another. In music, the “beat” represents how long a note will play. We’ll learn to speed this up and slow this down next.

Reflect: How could you make the notes play for longer?

((vim videoid=tpnvrkcixr wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Buzzer_4-768x432.jpg))

To make the notes play faster or slower, use the set tempo to (bpm) block from the Music folder. Snap the set tempo to (bpm) block into the top of the forever loop.

The “tempo” is the speed of a song. It is measured in beats per minute (bpm). MakeCode defaults to 120 bpm. Change the tempo by clicking the white oval and use your keyboard to set a new tempo.

((vim videoid=lo481lv9kj wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Buzzer_5-768x432.jpg))

Using a little bit of math, we can find that a song with 120 bpm has beats lasting half a second (120 bpm / 60 seconds in a minute = 2 beats in each second). Use the drop down menu to change the bpm and see how that affects the speed of the notes.

Reflect: What would you set the bpm to make a song where each beat = 1 second?

((vim videoid=fzxq3u2zhh wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Buzzer_6-768x432.jpg))

Drag out 3 rest(ms) blocks from the Music folder. Place one rest(ms) block after each play tone blocks. These blocks will cause there to be a silence, called a “rest.” Use the drop down menu to adjust the length of each rest.

((vim videoid=yooelbvfsp wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Buzzer_7-768x432.jpg))

The notes you’ve programmed will now play with silences or “rests” in between them. You can now program your Hummingbird to play any song at any tempo!

((vim videoid=llvpp4d2lr wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Buzzer_8-768x432.jpg))

Can you write a program to play a simple song you know?

Light Sensor

((vim videoid=cijsxk94r5 wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/Screenshot-2019-08-13-14.39.42-768x409.png))

This module will show you how to use a light sensor as an input with the Hummingbird Bit. A light sensor is a component that collects data based on how much light surrounds the sensor. The range of the light sensor is 0 to 100.

This module assumes that you have already completed the single color LED module.

Please note that there is no sound in these videos.

((vim videoid=louxjatlvu wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILLMakeCode_Humbit_Sensors_2-1-768x432.jpg))

Plug a sensor into your board. Any Hummingbird sensor can be connected to any of the three ports labelled “SENSORS” on the Bit. The yellow wire connects to ‘S,’ the red to ‘+,’ and the black to ‘-.’

((vim videoid=7wnovbb2xe wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/MakeCode_Sensor_3-1-768x432.jpg))

To see the value of the sensor on the micro:bit LED screen, place the Hummingbird Sensor block inside a show number block.

The Hummingbird Sensor block is near the bottom of the Hummingbird folder in MakeCode. Use the drop-down menu to select “Light.”

((vim videoid=2i35bcb98l wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILLMakeCode_Humbit_Sensors_4-1-768x432.jpg))

Interact with the light sensor and watch the number on the micro:bit LED screen change.

Reflect: How can you make the value of the sensor higher or lower?

((vim videoid=7mqd7mgtn5 wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Distance_5-768x432.jpg))

You can use the sensor data to control the brightness of an LED.

Plug an LED into LED port 1.

((vim videoid=v7s1h6m8em wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/MakeCode_Sensor_6-1-768x432.jpg))

Place a Hummingbird Sensor block inside a Hummingbird LED block.

((vim videoid=fbz8g90ahi wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILLMakeCode_Humbit_Sensors_7-1-768x432.jpg))

The Hummingbird Sensor block measures the value of the light sensor and sets the LED brightness to that value.

Reflect: In this program, the micro:bit runs the Hummingbird LED block about 40 times per second. What do you think would happen if you added a pause block to the forever loop?

((vim videoid=58w9tpzclj wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/MakeCode_Sensor_8-1-768x432.jpg))

Your light sensor value can be used to make decisions. To turn on an LED when the value of the sensor is low, use an if else block from the Logic folder. This block requires a comparison block, which is also in the Logic folder.

((vim videoid=9u3l6dpuh5 wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILLMakeCode_Humbit_Sensors_8-768x432.jpg))

This program compares the value of the light sensor to 10. If the sensor value is less than 10, the program runs the block inside the if section of the if else, and the LED turns on. When the sensor value is greater than 10, the program runs the block inside the else section, turning the LED off.

((vim videoid=k25toh6u36 wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Sensors_9-1-768x432.jpg))

Can you make an LED turn on and off with a different sensor? Disconnect the sensor you’ve been using and connect a new sensor. Use the drop-down menu in the Hummingbird Sensor block to make the block match your new sensor.

Dial Sensor

((vim videoid=duy3jhjy5b wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Dial_1-768x432.jpg))

This module will show you how to use a dial sensor as an input with the Hummingbird Bit. A dial sensor is a component that collects data based on how much you rotate the knob. The range of the dial sensor is 0 to 100.

This module assumes that you have already completed the single color LED module.

Please note that there is no sound in these videos.

((vim videoid=tx45kd5elh wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Dial_2-768x432.jpg))

Plug a sensor into your board. Any Hummingbird sensor can be connected to any of the three ports labelled “SENSORS” on the Bit. The yellow wire connects to ‘S,’ the red to ‘+,’ and the black to ‘-.’

((vim videoid=e62f2bjcdu wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Dial_3-768x432.jpg))

To see the value of the sensor on the micro:bit LED screen, place the Hummingbird Sensor block inside a show number block.

The Hummingbird Sensor block is near the bottom of the Hummingbird folder in MakeCode. Use the drop-down menu to select “Dial.”

((vim videoid=rqojras2it wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Dial_4-768x432.jpg))

Interact with the dial sensor and watch the number on the micro:bit LED screen change.

Reflect: How can you make the value of the sensor higher or lower?

((vim videoid=92l17yukx3 wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Dial_5-768x432.jpg))

You can use the sensor data to control the brightness of an LED.

Plug an LED into LED port 1.

((vim videoid=096ht1waty wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Dial_6-768x432.jpg))

Place a Hummingbird Sensor block inside a Hummingbird LED block.

((vim videoid=dqx1z2ajeh wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Dial_7-768x432.jpg))

The Hummingbird Sensor block measures the value of the light sensor and sets the LED brightness to that value.

Reflect: In this program, the micro:bit runs the Hummingbird LED block about 40 times per second. What do you think would happen if you added a pause block to the forever loop?

((vim videoid=v4b4221ifp wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Dial_8-768x432.jpg))

Your dial sensor value can be used to make decisions. To turn on an LED when the value of the sensor is high, use an if else block from the Logic folder. This block requires a comparison block, which is also in the Logic folder.

((vim videoid=wahrtnliea wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Dial_9-768x432.jpg))

This program compares the value of the dial sensor to 50. If the sensor value is greater than 50, the program runs the block inside the if section of the if else, and the LED turns on. When the sensor value is less than 50, the program runs the block inside the else section, turning the LED off.

((vim videoid=secmieln6u wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Dial_10-768x576.jpg))

Can you make an LED turn on and off with a different sensor? Disconnect the sensor you’ve been using and connect a new sensor. Use the drop-down menu in the Hummingbird Sensor block to make the block match your new sensor.

Distance Sensor

((vim videoid=dbgyzllxre wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Distance_1-768x432.jpg))

This module will show you how to use a distance sensor as an input with the Hummingbird Bit. A distance sensor is a component that collects data based on how close or far you are to the sensor. The range of the distance sensor is 1 to 260 cm.

The distance sensor is not included in the Hummingbird Bit Base Kit.

This module assumes that you have already completed the single color LED module.

Please note that there is no sound in these videos.

((vim videoid=i6h4r6mcnd wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Distance_2-768x432.jpg))

Plug a sensor into your board. Any Hummingbird sensor can be connected to any of the three ports labelled “SENSORS” on the Bit. The yellow wire connects to ‘S,’ the red to ‘+,’ and the black to ‘-.’

((vim videoid=aej81fkgr1 wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Distance_3-768x432.jpg))

To see the value of the sensor on the micro:bit LED screen, place the Hummingbird Sensor block inside a show number block.

The Hummingbird Sensor block is near the bottom of the Hummingbird folder in MakeCode. Use the drop-down menu to select “Distance.”

((vim videoid=89mb6m5f2n wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Distance_4-768x432.jpg))

Interact with the distance sensor and watch the number on the micro:bit LED screen change.

Reflect: How can you make the value of the sensor higher or lower?

((vim videoid=ige69mk1ix wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Distance_5-768x432.jpg))

You can use the sensor data to control the brightness of an LED.

Plug an LED into LED port 1.

((vim videoid=bfdp8q2oal wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Distance_6-768x432.jpg))

Place a Hummingbird Sensor block inside a Hummingbird LED block.

((vim videoid=tktnng2i6q wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Distance_7-768x432.jpg))

The Hummingbird Sensor block measures the value of the light sensor and sets the LED brightness to that value.

Reflect: In this program, the micro:bit runs the Hummingbird LED block about 40 times per second. What do you think would happen if you added a pause block to the forever loop?

((vim videoid=9wlh3j92cn wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Distance_8-768x432.jpg))

Your distance sensor value can be used to make decisions. To turn on an LED when the value of the sensor is low, use an if else block from the Logic folder. This block requires a comparison block, which is also in the Logic folder.

((vim videoid=xi0ygzlnp9 wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Distance_9-768x432.jpg))

This program compares the value of the distance sensor to 15. If the sensor value is less than 15, the program runs the block inside the if section of the if else, and the LED turns on. When the sensor value is greater than 15, the program runs the block inside the else section, turning the LED off.

((vim videoid=8m69bb1hyp wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Distance_10-768x576.jpg))

Can you make an LED turn on and off with a different sensor? Disconnect the sensor you’ve been using and connect a new sensor. Use the drop-down menu in the Hummingbird Sensor block to make the block match your new sensor.

Sound Sensor

((vim videoid=5fg04fgisc wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Sound_1-768x432.jpg))

This module will show you how to use a sound sensor as an input with the Hummingbird Bit. A sound sensor is a component that collects data based on how much sound surrounds the sensor. The range of the sound sensor is 0 to 100.

The sound sensor is not included in the Hummingbird Bit Base Kit.

This module assumes that you have already completed the single color LED module.

Please note that there is no sound in these videos.

((vim videoid=mjw5g2jphq wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Sound_2-768x432.jpg))

Plug a sensor into your board. Any Hummingbird sensor can be connected to any of the three ports labelled “SENSORS” on the Bit. The yellow wire connects to ‘S,’ the red to ‘+,’ and the black to ‘-.’

((vim videoid=cty9b8tl2g wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Sound_3-768x432.jpg))

To see the value of the sensor on the micro:bit LED screen, place the Hummingbird Sensor block inside a show number block.

The Hummingbird Sensor block is near the bottom of the Hummingbird folder
in MakeCode. Use the drop-down menu to select “Sound.”

((vim videoid=lxby2yxi4s wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Sound_4-768x432.jpg))

Interact with the sound sensor and watch the number on the micro:bit LED screen change.

Reflect: How can you make the value of the sensor higher or lower?

((vim videoid=2rcslvfnbt wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Sound_5-768x432.jpg))

You can use the sensor data to control the brightness of an LED.

Plug an LED into LED port 1.

((vim videoid=tld7dk9zio wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Sound_6-768x432.jpg))

Place a Hummingbird Sensor block inside a Hummingbird LED block.

((vim videoid=unqzq7taz8 wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Sound_7-768x432.jpg))

The Hummingbird Sensor block measures the value of the light sensor and sets the LED brightness to that value.

Reflect: In this program, the micro:bit runs the Hummingbird LED block about 40 times per second. What do you think would happen if you added a pause block to the forever loop?

((vim videoid=m3ww99a2s7 wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Sound_8-768x432.jpg))

Your sound sensor value can be used to make decisions. To turn on an LED when the value of the sensor is high, use an if else block from the Logic folder. This block requires a comparison block, which is also in the Logic folder.

((vim videoid=l2jx0ukkwt wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Sound_9-768x432.jpg))

This program compares the value of the sound sensor to 70. If the sensor value is greater than 70, the program runs the block inside the if section of the if else, and the LED turns on. When the sensor value is less than 70, the program runs the block inside the else section, turning the LED off.

((vim videoid=uk4r6sbk52 wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Sound_10-768x576.jpg))

Can you make an LED turn on and off with a different sensor? Disconnect the sensor you’ve been using and connect a new sensor. Use the drop-down menu in the Hummingbird Sensor block to make the block match your new sensor.

Buttons

((vim videoid=fsj99uv8a0 wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Buttons_1-768x432.jpg))

This module will show you how to program the A and B buttons on the micro:bit to control the single color LED output of the Hummingbird Bit. The micro:bit’s A and B buttons can be used as inputs. Pressing them can be an “event” to trigger other actions.

This module assumes that you have already completed the single color LED module.

Please note that there is no sound in these videos.

((vim videoid=ka99c4lb9y wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Buttons_2-768x432.jpg))

Plug in a single color LED. The A and B buttons are located on the face of the micro:bit. They can be pressed one at a time or together.

((vim videoid=nm35ld7x7n wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Buttons_3-768x432.jpg))

Remove the forever loop from your screen. Drag out the on button A pressed block from the Input folder. Drag a Hummingbird LED block from the Hummingbird into the loop. Set the Hummingbird LED to 100%. Download the code.

((vim videoid=awqo2o2gf0 wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Buttons_4-768x432.jpg))

The A button being pressed causes the Hummingbird LED to turn on.

Reflect: How could you use the A button to turn a tri-color LED red?

((vim videoid=0l9b7dl8dh wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Buttons_5-768x432.jpg))

Drag out another on button A pressed block from the Input folder. Use the drop down menu to change the second code to on button B pressed. Program the Hummingbird LED to turn off when the B button is pressed.

((vim videoid=rvasz181ct wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Buttons_6-768x432.jpg))

The A and B buttons now turn the LED on and off respectively.

((vim videoid=kco9kgsrcx wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Buttons_7-768x432.jpg))

Can you use on button A+B pressed block to make the LED blink 4 times?

Accelerometer

((vim videoid=nviqp2j6rf wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Accelerometer_1-768x432.jpg))

This module will show you how to use the accelerometer as an input to control a Hummingbird tri-color LED. The range of the x, y, and z variables on the accelerometer is -1024 to 1024 mg.

This module assumes that you have already completed the tri-color LED module.

Please note that there is no sound in these videos.

((vim videoid=pqjq8rjn62 wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Accelerometer_2-768x432.jpg))

Plug in the tri-color LED. You do not need to attach the accelerometer. The accelerometer is built into the micro:bit.

((vim videoid=qld0runub4 wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Accelerometer_3-768x432.jpg))

Remove the forever loop from your screen. Drag out the on shake block from the Input folder. Drag out 2 Hummingbird Tri-LED blocks from the Hummingbird folder and 1 pause (ms) block from the Basic folder. Write a program to turn the tri-color LED on and off inside of the on shake block.

((vim videoid=ufy1rmdfuc wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Accelerometer_4-768x432.jpg))

When you shake the Hummingbird controller board, your tri-color LED will turn red for 1 second and then turn off.

Reflect: How could you make the tri-color LED blink red and blue 3 times when the micro:bit is shaken, then turn off? (Hint: Look in the Loops folder!)

((vim videoid=6cd8fy4zr5 wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Accelerometer_5-768x432.jpg))

You can also tilt your Hummingbird Bit in different directions to change the colors of the tri-color LED.

First, delete the pause and second Hummingbird Tri-LED blocks. Select the drop down menu in the on shake block, and change it to read “logo up.” Duplicate this whole event. Then, use the drop down menu to select “logo down” in the second on shake block. Change the tri-color LED to green on the second Hummingbird Tri-LED block.

((vim videoid=8qjg9d6uxg wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Accelerometer_6-768x432.jpg))

When you tilt the Hummingbird Bit controller forward and back, the tri-color LED will change color from red to green.

Reflect: How could you make this code control a position servo to go from 0 to 180 degrees?

((vim videoid=5e6kvzz0dp wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Accelerometer_7-768x432.jpg))

Write a program that makes the tri-color LED turn blue and purple when the Hummingbird Bit is tilted left and right.

((vim videoid=4hic8col83 wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Accelerometer_8-768x432.jpg))

While we’ve been using the accelerometer as an event up to this point, you can also use the accelerometer’s value to slowly alter a component by nesting it, which you can also do with sensors. This action requires us to use some math.

First, delete your 2 on logo up and on logo down event blocks. Drag out a forever loop from the Basic folder. Drag a Hummingbird Tri-LED block into the forever loop. Drag a division block from the Math folder. Nest this block into the white oval next to “Red” in the Hummingbird Tri-LED block.

Nest an acceleration (mg) x block from the Basic folder into the first space in the division block. This accelerometer can measure front to back movement (called x), side to side movement (called y), and up and down movement (called z). Use your keyboard to type the number 10 into the second space of the division block.

((vim videoid=9ccreem3ln wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Accelerometer_9-768x432.jpg))

Why do you need a math block here? The range of the x, y, and z values on the accelerometer is -1024 to 1024 mg. In order for this sensor to effectively control the tri-color LED, which has a range of 0-100, we need to divide the value of the accelerometer block by about 10.

Reflect: How could you make the y variable of the accelerometer control the brightness of the blue of the tri-color LED at the same time?

((vim videoid=iue9vc95cl wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Accelerometer_10-768x432.jpg))

Write a program that:
– Makes the x variable of the accelerometer control the brightness of the red of the tri-color LED.
– Makes the y variable of the accelerometer control the brightness of the blue of the tri-color LED.
– Makes the z variable of the accelerometer control the brightness of the green of the tri-color LED.

Compass

((vim videoid=xxgecheg35 wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Compass_1-768x432.jpg))

This module will show you how to use the compass as an input to control the movement of a Hummingbird position servo. The range of the compass is 0° to 359°.

This module assumes that you have already completed the position servo module.

Please note that there is no sound in these videos.

((vim videoid=6uya26409c wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Compass_2-768x432.jpg))

Drag the show number block from the Basic folder into a forever loop. Drag the compass heading block from the Input folder into the show number block.

((vim videoid=nb6brvzyyx wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Compass_3-768x432.jpg))

The compass needs to be calibrated before it can be used. Follow the steps displayed on the micro:bit’s LED array to calibrate the compass. The micro:bit asks you to “TILT TO FILL SCREEN.” Tilt the micro:bit so that all the LEDs on the LED display screen are lit. This step will need to be repeated each time you download.

((vim videoid=opo8eoqdil wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Compass_4-768x432.jpg))

The micro:bit’s LED screen is now displaying the input value from the compass. The compass measures its heading in degrees, from 0-360. North is 0.

Reflect: What number represents South?

((vim videoid=3zez7ty8vu wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_HUmbit_MakeCOde_Compass_5-768x432.jpg))

Plug in the position servo. You do not need to attach the compass. The compass is built into the micro:bit.

((vim videoid=w80yz7f6qj wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Compass_6-768x432.jpg))

Drag the compass heading block out of the show number block and delete the show number block. Drag out a Hummingbird Position Servo block from the Hummingbird folder and nest the compass heading block inside of it.

((vim videoid=ra7bu5fv7x wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Compass_7-768x432.jpg))

The position servo will now rotate to match the compass heading. Although the range of the compass is 0°-359°, the position servo will stop at 180 degrees, because the range of the position servo is 0°-180°.

Reflect: How could you use the compass to control the brightness of a single color LED?

((vim videoid=0dwwyxat7v wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Compass_8-768x432.jpg))

The compass value can also be used to make decisions. We will now set your position servo to either 0 or 180 degrees based on the compass value.

First, drag the compass heading and Hummingbird Position Servo blocks apart and outside of the forever loop. Drag an if else block from the Logic folder into the forever loop. Nest a less than block from the Logic folder into the hexagon space of the if else block.

Nest the compass heading block into the first space of the less than block, and type “180” degrees into the second space. Drag the Hummingbird Position Servo block into the first open space of the if else block and set it to “0.” Drag another Hummingbird Position Servo block into the second open space of the if else block and set it to “180.”

((vim videoid=2sgtqoa9jd wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Compass_9-768x432.jpg))

This program compares the value of the compass to 180. If the compass value is less than 180 (indicating west), the position servo is set to 0 degrees. When the compass value is greater than 180 (indicating east), the position servo is set to 180 degrees.

Reflect: How could you use a similar code to turn a tri-color LED red and blue based on the value of the compass?

((vim videoid=zt1aeasgdp wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Compass_10-768x432.jpg))

What kind of robot could you build that would respond to data from the compass?

Radio

((vim videoid=wisa5z6b2z wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Radio_1-768x432.jpg))

This module will show you how to use the radio feature to transmit data from one Hummingbird controller to another, “controlling” one device with another. For this module, you will need 2 Hummingbird Bit boards*, 1 tri-color LED, and 1 dial sensor.

This module assumes that you have already completed the tri-color LED, buttons, and sensor modules.

*In steps 2-8, you will be using a micro:bit by itself without a Hummingbird controller board. To power this micro:bit, you can either use a AAA battery pack or the USB cord included in your kit.

Please note that there is no sound in these videos.

((vim videoid=qtnz6ajg2b wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Radio_2-768x432.jpg))

We will begin by programming the “transmitting” Hummingbird (which we will call HB1) to send a message when the A button is pressed. Eventually, pressing the A button on HB1 will turn the tri-color LED on HB2 red.

On HB1:
First, remove the forever loop from your screen. Next, set the radio group by dragging out the radio set group block from the Radio folder into the On Start loop. Set the radio group to a number between 1-255. Drag out the on button A pressed block from the Input folder. Drag the radio send string block from the Radio folder into the on button A pressed loop. Give the string a message like “red.” (Capitalization will matter, so carefully note the exact string you are sending).

((vim videoid=fornyjreoc wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Radio_3-768x432.jpg))

Switching to the second Hummingbird board, plug in the tri-color LED into port 1.

((vim videoid=xeau5arlkc wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_MakeCode_Humbit_Radio_4-768x432.jpg))

We will now program the “receiving” Hummingbird (HB2) to use a received message to turn the HB2 tri-color LED red.

On HB2:
First, remove the forever loop from your screen. Next, drag out the radio set group block from the Radio folder into the on start loop. Set the radio group to the same number as your HB1. Drag out the on radio received – receivedString block from the Radio folder. Drag a Hummingbird Tri-LED block from the Hummingbird folder into the on radio received – receivedString block. Set Red to 100%.

((vim videoid=u4qusx1yhy wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Radio-5-768x432.jpg))

When the A button is pressed on HB1, the tri-color LED on HB2 turns red.

Reflect: Could you write a similar script to make a message or picture appear on the LED screen of HB2 when you press the A button on HB1?

((vim videoid=dkmj11b6i1 wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Radio_6-768x432.jpg))

Now we want to program our linked Hummingbirds so that pressing the A and B buttons on HB1 will turn the tri-color LED on HB2 red and blue.

First, duplicate the on button A pressed loop and set it to on button B pressed. Give this string a different message like “blue.” (Capitalization will matter, so make note of the string you are sending).

((vim videoid=zpu15i77pg wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Radio_7-768x432.jpg))

We now need a way for HB2 to differentiate between strings. Based on the string it receives, HB2 will either turn the tri-color LED red or blue.

On HB2:
First, remove the Hummingbird Tri-LED block from the on radio received loop and set it to the side. Drag an if then statement from the Logic folder into the on radio received block. Nest a 0 = 0 block from the Logic folder into the hexagon space of the logic blocks. Nest the receivedString block from the Variables folder into the first space in the 0 = 0 block.

Click “Advanced” on the bottom of the folders section to reveal the Text folder. Nest a ” _ “ block into the second space of the 0 = 0 block. Type “red” into that space, exactly matching the string HB1 sent. Drag a Hummingbird Tri-LED block from the Hummingbird folder into the on radio received – receivedString block. Set Red to 100%. Duplicate the if then block and set the text to “blue” and the tri-color LED to 100% blue.

((vim videoid=2wk54oaae6 wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Radio_8-768x432.jpg))

When the A button is pressed on HB1, the tri-color LED on HB2 turns red. When B button is pressed on HB1, the tri-color LED on HB2 turns blue.

Reflect: How could you do something similar with a position servo, setting it to either 0 or 180 degrees based on which button is pressed?

((vim videoid=jalo5dj03d wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Radio_9-768x432.jpg))

Next, plug the first micro:bit into a Hummingbird. Then plug a dial sensor into sensor port 1.

((vim videoid=epm3pyklgz wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Radio_10-768x432.jpg))

Now we’re going to program a dial sensor on HB1 to control the tri-color LED on HB2.

On HB1:
First, drag the radio send string “red” and radio send string “blue” blocks to the side and save them for later. Delete the on button A pressed and on button B pressed blocks. Drag out a forever loop from the Basic folder. Drag an if then else statement from the Logic folder into the forever loop.

Nest a less than block from the Logic folder into the hexagon space of the if then else block. Drag the Hummingbird Light block from the Hummingbird folder into the first space of the less than block. Use the drop down menu to select “Dial.” Type “50” into the second space of the less than block. Drag the radio send string “red” block into the first space, and the radio send string “blue” block into the second space of the if then else statement.

((vim videoid=djqpyum8mz wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_Makcode_Radio_11-768x432.jpg))

We actually don’t need to change anything in our code for HB2! It will still be receiving the same strings, “red” or “blue,” but now the dial sensor will be triggering different strings instead of the A and B buttons.

Now, when you turn the HB1 dial sensor above 50%, the HB2 tri-color LED turns blue. When you turn the HB1 dial sensor less than 50%, the HB2 tri-color LED turns red.

Reflect: Could you recreate this same function with a different sensor?

((vim videoid=wosz0bs5ta wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Radio_12-768x432.jpg))

Up to this point, we have been sending strings of text as messages. Now we will be sending number values as messages between HB1 and HB2. We will use the dial sensor on HB1 to control the brightness of the tri-color LED on HB2 in real time.

On HB1:
First, delete everything inside the forever loop. Drag out a radio send number block from the Radio folder. Nest the Hummingbird Dial sensor block into the radio send number block.

((vim videoid=y8l94qek2a wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Radio_13-768x432.jpg))

We need to reset the HB2 to look for its radio signal in numbers rather than strings of text.

On HB2:
Delete the on radio received – receivedString loop. Drag out an on radio received – receivedNumber block from the Radio folder. Drag out a Hummingbird Tri-LED block into the on radio received – receivedNumber loop. Nest a red receivedNumber block from the Variables folder into the tri-color LED red space.

((vim videoid=i4k71hkpmx wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/STILL_Humbit_MakeCode_Radio_14-768x432.jpg))

As you turn the dial sensor on HB1, the brightness of the tri-color LED on HB2 will increase and decrease in real time.

Reflect: How could you make the dial sensor also control the brightness of the blue light in the tri-color LED?

((vim videoid=jks6bqv5oy wl=1))
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2018/12/Screenshot-2019-08-07-09.59.39-768x430.png))

Combining skills and components like accelerometer, compass, and motors can make for some great animatronic and puppeteering projects. What sort of animatronic puppet could you make, controlled by radio?

Temperature and V2 Sensors

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/bitstate-768x450.png))

This module will show you how to use three additional sensors: the temperature sensor, the micro:bit V2 touch sensor, and the micro:bit V2 sound sensor. The temperature sensor is present on all micro:bits, but the other two sensors can only be used if your Hummingbird contains a micro:bit V2.

The Temperature Sensor

Your Hummingbird can detect temperature using a sensor in the micro:bit. The micro:bit temperature sensor measures the temperature of the air in degrees Celsius. The value of the temperature sensor is measured with the temperature (°C) block on the Input menu.

For example, you can display an “H” on the micro:bit when the temperature is warmer than 20 degrees, and a “C” otherwise.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/other1-768x730.png))

CHALLENGE

Make a tri-color LED turn blue when the Hummingbird detects that it is cold and red otherwise.

Click Here to see example code.

The Touch Sensor

If your Hummingbird contains a micro:bit V2, the gold micro:bit logo is also a touch button. The logo is pressed block at the bottom of the Input menu returns true if you are touching it and false if you are not.

For example, you can make a tri-LED turn green when you are touching the button and red otherwise.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/other3.png))

The Input menu also contains the on logo pressed block. You can use this block to start a script when you touch and release the logo touch button, or you can use the drop-down menu to select other touch options. For example, you can press the logo to turn on the rotation servo.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/other4-768x263.png))

Note that these blocks can only be used with micro:bit V2. If you try to use them with micro:bit V1, you will see an unhappy face on the micro:bit LED display.

CHALLENGE

Write a program that moves the position servo to 0° when you press button A, 90° when you press button B, and 180° when you touch the logo.

Click Here to see example code.

The micro:bit V2 Sound Sensor

The micro:bit V2 also contains a sound sensor, which can detect a noise like a clap. This is similar to the sound sensor that comes with the Hummingbird Premium kit, but it is contained in the micro:bit rather than a separate sensor.

The value of the sound sensor can be measured with the sound level block at the bottom of the Input menu. The range of the micro:bit sound sensor is 0-255. For example, you can turn the rotation servo off when the micro:bit detects a noise and on otherwise.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/other6-768x545.png))

The Input menu also contains the on loud sound block. You can use this block to start a script when the micro:bit V2 detects a loud sound, or you can use the drop-down menu to select other sound options. For example, you can use this block to turn on an LED when you clap.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/other7.png))

Note that these blocks can only be used with micro:bit V2. If you try to use them with micro:bit V1, you will see an unhappy face on the micro:bit LED display.

CHALLENGE

Make the Hummingbird play a note when you clap your hands.

Click Here to see example code.

Variables

((vim videoid=scuqb5gljw wl=1))
((img class=img-responsive src=))

What is a variable? In programming, a variable is a value that can change, depending on conditions or on information passed to the program. Using variables with the Hummingbird Robotics Kit will help you create robots with more advanced functions.

Before you begin this module, make sure that you have completed the single color LED module, the position servo module, the buttons module, and at least one of the sensor modules.

((vim videoid=6yukl7g4aj wl=1))
((img class=img-responsive src=))

You can name a variable anything you want, but it makes most sense to give it a name that matches its function. In this module, we are creating a variable that counts up and down when the A and B buttons are pressed, so a good name for this variable is “count.”

((vim videoid=zvkl3vuk48 wl=1))
((img class=img-responsive src=))

In order to make a variable count backwards, you need to change that variable by a negative number.

((vim videoid=k4qeyzx6tr wl=1))
((img class=img-responsive src=))

To associate an LED with a variable, drag the rounded variable block into the intensity space on the LED block. Make sure the LED block is in a forever loop.

((vim videoid=8e3phps0dy wl=1))
((img class=img-responsive src=))

Nesting a variable into an output block is one way to use a variable. You can also use a variable to control robot expressions. If the variable equals 1, your robot can perform one set of actions. If your variable equals 2, your robot can perform a different set of actions.

Try building a robot using the variable to control different expressions. You can build any type of robot you want, but we recommend building the Tiny Drummer.

((vim videoid=uyzub8zwof wl=1))
((img class=img-responsive src=))

Creating a variable that counts on its own will require a good understanding of how loops work and of how pause blocks work. Create a variable that counts upwards on its own, then associate that counting variable with an LED. How does the LED react?

((vim videoid=85t6dn0d4d wl=1))
((img class=img-responsive src=))

Getting a variable to stop counting on a specific number will require the use of a while loop and an = operator block.

((vim videoid=xb50mcjqcf wl=1))
((img class=img-responsive src=))

Programming a position servo to move slowly is very similar to programming an LED to fade in and out. Nest the counting variable block inside of a position servo block instead of an LED block

To manually control the speed of that position servo with the A and B buttons we will need a new variable. Create a second variable and call it “time.”

((vim videoid=7sa5jyj3kc wl=1))
((img class=img-responsive src=))

Nest the time variable block in the pause blocks. Use the A and B buttons to incrementally change the “time” variable. By controlling the wait times between servo positions, you are controlling the speed of your servo.

((vim videoid=4r738h0xzm wl=1))
((img class=img-responsive src=))

If the wait time between servo positions is too big or too small, the servo can become difficult to work with. Set some parameters for your time variable. There are many ways to set variable parameters. 

Try to build a robot that uses 2 slow moving servos. You can build anything you want, but we recommend the Little Bot.

Rover: Driving and Avoiding Obstacles

((vim videoid=2twdzx6twj wl=1))
((img class=img-responsive src=))

In this module, you will program a mobile robot to move and avoid obstacles. You will need a rover for this module, so go ahead and build one with this tutorial. We kept our rover pretty simple, but feel free to make yours a parade float, a bananamobile, or whatever you can dream up!

Note: The rover modules assume that you have already completed the modules in the Inputs and Outputs sections.

Moving Forward and Back

The two rotation servos on the rover point in opposite directions. 

This means that to move the rover forward, the two servos must move in opposite directions.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image4.png))

To move the rover forward, set the speed of rotation servo 1 to 100% and the speed of rotation servo 2 to -100%.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image4-1-768x477.png))

CHALLENGE

Try out this code. Experiment with different wheel speeds to see how you can move the rover in different ways. How can you move backward?

Click Here to see example code.

Turning

When the speeds of the rotation servos are equal, the robot turns in place. 

Notice that this code turns the rotation servos off at the end of the program. Otherwise, they will remain on when the script ends, and the rover will keep spinning.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image15-1-768x937.png))

CHALLENGE

Try out this code. How can you change how far the robot turns?

Click Here to see example code.

Avoiding Obstacles

You can use the distance sensor to help your robot avoid obstacles. This program will stop the rover when it sees an obstacle less than 20 cm away. Otherwise, the rover will move forward.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image28-1-768x496.png))

CHALLENGE

Modify your program to make the rover back up and turn left when it sees an obstacle. Now your rover can wander around the room!

Click Here to see example code.

Adding Extras

The rover also has two tri-color LEDs for headlights and a servo that controls the steering wheel. You can incorporate these components into your program as well.

CHALLENGE

Make the headlights turn red when the rover is moving away from an obstacle and green when the rover is moving forward. Make your driver steer by turning the steering wheel to the left as the robot turns left and back to the center when it is moving forward or back.

Click Here to see example code.

Rover: Randomness

((vim videoid=65cranijl9 wl=1))
((img class=img-responsive src=))

In this module, you will learn to generate random numbers and use them to create interesting and sometimes unexpected behaviors for your rover. For example, you can use random numbers to make the rover move randomly with random colors for the headlights.

Generating Random Numbers

The pick random block is on the Math menu in MakeCode. This block randomly chooses a number between the two limits given. For example, this block generates a number between 0 and 10.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image20-1.png))

You can use the pick random block anywhere that you would use a number in your program. For example, this program sets the speed of each rover wheel to a random number every two seconds. This program will make your rover wander randomly about the room!

Notice that each wheel gets a different random number, so the Finch will mostly turn but sometimes move straight. The random number for rotation servo 2 is multiplied by -1 to make this number negative.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image1-1-768x268.png))

CHALLENGE

Use the pick random block to set the rover headlights to different random colors as the Finch moves randomly around the room.

Click Here to see example code.

Randomness with Variables

If you want to set both headlights to the same random color, you can add a variable to your program. Create a variable called red. If you need more information about how to make and use a variable, refer to the Variables module.

Set your variable equal to a random number between 0 and 100. Then set the amount of red for the tri-color LEDs to red.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image27-1.png))

CHALLENGE

Create two variables, green and blue. Set each of these variables to a random number, and then use these variables to set the amount of green and blue light for both tri-color LEDs. When you are done, your program should set both tri-color LEDs to the same random color every second.

Click Here to see example code.

Rover: Radio Control

((vim videoid=5plav983gw wl=1))
((img class=img-responsive src=))

The Radio module covers how to send numbers and strings from one micro:bit to another. You can also send both a number and a string at the same time. This enables you to send labeled values from one micro:bit to another. This module will show you how to use this functionality to drive the rover using the accelerometer in a second micro:bit. When you tilt the second micro:bit, the rover will move and turn.

You will need an extra micro:bit for this module.

The Acceleration Block

Start by programming the micro:bit that you will use as the remote control. We will call this the sending micro:bit.

The micro:bit accelerometer measures any force that causes acceleration in the x-, y-, or z-direction. Because the micro:bit is usually moving pretty slowly, the accelerometer mostly measures the acceleration due to gravity. When the micro:bit is sitting on a level surface, the acceleration due to gravity points down perpendicular to the surface of the micro:bit, along the negative z-axis. If you instead position the micro:bit so that button B is toward the ground, the acceleration due to gravity points along the positive x -axis. The acceleration block on the Input menu enables you to measure these differences.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image26-1.png))

To use the acceleration block, select the axis (x, y, or z) in the block. The block will report the acceleration in that direction in milligravities. Each acceleration value is roughly between -1000 and 1000. As an example, this code varies the icon shown on the micro:bit based on whether or not the x-value of the accelerometer is greater than 500 mg. 

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image23-1-768x505.png))

CHALLENGE

Modify the program above so that the micro:bit shows a third icon when the y-value of the acceleration is more than 500 mg.

Click Here to see example code.

Sending Labeled Values with Radio

To control the rover, we need to send the x– and y-values of the acceleration from the sending micro:bit to the rover. To send a number with a label, use the radio send value block from the Radio menu. For example, the code below will send the x-value of the accelerometer with the label “xaccel.”

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image9-1-768x409.png))

CHALLENGE

Modify the code above so that it also sends the y-value of the accelerometer with the label “yaccel.”

Click Here to see example code.

Receiving Labeled Values with Radio

The rover can receive the values from the sending micro:bit using the on radio received block that contains two variables, name and value. For example, the code below checks to see if the name of the value is “xaccel.” If it is, then the program loads the value into a variable called xaccel.

Remember, both the rover and the micro:bit sending messages must be set to the same radio group.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image14-1.png))

CHALLENGE

Modify the code above so that when it receives a value labeled “yaccel,” it loads the value into a variable with the same name.

Click Here to see example code.

Using Acceleration Variables

Now that the rover is receiving the accelerometer values from the sending micro:bit, we can use them to control the rover. As an example, this code uses the yaccel variable to control the speed of rotation servo 1. Notice that the accelerometer value is divided by 10 to get a value between -100 and 100, the limits of the rotation servo speed.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image31-768x431.png))

CHALLENGE

Write a program that moves the rover forward or backward using the x-axis of the accelerometer.

Click Here to see example code.

Using Two Acceleration Variables

Now that you are using the yaccel variable to move forward and back, it would be nice to use the  xaccel variable to turn the rover. However, first you have to decide if the robot should be turning. You can do this based on which acceleration value is larger. If the absolute value of yaccel is larger than the absolute value of xaccel, then the robot should move in a straight line. Otherwise, the robot should turn.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image32-768x334.png))

CHALLENGE

Use the sample code above to write a program that moves the robot forward or backward using the yaccel variable when absolute yaccel value is larger than the absolute xaccel value. Otherwise, the robot should turn left or right using the xaccel variable.

Click Here to see example code.

Rover: Compass

((vim videoid=r7cdqnrxhi wl=1))
((img class=img-responsive src=))

In this module, you will learn to use the compass that is on the micro:bit to make your robot move in a particular direction. 

The compass tells you the direction of your micro:bit relative to magnetic north. You can make your rover drive north while avoiding obstacles!

The Compass Heading Block

Use the compass heading block on the Input menu to read the value of the compass.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image12-1.png))

This value will be between 0° and 359°. 0° corresponds to the direction of magnetic north. The angle increases as the robot turns clockwise, so 90° is east, 180° is south, and 270° is west.

To use the compass, the micro:bit must be positioned so that the LED display is parallel to the ground. Otherwise, the compass will not provide useful measurements. When you use the compass, the micro:bit will prompt you to tilt it to calibrate the compass.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image14-768x649.png))

CHALLENGE

Write a program that displays the value of the compass on the micro:bit screen when you press button A. Examine how this value changes as you turn the rover.

Click Here to see example code.

Displaying Direction

You can use the compass to make the rover tell you the direction it is heading in. 

For example, if the value of the compass is between 45 and 135, print “E” on the micro:bit screen.

You can use the and block on the Logic menu to combine comparisons. The and block will be true only when both Boolean blocks inside it are true.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image16-1-768x283.png))

CHALLENGE

Add a second if else block to your script as shown. Modify the nested if else so that the micro:bit says “S” when the value of the compass is between 135 and 225.

Click Here to see example code.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image32-768x334.png))

Driving with the Compass

You can also use the compass to make the rover move in a particular direction. For example, this code makes the robot turn clockwise when the compass is less than 180° and counterclockwise otherwise. Try placing the rover in different positions before running this script. Which direction does the rover drive in?

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image30.png))

CHALLENGE

Modify your program so that the robot drives south as long as there is no obstacle in the way. When the robot encounters an obstacle, it should back up and turn.

Click Here to see example code.

Rover: Line Tracking

((vim videoid=4yigib6d22 wl=1))
((img class=img-responsive src=))

In this module, you will learn to use an LED and a light sensor to enable the rover to track a line.

Making a Line Tracking Sensor

You will use a single color LED and a light sensor to create a line tracking sensor. To track a black line on a light-colored surface, you need to know whether the sensor is over a black surface or a white surface. You can determine this by measuring the amount of light reflected by the surface. A white (or light-colored) surface reflects a lot of light, while a black surface reflects very little light.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/linetracking-schematic-768x475.png))

In addition to a single color LED and a light sensor, you will need a piece of cardboard that is roughly 8 cm by 15 cm and a metal brad.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/build1-768x564.png))

Poke holes in the cardboard so that you can mount the LED and the light sensor close together along one of the long edges of the cardboard. Use the metal brad to hold the light sensor in place.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/build2-768x534.png))

Glue the piece of cardboard to the bottom of the rover’s rotation servos, the LED and the light sensor should be pointing at the ground and 1-2 cm away from the ground.

Connect the single color LED to LED port 1 and the light sensor to sensor port 2.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/build3-768x283.png))

Making a Line to Track

To create a line to track, you will need large sheets of white paper and black electrical tape about 2 cm wide. Use the tape to make a black line on a white background. Avoid sharp turns; it is easier for the rover to follow gradual curves.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2019/12/image1-7-1.png))

Basic Line Tracking

To track a line, the rover should turn right or left based on whether or not it detects the line. Let’s think about tracking the left side of the line as the rover moves clockwise around the loop. When the line sensor is over the black line, the rover should turn left. When the line sensor is over the white line, the rover should turn right. 

Notice that this sample code uses the rotation servos to turn using only one wheel at a time. This means that both turns move the robot slightly forward. As the program repeats the if else block over and over, the rover will follow the line as it turns back and forth. 

Note: Rotation servos can vary a lot, so what is a slow speed for one motor may not be for another motor. For example, in the sample code one motor is running at 20% while the other runs at -50%.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/makecodelinetrack1-768x604.png))

CHALLENGE

Try out this code. You may need to adjust the line sensor threshold; use the upper-right script that prints the value of the light sensor when you press button A. You may also need to adjust and the turning speed of each rotation servo in order to track your line.

More Line Tracking

You can combine line tracking with other robot behaviors to make more complex programs! For example, the robot can track the line only until it finds an obstacle or hears a loud noise.

CHALLENGE

Write a program that makes the rover track a line but stops the rover when there is an obstacle in front of it.

Click Here to see example code.

Flower: Sensor Control

((vim videoid=bf4cw06uch wl=1))
((img class=img-responsive src=))

In this module, you will write MakeCode programs to control a robotic flower. You will need a flower for this module, so use these instructions to build one if you haven’t already.

You should also connect a dial sensor to sensor port 1 for this module.

Note: The flower modules assume that you have already completed the modules in the Inputs and Outputs sections.

The Dial Sensor

You will start by using the Bit dial sensor to control the LEDs.

A convenient way to see the value of the sensor is to use the show number block on the Basic menu. Use an on button pressed block to display the value of the sensor on the screen when you press button A.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image12-5-768x180.png))

CHALLENGE

Use the dial to control the brightness of the single color LEDs.

Click Here to see example code.

Math Blocks with the Dial

You can also use the blocks on the Math menu to change the behavior of your program. For example, this program will also make tri-color LED 1 gradually change from blue to red as you turn the dial from 0 to 100.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image19-5-768x547.png))

CHALLENGE

Modify your project as follows:

  • LED 2 should go from fully on to fully off as you turn the dial from 0 to 100.
  • Tri-color LED 2 should change from red to blue as you turn the dial from 0 to 100.

Click Here to see example code.

The Accelerometer

You can also use the accelerometer to control how much the flower blooms. 

The micro:bit accelerometer measures how much the micro:bit is tilting in three different directions, which are called x, y, and zThe value of the acceleration is between -1024 mg and 1024 mg for each direction. 

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/microbitaccel-768x388.png))

You can measure the acceleration in the x, y, and z directions using the acceleration block on the Input menu.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image22-4.png))

CHALLENGE

Write a program to see the x-value of the accelerometer change as you tilt the Hummingbird in different directions. For an extra challenge, display the y– and z-values of the accelerometer as well.

Click Here to see example code.

Math Blocks with the Accelerometer

The x-value of the acceleration is between -1024 and 1024.  To make the flower bloom, we want to use this value to calculate an angle for the position servo. 

For example, if we calculate the angle by dividing the x-value of the acceleration by 25 then as the x-value of the acceleration changes from 0 to 1024, the angle will change from 0° to about 41°.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image5-5-768x673.png))

CHALLENGE

Adjust the program so that the flower fully blooms as you tilt the Hummingbird Bit to the left (so that the sensor ports are toward the table and the LED ports point toward the ceiling).

Click Here to see example code.

CHALLENGE

The flower doesn’t bloom when you tilt the Bit to the right because the micro:bit x-acceleration is less than 0. How can you make your flower bloom when you tilt the Bit to the right or left?

Hint: You can do this using an if else block or a block from the Math menu.

Click Here to see example code.

Flower: Control with Variables

((vim videoid=bf4cw06uch wl=1))
((img class=img-responsive src=))

In the previous module, you used the dial and the micro:bit accelerometer to make the flower bloom and its lights dim, brighten, and change colors. 

In this module, you will program the flower to do these things automatically.

The repeat Block

You have been using forever loops to repeat blocks. You can also use the repeat block on the Loops menu. 

This block repeats whatever is inside it a certain number of times. 

For example, this code will make an LED turn on and off 10 times.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image13-4-768x509.png))

CHALLENGE

Write a program to make the flower open and close 5 times.

Click Here to see example code.

Loops with Variables

To make the flower bloom gradually, you will use the repeat block with a variable. A variable is a name that represents a value. You can use it to store information.

Go to the Variables menu and click Make a Variable. Name your variable count.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image6-5.png))

You will notice that the Variables menu looks different now. It contains a block for your variable and blocks to change its value.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image8-6.png))

CHALLENGE

Try out this code and watch the value of count. What does the change by block do? How does the value of count at the end of the script depend on the number in the repeat block?

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image1-6.png))

Loops with Variables

Make your flower bloom gradually using  the repeat block and count. Set the number in the repeat block to be the “full bloom” angle for your flower (yours may be different than 90°). Each time through the loop, set the position servo to count and stop briefly. You can vary the length of the wait to make your flower bloom more slowly.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image3-5.png))

To make the flower bloom repeatedly, place the code inside a forever loop.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image21-5.png))

CHALLENGE

With one repeat block, the flower blooms gradually and then closes quickly. To make the flower close gradually as well, add a second repeat block. Make the angle of the servo go from 90° to 0° by changing count by -1.

Click Here to see example code.

Adding Loops

You can also use a variable to change the color of the tri-color LEDs. 

Add a second variable and a second forever loop with a repeat inside. To make the LED change from green to red, use a subtraction block to make green decrease from 100 to 0 as red increases from 0 to 100.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image18-5.png))

CHALLENGE

Add two more repeat blocks to your tri-color LED script. Make the LED change from green to red, then red to blue, then blue back to green. Make the program repeat this sequence until you press the stop button.

Click Here to see example code.

CHALLENGE

Add two more repeat blocks to your tri-color LED script. Make the LED change from green to red, then red to blue, then blue back to green. Make the program repeat this sequence until you press the stop button.

Click Here to see example code.

For Loops

MakeCode also contains a loop called a for loop.The for block on the Loops menu is a loop that creates a variable called index. The variable index automatically changes from the first value specified in the for block to the second. Each time through the loop, the value of index automatically changes by one. This means that this program also gradually changes tri-color LED 1 from green to red! In this lesson, we focus on declaring our own variables, but you can explore how to use for blocks in your Hummingbird programs.

((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image7-6.png))

CHALLENGE

Make the flower gradually bloom and close using for loops.

Click Here to see example code.

Back to Top