# Welcome to KidsCode

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-M8txYtqhIXm2xQfrA1P%2F-M8tyH_CNAlAOOLYnJpa%2FArduinoEducation_Logo-02.svg?alt=media\&token=a4eb5991-8be6-4cb6-bbd4-adbbd996ad42)

{% hint style="info" %}
**Teach kids the basics of Electronics and Coding using the Arduino Uno and mBlock. mBlock allows kids to code using block programming**

Click [here](https://docs.kidscode.co.za/arduino-kids-lessons/setting-up-mblock) to get stated
{% endhint %}

{% hint style="warning" %}
**Setup an Arduino Bluetooth car?**

Click [here](https://docs.kidscode.co.za/arduino-robot-car/arduino-bluetooth-car) to get stated
{% endhint %}

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-LssPsPo_ohpvqfa7bqh%2F-LssQ3d-4svFUSF15qFe%2Fmicrobit-logo-stacked.png?alt=media\&token=b9c6d115-bae4-4a41-bbc6-84f6dd2b101d)

{% hint style="success" %}

#### This blog was created to help kids learn how to code using the BBC micro:bit

Click [here](https://docs.kidscode.co.za/microbit-beginners/micro-bit-the-hardware) to get started
{% endhint %}


# Setting up mBlock

## What will we do

In this lesson we will show you how to setup and use the the web based mBlock IDE.

To understand more about mBlock, please visit this [link](https://www.mblock.cc/doc/en/quick-start/quick-start.html)

## Launching mBlock

Go to <https://ide.mblock.cc/> on a **chrome** browser.

Under the devices section, click **Add** and select **Arduino Uno** from the selection list

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-M8tymYL7eqowqUT33a2%2F-M8u2Zj3e_-fENm16h0l%2Fmblock1.png?alt=media\&token=df1e9ea9-99d2-421d-ac5b-71dd7d67c316)

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-M8tymYL7eqowqUT33a2%2F-M8u2l78BQXE_uQOUFi9%2Fmblock2.png?alt=media\&token=402bc4fc-635c-4295-bc68-28c9aeb3dec2)

## Install the WebLink

Install the **WebLink** and following the details in this link <https://www.mblock.cc/doc/en/part-one-basics/mlink-quick-start-guide.html>

Once installed, test that you can connect to your device.

## Connect your Arduino Uno

Connect you Arduino to your PC using the USB Cable

Click in the **Connect** button

![Click on Connect](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-M8u2n0RTB0Hwt41tfbr%2F-M8u92QkE7ucq6A-1lMw%2Fmblock3.png?alt=media\&token=5042732d-eead-4bc9-b0b8-28c439d6dac5)

Select on the check box and select your device

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-M8u2n0RTB0Hwt41tfbr%2F-M8u9CRaWgocax9xbyCK%2Fmblock4.png?alt=media\&token=97935f7f-0187-4c16-9197-a8b204e7f36f)

## Troubleshooting


# Arduino Beginner Lessons

Learn the basics of Arduino using block programming. Great lessons to get your started.

## Components needed

* Arduino compatible UNO R3 development board
* USB cable
* Mini 300TP breadboard
* Red, Green and Yellow LED's
* Push button switch
* Passive buzzer (piezo buzzer)
* Resistors
* Jumper Wire

You can purchase a Arduino Beginner kit from [here](https://www.robofactory.co.za/arduino-kits/127-arduino-uno-r3-beginner-kit.html)<br>

## Lessons

* [Setting up mBlock](/setting-up-mblock)
* [Blinking and LED](/microbit-advanced-activities/blinking-an-led)
* [LED Chasing](/arduino-lessons/arduino-beginner-lessons/led-chasing)
* [Traffic Light](/arduino-lessons/arduino-beginner-lessons/traffic-signal)
* [Using a Buzzer](/arduino-lessons/arduino-beginner-lessons/buzzer)
* [Buzzer and Push Button](/arduino-lessons/arduino-beginner-lessons/buzzer-+-push-button)
* [LED and Push Button](/arduino-lessons/arduino-beginner-lessons/push-button)


# Blinking an LED

## What will we do

Lets start by making our LED blink on and off. The way to make an LED blink is to follow this sequence of code instructions over and over again:

* Turn the LED on
* Delay for a period of time
* Turn the LED off
* Delay for a period of time

{% hint style="success" %}
Please ensure that you have mBlock setup on you computer. Click [here](/setting-up-mblock) to setup mBlock
{% endhint %}

## Parts List

You will need the following parts:

* **1x** arduino uno
* **1x** arduino USB Cable
* **1x** Breadboard
* **2x** Jumper Wire
* **1x** LED&#x20;
* **1x** Resistor

You can purchased an Arduino kit from [here](https://www.robofactory.co.za/arduino-kits/66-arduino-uno-r3-basic-starter-kit.html)

{% embed url="<https://www.robofactory.co.za/arduino-kits/66-arduino-uno-r3-basic-starter-kit.html>" %}

## Wiring it up

This example we use a red LED but you can use any colour LED you prefer.&#x20;

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-M6KHBUnLmM-6jNl9924%2F-M6KHTrk_yIYi1duHidc%2Farduino%20-%20blinking%20led.png?alt=media\&token=57c44282-de3a-45f4-ada5-2c9e67a912de)

Ensure that the LED are the right way around, with the longer positive leads (anodes) to the left.

## mBlock IDE

Launch the mBlock IDE (<https://ide.mblock.cc/#/>) and select the Arduino Uno Device.

## Install the KidsCode Extension

Click on the **Extensions** button

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-M8u9rabTwe6GN62i0bu%2F-M8uBMB0jm_-3yp5yWJs%2Fmblock5.png?alt=media\&token=b88847e5-13c9-4b6f-9cea-7c93e8f5770b)

Search for **Kids Code** on the extension popup and **Add** the **Kids Code** extension

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-M8u9rabTwe6GN62i0bu%2F-M8uB_6GFdx-58Cn_h6N%2Fmblock6.png?alt=media\&token=92d5573d-0ad6-4c39-bcf3-2183e2659160)

You will see the Kids Code blocks at the bottom.

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-M8u9rabTwe6GN62i0bu%2F-M8uBikg1oFHvXTBDbgm%2Fmblock7.png?alt=media\&token=4d43856f-40d7-463b-b974-741962c53ab9)

## Block Coding

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-M8uBl-uQq0KWFVLZyrn%2F-M8uCTow5gKV-denwxpd%2Fcode1.png?alt=media\&token=b9a70f76-8ac6-4302-a974-ce976cb1f040)

{% embed url="<https://ide.mblock.cc/#/?cloudProjectId=262516>" %}


# LED Switching

## What will we do

In this lesson we will learn how to switch two LED’s on and off one at a time. It will work in the following sequence

* Turn Red LED ON
* Wait for 1 second
* Turn Red LED OFF and Yellow LED ON
* Wait for 1 second

Run the above code for 8 times.

{% hint style="success" %}
Please ensure that you have mBlock setup on you computer. Click [here](/setting-up-mblock) to setup mBlock
{% endhint %}

You purchased your Arduino kit from [here](https://www.robofactory.co.za/arduino-kits/66-arduino-uno-r3-basic-starter-kit.html)

{% embed url="<https://www.robofactory.co.za/arduino-kits/66-arduino-uno-r3-basic-starter-kit.html>" %}

## Parts List

You will need the following parts:

* **1x** arduino uno
* **1x** arduino USB Cable
* **1x** Breadboard
* **3x** Jumper Wire
* **2x** LED (RED and Yellow)
* **2x** Resistor

## **Wiring it up**

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-M8uEe36HCdRQ0VD4W-5%2F-M8uF5W0gT0EuzpVY4Vr%2Fled%20switching.png?alt=media\&token=72760c4b-cf1c-41e8-8a3d-7671295a92a7)

Ensure that the LED are the right way around, with the longer positive leads (anodes) to the left.

## mBlock IDE

Launch the mBlock IDE (<https://ide.mblock.cc/#/>) and select the Arduino Uno Device and install the [Kids Code Extension](https://docs.kidscode.co.za/arduino-kids-lessons/blinking-an-led#install-the-kidscode-extension)&#x20;

## Block Coding <a href="#block-coding" id="block-coding"></a>

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-M8uEe36HCdRQ0VD4W-5%2F-M8uFI0ZKPAaRf3RsQoG%2Fled-switching-code.png?alt=media\&token=cd848c84-71fd-427c-b427-450c47e40327)

{% embed url="<https://ide.mblock.cc/#/?cloudProjectId=262531>" %}


# LED Chasing

## What will we do

In this lesson we will add one more LED and create a light chasing effect. We will use 3 of the same color LED’&#x73;**.**

The sequence for the code will be as follows

* Turn LED1 ON
* Wait for 0.5 second
* Turn LED1 OFF and LED2 ON
* Wait for 0.5 second
* Turn LED2 OFF and LED3 ON
* Wait for 0.5 second
* Turn LED2 ON and LED3 OFF
* Wait for 0.5 second
* Turn LED2 OFF and LED1 ON

## Parts List

You will need the following parts:

* **1x** arduino uno
* **1x** arduino USB Cable
* **1x** Breadboard
* **3x** Jumper Wire
* **3x** LED (all same colour)
* **3x** Resistor

{% hint style="success" %}
Please ensure that you have mBlock setup on you computer. Click [here](/setting-up-mblock) to setup mBlock
{% endhint %}

You purchased your Arduino kit from the [here](https://www.robofactory.co.za/arduino-kits/66-arduino-uno-r3-basic-starter-kit.html)

{% embed url="<https://www.robofactory.co.za/arduino-kits/66-arduino-uno-r3-basic-starter-kit.html>" %}

## **Wiring it up** <a href="#wiring-it-up" id="wiring-it-up"></a>

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-M8uFvpZUQF6EAMa4V3F%2F-M8uHeu1tiNQC2aPMR7m%2Fled%20chasing.png?alt=media\&token=a35967f3-cd03-42e7-b9a2-e17f377c8af4)

Ensure that the LED are the right way around, with the longer positive leads (anodes) to the left.

## mBlock IDE

Launch the mBlock IDE (<https://ide.mblock.cc/#/>) and select the Arduino Uno Device and install the [Kids Code Extension](https://docs.kidscode.co.za/arduino-kids-lessons/blinking-an-led#install-the-kidscode-extension)&#x20;

## Block Coding <a href="#block-coding" id="block-coding"></a>

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-M8uIg8-I0DOXGuIqp1S%2F-M8uIrp0mx1HIy1Qd1Dv%2Fled%20chasing%20-%20code.png?alt=media\&token=3c64d355-5f92-4109-a91c-44d5e5439303)

{% embed url="<https://ide.mblock.cc/#/?cloudProjectId=262546>" %}


# Traffic Signal

## What will we do

This example uses three LEDs to make a model traffic light signal. You can use all red LEDs if you like, but its more realistic if you use red, yellow and green.

The LEDs cycle around in the sequence red, green, yellow and then back to red again

{% hint style="success" %}
Please ensure that you have mBlock setup on you computer. Click [here](/setting-up-mblock) to setup mBlock
{% endhint %}

## Parts List

You will need the following parts:

* **1x** arduino uno
* **1x**  arduino uno USB Cable
* **1x** Breadboard
* **4x** Jumper Wire
* **1x** Red LED&#x20;
* **1x** Yellow LED&#x20;
* **1x** Green LED&#x20;
* **3x** Resistors

You purchased your Arduino kit from [here](https://www.robofactory.co.za/arduino-kits/66-arduino-uno-r3-basic-starter-kit.html)

{% embed url="<https://www.robofactory.co.za/arduino-kits/66-arduino-uno-r3-basic-starter-kit.html>" %}

## Wiring it up

To add the extra LEDs and resistors, wire them up as shown in the breadboard layout below.

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-M6H9rHABIe5CWjXSbTZ%2F-M6K-wdOruxOMdb9XH89%2Farduino%20-%20traffic%20lights.png?alt=media\&token=c56fa9de-6907-483a-b542-456d5e855812)

Ensure that the LEDs are the right way around, with the longer positive leads (anodes) to the left.

## How does it work

Think of how a traffic light works.

* it starts from RED
* then turns to GREEN
* then turns YELLOW
* and back to RED

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-M6KLy8-3oUWa3-92S7q%2F-M6LMH_ZFSbZht4Bqiz2%2Fpower1.png?alt=media\&token=94406626-8015-4650-9037-ae1394c96c15)

Think about the how long the light stays on before it changes to the next colour

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-M6KLy8-3oUWa3-92S7q%2F-M6LMplfuoEatb7x9yrU%2Fpower2.png?alt=media\&token=8db1fcc5-a85c-49e3-a942-90475ec44b18)

This time that it takes before the light changes is called a WAIT in coding. So the program will **WAIT** for a specific number of seconds before the next light changes to the next colour

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-M6KLy8-3oUWa3-92S7q%2F-M6LNKe6UnKLPMT7CmnY%2Fpower3.png?alt=media\&token=2535e64d-7703-4409-9c7f-0124a9d04491)

In order to turn the light ON or OFF in code, we say that if we want the light on then we need to set it to HIGH and if we want the light OFF we setup it to LOW.

So to change the traffic lights we say

* to make the light ON, we set it to HIGH
* to make the light OFF, we set it to LOW

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-M6LNug-fXp3ELa2TqD3%2F-M6LNyHlKS2nBCXMb_6q%2Fpower4.png?alt=media\&token=7d14ff6e-e7f2-4e79-a0be-c3c0d8c11636)

If you look at the wiring diagram above, you will see that we connected it as follows

* we connected **DIGITAL PIN 7** **(D7)** to the **RED** light
* we connect **DIGITAL PIN 6 (D6)** to the **YELLOW** light
* we connect **DIGITAL PIN 5 (D5)** to the **GREEN** light

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-M6LO-6q6GR9IgAvFCkZ%2F-M6LOWuUVYq4b0Gk5g-y%2Fpower5.png?alt=media\&token=8088e2eb-a34c-4514-af62-46a18997ba8c)

So In order for the program to work we will do the following

* set **D7** to **HIGH** (red light)
* set **D6** to **LOW** (yellow light)
* set **D5** to **LOW** (green light)
* ***WAIT** for 10 seconds*
* set **D7** to **LOW** (red light)
* set **D6** to **LOW** (yellow light)
* set **D5** to **HIGH** (green light)
* ***WAIT** for 10 seconds*
* set **D7** to **LOW** (red light)
* set **D6** to **HIGH** (yellow light)
* set **D5** to **LOW** (green light)
* ***WAIT** for 1 seconds*

## Block Coding <a href="#block-coding" id="block-coding"></a>

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-M8uIx29lznRqBVCJXZ8%2F-M8uKqqdG1OQFmdAcfUd%2Ftraffic%20light%20-%20code.png?alt=media\&token=92fcb668-4723-49b7-be81-5df5eba1ede8)

{% embed url="<https://ide.mblock.cc/#/?cloudProjectId=262563>" %}


# Buzzer

## What will we do

This example will show you how to wire up a buzzer and play a sound.

## Parts List

You will need the following parts:

* **1x** arduino uno
* **1x**  arduino uno USB Cable
* **1x** Breadboard
* **2x** Jumper Wire
* **1x** Piezo Buzzer

{% hint style="success" %}
Please ensure that you have mBlock setup on you computer. Click [here](/setting-up-mblock) to setup mBlock
{% endhint %}

You purchased your Arduino kit from [here](https://www.robofactory.co.za/arduino-kits/66-arduino-uno-r3-basic-starter-kit.html)

{% embed url="<https://www.robofactory.co.za/arduino-kits/66-arduino-uno-r3-basic-starter-kit.html>" %}

## Wiring it up

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-M6PUI7Rw78wyY-sriVE%2F-M6PWD-XaglCAWCEkGyi%2Farduino%20-%20buzzer.png?alt=media\&token=71e7e155-738a-4da4-b724-11a057681f3c)

Ensure that the buzzer are the right way around, with the positive lead to the left.

## Block Coding <a href="#block-coding" id="block-coding"></a>

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-M6PHk-NPMejaejAmPdb%2F-M6PT6ONvxHtboYJs59o%2Farduino%20-%20buzzer%20code.png?alt=media\&token=a3143a95-7e95-4eac-953f-ee84e0d82b1a)

{% embed url="<https://ide.mblock.cc/#/?cloudProjectId=218898>" %}

## &#x20;<a href="#block-coding" id="block-coding"></a>


# Buzzer + Push Button

## What will we do

This example is an extension of the [buzzer tutorial](https://docs.kidscode.co.za/arduino-lessons/buzzer). We will now add a push button to restart the buzzer.&#x20;

## Parts List

You will need the following parts:

* **1x** arduino uno
* **1x** arduino uno USB Cable
* **1x** Breadboard
* **4x** Jumper Wire
* **1x** Piezo Buzzer
* **1x** Push button switch
* **1x** Resistors

{% hint style="success" %}
Please ensure that you have mBlock setup on you computer. Click [here](/setting-up-mblock) to setup mBlock
{% endhint %}

You purchased your Arduino kit from [here](https://www.robofactory.co.za/arduino-kits/66-arduino-uno-r3-basic-starter-kit.html)

{% embed url="<https://www.robofactory.co.za/arduino-kits/66-arduino-uno-r3-basic-starter-kit.html>" %}

## Wiring it up

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-M6PWGATcwRqUb5i6zZm%2F-M6PYfnVUVQ1tHgKcsws%2Fbuzzer%20%2B%20push%20button.png?alt=media\&token=eefd7647-076e-4858-9a3d-aff7f0dfbe47)

Ensure that the buzzer are the right way around, with the positive lead to the left.

## Block Coding <a href="#block-coding" id="block-coding"></a>

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-M6PWGATcwRqUb5i6zZm%2F-M6PYjl7mKa65uzfdzsT%2Fbuzzer%20%2B%20push%20button%20code.png?alt=media\&token=c3d34839-eff6-44fb-9506-338bd13330ba)

{% embed url="<https://ide.mblock.cc/#/?cloudProjectId=218945>" %}


# LED + Push Button

## What will we do

This example uses 2 LEDs and a switch to make an ON/OFF door lock. When the RED LED is ON then the door lock is closed. When you press the BUTTON, door will open and the RED LED will be off and the GREEN LED will be ON.

## Parts List

You will need the following parts:

* **1x** arduino uno
* **1x**  arduino uno USB Cable
* **1x** Breadboard
* **5x** Jumper Wire
* **1x** Red LED&#x20;
* **1x** Green LED&#x20;
* **1x** Push button switch
* **3x** Resistors

{% hint style="success" %}
Please ensure that you have mBlock setup on you computer. Click [here](/setting-up-mblock) to setup mBlock
{% endhint %}

You purchased your Arduino kit from [here](https://www.robofactory.co.za/arduino-kits/66-arduino-uno-r3-basic-starter-kit.html)

{% embed url="<https://www.robofactory.co.za/arduino-kits/66-arduino-uno-r3-basic-starter-kit.html>" %}

## Wiring it up

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-M6P4jbJShCfxTkf9fUe%2F-M6PGee2UzMUQaU1Zzhm%2Farduino%20-%20push%20button.png?alt=media\&token=6560d5d4-3c82-4078-b5bc-0189c83b02c0)

Ensure that the LEDs are the right way around, with the longer positive leads (anodes) to the left.

## Block Coding <a href="#block-coding" id="block-coding"></a>

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-M6M10kB3c5xeZ-_KHRp%2F-M6M1KjiCGa6nTusYnSj%2Farduino%20-%20push%20button%20code.png?alt=media\&token=2fbb324d-a51c-496c-b197-da811971fa02)

{% embed url="<https://ide.mblock.cc/#/?cloudProjectId=218454>" %}


# Bluetooth LED

## What will we do

In this lesson we will learn how to switch an LED’s on and off from our Android phone using a bluetooth module.

We will wire up our circuit to include a LED and a Bluetooth module. We will also write some code that will read a character for the Android app that will tell the LED to come on and go off.

we will use character **a** to turn on the LED and character **b** to switch off the LED

The Android app can be downloaded [here](https://kidscode.nyc3.digitaloceanspaces.com/kides_code_arduino_led.apk).

{% hint style="success" %}
Please ensure that you have mBlock setup on you computer. Click [here](/setting-up-mblock) to setup mBlock
{% endhint %}

## Parts List

You will need the following parts:

* **1x** arduino uno
* **1x** arduino USB Cable
* **1x** Breadboard
* **7x** Jumper Wire
* **1x** LED (any colour)
* **1x** Resistor
* **1x** HC-05 Bluetooth module.

I purchased my module from this [store](https://www.robofactory.co.za/arduino-modules/88-bluetooth-transceiver-module.html).

{% embed url="<https://www.robofactory.co.za/arduino-modules/88-bluetooth-transceiver-module.html>" %}

## **Wiring it up** <a href="#wiring-it-up" id="wiring-it-up"></a>

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-M9FD18fIvknZHDfiLjV%2F-M9FDn-c9VcGtR9NM1ZH%2FBluetooth%20LED.png?alt=media\&token=a25572ff-aba1-4aba-965b-6529e834da36)

## mBlock IDE

Launch the mBlock IDE (<https://ide.mblock.cc/#/>) and select the Arduino Uno Device and install the [Kids Code Extension](https://docs.kidscode.co.za/arduino-kids-lessons/blinking-an-led#install-the-kidscode-extension)&#x20;

## Block Coding <a href="#block-coding" id="block-coding"></a>

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-M9FD18fIvknZHDfiLjV%2F-M9FEIyxew4kOY2eX9oh%2FBluetooth%20LED%20-%20code.png?alt=media\&token=617eb044-0d35-4208-ad8f-8d1a5496e961)

You can find the green coding blocks under **Bluetooth HC-05** at the bottom of your block list

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-M9FD18fIvknZHDfiLjV%2F-M9FErs9j2o9vJaJ2Bch%2Fpic1.png?alt=media\&token=75010637-dba1-457e-88b8-cd3ff52bc40f)

## Block Coding Explained <a href="#block-coding" id="block-coding"></a>

1. Using the green **Start Bluetooth HC-05** block you initialize the Bluetooth
2. You need to check if the bluetooth is receiving data, using the green  **HC-05 receiving data** block
3. If you receiving data then you will read the data from the Bluetooth using the **read data from HC-05** block.
4. You will then check if your received character **a** and then turn **ON** the LED at pin **D5**.
5. You will also  check if your received character **b** and then turn **OFF** the LED at pin **D5**.

{% hint style="info" %}
Please remove the green RX jumper from the Arduino board before you upload your code. If the jumper is not removed then you will get an error.
{% endhint %}

{% embed url="<https://ide.mblock.cc/#/?cloudProjectId=267234>" %}

## Testing your code <a href="#block-coding" id="block-coding"></a>

* Down the Android app from [here](https://kidscode.nyc3.digitaloceanspaces.com/kides_code_arduino_led.apk).
* Pair the bluetooth with your phone. Search for **HC-05** and pair this device. The password will be **1234**
* Open the app and press the Connect button

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-M9FGBcFKYnmQp8IpQCq%2F-M9FHQm45F7axTJ97XMe%2Fpic2.png?alt=media\&token=ea61c5b9-717d-4eeb-8e6d-881a629d6fb7)

* Select **HC-05** from the list.
* Once connected, press the **ON** button and your **LED** should light up.
* Press the **OFF** button and the LED will go **OFF**

&#x20;


# Arduino Bluetooth Car

Follow the below guide to build your own bluetooth Arduino Car.

## Contents

* [What you will need](/arduino-robot-car/arduino-bluetooth-car/what-you-will-need)
* [Circuit Diagram](/arduino-robot-car/arduino-bluetooth-car/circuit-diagram)
* [Assembly](/arduino-robot-car/arduino-bluetooth-car/assembly-the-car)
* [Code upload](/arduino-robot-car/arduino-bluetooth-car/upload-the-code)
* [Test](/arduino-robot-car/arduino-bluetooth-car/bluetooth-setup-and-test)

## Support

* Please log all support queries on our [github page](https://github.com/RoboFactorySA/arduino-bluetooth-car/issues)&#x20;


# What you will need

This guide will show you how to setup a 4WD Arduino Robot car and control with your phone with Bluetooth

## Components Required

* 1 X [Arduino UNO](https://www.robofactory.co.za/arduino-boards/85-arduino-uno-r3-compatible.html)
* 1 X [HC-05 Bluetooth Module](https://www.robofactory.co.za/arduino-modules/88-bluetooth-transceiver-module.html)
* 1 X [Car Chassis kit](https://www.robofactory.co.za/arduino-kits/169-4wd-robot-car-chassis-kit.html)
* 1 X [L298N motor drive](https://www.robofactory.co.za/arduino-modules/124-l298n-dual-stepper-motor-driver-board-module.html)
* 3 x [18650 battery](https://www.robofactory.co.za/accessories/201-rakieta-37v-2000mah-18650-lithium-battery.html)
* 1 X 3 way 18650 battery holder (the [Car Chassis kit](https://www.robofactory.co.za/arduino-kits/169-4wd-robot-car-chassis-kit.html) from [RoboFactory](https://www.robofactory.co.za/) does come with this battery holder)
* 1X [Male To Male Jumper Wires](https://www.robofactory.co.za/accessories/120-male-to-male-breadboard-jumpers-40pcs-20cm.html)
* 1X [Male To Female Jumper Wires](https://www.robofactory.co.za/accessories/121-male-to-female-breadboard-jumpers-40pcs-20cm.html)

> You can purchase the above from [RoboFactory](https://www.robofactory.co.za/11-arduino)

## Software Required

* [Arduino IDE](https://www.arduino.cc/en/main/software)
* [Arduino Bluetooth RC Car Android App](https://play.google.com/store/apps/details?id=braulio.calle.bluetoothRCcontroller)


# Circuit Diagram

The entire Circuit will be as below:

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-MRv1R-o1zGlxNjfl9On%2F-MRv1Z1IqB_aLwHgBUHa%2Ffritzing.png?alt=media\&token=4db4283c-75b5-42fc-989d-fcfd3589370e)

The 2 Left motors will connect to Motor A on the driver board

The 2 Right motors will connect to Motor B on the driver board

A 3 X 18650 battery pack **positive** will be connect to the **VSS / 12V** terminal on the driver board and the **negative** will be connected to the **GND** terminal on the driver board.

The Arduino board will be powered by the same 3 x 18650 battery pack. Connect a jumper from the **VSS / 12v** terminal on the motor board to the **VIN** on the Arduino board. Connect another jumper from the **GND** on the motor driver to **GND** on the Arduino board

The Motor driver will be connected to the Arduino board as per below connections:

* Motor driver ENA -> PIN 9 on Arduino Board
* Motor driver IN1 -> PIN 8 on Arduino Board
* Motor driver IN2 -> PIN 7 on Arduino Board
* Motor driver ENB -> PIN 3 on Arduino Board
* Motor driver IN3 -> PIN 5 on Arduino Board
* Motor driver IN4 -> PIN 4 on Arduino Board

The bluetooth module will be connected to the Arduino board as per below connections:

* Bluetooth VCC -> 5v on Arduino Board
* Bluetooth GND -> GND on Arduino Board
* Bluetooth TX > PIN RX on Arduino Board
* Bluetooth RX -> PIN TX on Arduino Board


# Assembly the Car

## Solder the motors

Solder each motor with a black and a red wire and attach them with the chassis.

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-MQ3XXL4wMmPzgMZKlI3%2F-MQ3YP_U33Y6vERbxWON%2Fimage.png?alt=media\&token=192b60d5-5ec4-48f8-b60a-926e2f958c1a)

## Attach the Motors

Attached the motors to the base of the car. Join the left side motor wires together as: **red wire --> red wire** and **black wire --> black wire,** similarly join the motors on right side together as: **red wire --> red wire** and **black wire --> black wire**

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-MQ3XXL4wMmPzgMZKlI3%2F-MQ3YWs__YQTzIpUByj6%2Fimage.png?alt=media\&token=ddbd7110-08e4-400c-a085-57a55297f44b)

## Attached the Wheels

Add the Wheels to the motors

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-MQ3XXL4wMmPzgMZKlI3%2F-MQ3Z0Y9sPas3Kya28Ga%2Fimage.png?alt=media\&token=0edd9856-9de2-4306-8a1d-437b01a87988)

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-MQ3XXL4wMmPzgMZKlI3%2F-MQ3Z4y2c9GO8VZV9M5n%2Fimage.png?alt=media\&token=9245c262-9bc3-480d-bd5f-6e342e0f896b)

You can also view the video below as a guide

{% embed url="<https://youtu.be/0YUQ4s5XZqY?list=PLVcrH7rfVz6vqat1z8NBMmJgz5W39i3GY>" %}

## Connect the Motor Driver

The Motor driver will be the **back** of the car. The Motor driver will have two connectors, one for Motor A and another for Motor B.

Looking at the car from behind, connect the **Left motors** to **Motor A** and the **Left motors** to **Motor B.**&#x20;

Remember that the two left motors will connect to a single Motor A and two right Motors will connect to a single Motor B on the motor driver

{% hint style="info" %}
Remember that the two left motors will connect to a single Motor A and two right Motors will connect to a single Motor B on the motor driver
{% endhint %}

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-MQ3XXL4wMmPzgMZKlI3%2F-MQ3_fncDlXcy_eLr_Sq%2Fimage.png?alt=media\&token=85ca89bc-471b-4d03-8002-9e7fb80eb7d0)

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-MQ3XXL4wMmPzgMZKlI3%2F-MQ3_jLlskUhfU5hiqIg%2Fimage.png?alt=media\&token=13128219-0b40-4370-a1d3-d43354a2a71a)

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-MQ3XXL4wMmPzgMZKlI3%2F-MQ3_m3MU0zQRFy7JA5Q%2Fimage.png?alt=media\&token=488eea99-f707-46d1-ae54-0a32f5a246e0)

## Connect the Motor Driver to the Arduino

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-MQ3XXL4wMmPzgMZKlI3%2F-MQ3_J8o6_eKydScCz-Y%2Fimage.png?alt=media\&token=aa754123-763f-414f-ac56-6c08f84b3e49)

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-MQ3XXL4wMmPzgMZKlI3%2F-MQ3_NjwC-5ISDdTENZp%2Fimage.png?alt=media\&token=0835c072-8575-43f1-bd15-428dc8292a4b)

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-MQ3XXL4wMmPzgMZKlI3%2F-MQ3_S1y2o7H8v7CMrUu%2Fimage.png?alt=media\&token=0a4f4f7f-0bcd-45da-b3f9-561d58faa428)

Connect the jumper wires as below:

**Please remove the jumper from ENA and ENB on the motor driver**

* Motor driver ENA -> PIN 9 on Arduino Board
* Motor driver IN1 -> PIN 8 on Arduino Board
* Motor driver IN2 -> PIN 7 on Arduino Board
* Motor driver ENB -> PIN 3 on Arduino Board
* Motor driver IN3 -> PIN 5 on Arduino Board
* Motor driver IN4 -> PIN 4 on Arduino Board

Connect the battery pack **positive** wire to the **VCC / 12V** terminal of the motor driver

Connect the battery pack **negative** battery to the **GND** terminal of the motor driver

Connect a jumper from the **VSS / 12v** terminal on the motor board to the **VIN** on the Arduino board. Connect another jumper from the **GND** on the motor driver to **GND** on the Arduino board

## Connect the Bluetooth Module to Arduino

Connect the Bluetooth module as shown below

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-MQ3f84sxyjwYr7HLSxQ%2F-MQ3gHwoWBvJyYq9QdFh%2Fimage.png?alt=media\&token=843a33bb-cca9-4b25-a6e5-90bdb2869a65)

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-MQ3f84sxyjwYr7HLSxQ%2F-MQ3gOns-Rnc7QgizArC%2Fimage.png?alt=media\&token=c654ce9f-a0d6-476a-9d1d-b756a8f5b658)

Now you are done with the car assembly. Next you need to upload the code to the Arduino board, download the App and test.


# Upload the Code

## Code upload

Open up your Arduino IDE.

Connect your USB cable to your PC and Arduino board.

{% hint style="warning" %}
Please ensure that the TX and RX for the Bluetooth module is not connected. If this is connected then the code upload will fail.
{% endhint %}

Copy the code below to a new Arduino project and Click the upload button

```
// Motor A (Right) connections
#define ENA 9       // Enable/speed motor Right wheels
#define IN_1  8    // Right wheels
#define IN_2  7    // Right wheels

// Motor B (Left) connections
#define ENB 3       // Enable/speed motor Left Right
#define IN_3  5    		// Left wheels
#define IN_4  4    		// Left wheels

int command; 			      //Int to store app command state.
int speedCar = 255; 		// 50 - 255.

void setup() {

  pinMode(ENA, OUTPUT);
  pinMode(ENB, OUTPUT);
  pinMode(IN_1, OUTPUT);
  pinMode(IN_2, OUTPUT);
  pinMode(IN_3, OUTPUT);
  pinMode(IN_4, OUTPUT);

  Serial.begin(9600);

}

void goAhead() {

  digitalWrite(IN_1, HIGH);
  digitalWrite(IN_2, LOW);
  analogWrite(ENA, speedCar);

  digitalWrite(IN_3, LOW);
  digitalWrite(IN_4, HIGH);
  analogWrite(ENB, speedCar);
}

void goBack() {

  digitalWrite(IN_1, LOW);
  digitalWrite(IN_2, HIGH);
  analogWrite(ENA, speedCar);


  digitalWrite(IN_3, HIGH);
  digitalWrite(IN_4, LOW);
  analogWrite(ENB, speedCar);
}

void goRight() {

  digitalWrite(IN_1, HIGH);
  digitalWrite(IN_2, LOW);
  analogWrite(ENA, speedCar);


  digitalWrite(IN_3, LOW);
  digitalWrite(IN_4, LOW);
  analogWrite(ENB, speedCar);
}

void goLeft() {

  digitalWrite(IN_1, LOW);
  digitalWrite(IN_2, LOW);
  analogWrite(ENA, speedCar);

  digitalWrite(IN_3, LOW);
  digitalWrite(IN_4, HIGH);
  analogWrite(ENB, speedCar);

}

void stopRobot() {

  digitalWrite(IN_1, LOW);
  digitalWrite(IN_2, LOW);
  analogWrite(ENA, speedCar);


  digitalWrite(IN_3, LOW);
  digitalWrite(IN_4, LOW);
  analogWrite(ENB, speedCar);
}

void loop() {

  if (Serial.available() > 0) {
    command = Serial.read();
    stopRobot(); 			//Initialize with motors stopped.

    switch (command) {
      case 'F': goAhead(); break;
      case 'B': goBack(); break;
      case 'L': goLeft(); break;
      case 'R': goRight(); break;
      case '0': speedCar = 100; break;
      case '1': speedCar = 115; break;
      case '2': speedCar = 130; break;
      case '3': speedCar = 145; break;
      case '4': speedCar = 160; break;
      case '5': speedCar = 175; break;
      case '6': speedCar = 190; break;
      case '7': speedCar = 205; break;
      case '8': speedCar = 220; break;
      case '9': speedCar = 235; break;
      case 'q': speedCar = 255; break;

    }
  }
}


```

{% hint style="success" %}
Once the code is uploaded successfully, connect RX of Hc-05 to TX of Arduino and TX of Hc-05 to RX of Arduino
{% endhint %}

## Install the Arduino App

Install the [Arduino Bluetooth RC Car](https://play.google.com/store/apps/details?id=braulio.calle.bluetoothRCcontroller\&rdid=braulio.calle.bluetoothRCcontroller) App.


# Bluetooth setup and Test

## Pair With Bluetooth Module

Disconnect the USB cable and connect all the batteries.

Check that the LED of Bluetooth module is **blinking fast without pairing**

Open up the App, you will see the a red flashing circle on the left. This means the bluetooth is not paired.&#x20;

Click on the Settings Icon and Select "Connect to Car". Select the **HC-05** bluetooth device and enter password **1234.**

Once the circle turns green, then the phone is connected. Use the Up, Down, Left, Right and Speed buttons to test your car.


# micro:bit, the hardware

{% embed url="<https://www.youtube.com/watch?v=RkWDYTx_mg4>" %}


# Overview of MakeCode

This lesson will teach your students how to use and navigate the MakeCode editor

To view the MakeCode editor, go to <https://makecode.microbit.org/> using the chrome browser

![MakeCode website](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-LskcML6iX1eVw_Fa0KA%2F-LskclQv7ySUOW6M71CY%2FMakeCode1.png?alt=media\&token=1464773f-ef91-4b77-b6ed-527e2515a128)

Then select ***"New Project"***

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-LskeMlK5PLwVKwL2v-w%2F-LskePep5bXfg7pvbrYc%2Fmakecode3.png?alt=media\&token=1c547368-21d5-469b-9d08-9e9045f15e41)

The MakeCode editor consists of the following components

* **Simulator** - on the left side of the screen, you will see a virtual micro:bit that will show what your program will look like running on a micro:bit.
* **Toolbox** - in the middle of the screen, there are a number of different categories, each containing a number of blocks that can be dragged into the programming workspace on the right.
* **Workspace** - on the right side of the screen is the Programming Workspace where you will create your program. Programs are constructed by snapping blocks together in this area.

The color of the blocks identifies their category. All of the blocks that make up the program above come from the **Basic** Toolbox category, which is light blue.


# Video Library

## Say Hello

{% embed url="<https://www.youtube.com/watch?v=kaNtg1HGXbY>" %}

### Using the MakeCode editor

{% embed url="<https://www.youtube.com/watch?v=MMqKMGeykM8>" %}


# Lesson 1

This lesson will teach your kids the basic components of the micro:bit, introduce them to the MakeCode editor and allow them to run their first program

### What will you learn in this lesson

* You will see and learn what a micro:bit is.
* You will learn about the different micro:bit components.
* You will learn how to connect your micro:bit to your computer.
* You will learn how to write your first program and upload it to your micro:bit
* You will learn about block programing and the MakeCode editor


# My micro:bit

This lesson will teach your kids the basic components of the micro:bit

{% hint style="success" %}

## Teachers Notes

In this lesson you will need to explain to your kids the different components of the micro:bit. You will need to have a real micro:bit in front of your and show them them components. You can also explain to then real life use cases for each component
{% endhint %}

## micro:bit components

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-LskgaOeASSwrLdBrnM2%2F-LskiI1rMdMcUPxCpUNP%2Fmicrobit-hardware-access.jpg?alt=media\&token=cf5034c7-2bf3-497c-b390-6d71bb1aa0ab)

## LEDs

An LED stands for Light Emitting Diode. It is a small component that lights up. The micro:bit has 25 individually-programmable LEDs, allowing you to display text, numbers, and images.&#x20;

*An example of this would be showing the number of a dice or showing the score of a game your playing.*&#x20;

*So with the mirco:bit we can  use this to display number, words and pictures.*

>

![25 LEDs on micro:bit](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-LskjQqHlsd77v1kK6n3%2F-LskjV7tfxnFEA1cX66y%2Fbeating-heart.gif?alt=media\&token=31bb71ab-1b66-4f19-a359-643ef3c182f2)

## Buttons

There are two buttons on the front of the micro:bit (labelled A and B). You can detect when these buttons are pressed, allowing you to trigger code on the device to do different things like display "A" when button A is pressed and display "B" when button B is pressed.

*An example of a button would be the ones on you remote for your TV.  When you press the button something happens on the TV.*&#x20;

*So with the mirco:bit we can use this create a dice, so when you press a button it give u a number.*

![micro:bit buttons A and B](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-LskjxYUTomtWHjpm2hk%2F-LskkbDAHUx7cmPpmjUy%2Fmicrobit-features-buttons.png?alt=media\&token=f587d9f5-06ff-4dc8-94ff-9800e533f3fc)

## Light Sensor

A light sensor has the ability to detect light or darkness. The LED screen works as a basic light sensor, allowing you to detect  light.

*An example of this would be to detect when it is dark outside and it means playtime is over.*

![LED can be used as a light sensor](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lskld_eex-nZmn54nqI%2F-LskmIXpEkJ4iPuuKlAt%2Fmicrobit-features-light.png?alt=media\&token=160d8b3f-c54c-421a-98d1-0b57c26f20a5)

## Temperature Sensor

A Temperature sensor allows you to measure how hot a cold it is. This sensor allows the micro:bit to detect the current temperature of the device

*An example of this would be a sensor in a car that tells you what the temperature is so we can also use this device to tell you how hot or cold it is.*

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lskld_eex-nZmn54nqI%2F-LsknAYtbHJsTdakr63Z%2Fmicrobit-features-temp.png?alt=media\&token=c2da9e07-7d5f-4f4e-991a-9279a9cf31e3)

## Accelerometer

An accelerometer measures the acceleration of your micro:bit; this component senses when the micro:bit is moved. It can also detect other actions, e.g. shake, tilt, and free-fall

*An example of this would be a sensor in a watch or phone that checks when the phone or watch is moved. This then helps you count the steps you take.*&#x20;

*So with the mirco:bit we can  also create a watch that will count our steps.*

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lskld_eex-nZmn54nqI%2F-LsknLfFQUFLicqrn_sB%2Fmicrobit-features-accelerometer.png?alt=media\&token=b6420664-0d35-4f8d-865c-12ced9a69818)

## Compass

The compass allows you to detect the direction which are in.

*An example of this would be tell you the direction of North so that know which way to travel to get to Sandton*

![micro:bit compass](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lskld_eex-nZmn54nqI%2F-LsknAYpAyhz0-YFITJj%2Fmicrobit-features-compass.png?alt=media\&token=a10b7c23-2d3c-4d91-8d36-9be64bdf723a)

## Radio

The radio feature allows you to communicate wirelessly between micro:bits. Use the radio to send messages to other micro:bits, build multiplayer games, and much more!

*An example of this would be a phone that can connect to the internet. This uses a wireless sensor.*&#x20;

*So with the mirco:bit we can  use this to send messages to another micro:bit*

![micro:bit radio](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lskld_eex-nZmn54nqI%2F-LsknAYrzw4SmmYgsJrG%2Fmicrobit-features-radio.png?alt=media\&token=aab68dfe-88d1-446c-89c0-4973a6ce5273)

## Bluetooth

Bluetooth allows the micro:bit to control phones and tablets over Bluetooth. You can also control your micro:bit from other apps using bluetooth

*An example of this would be to use your micro:bit button to take a photo with your phone camera*

![micro:bit bluetooth](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lskld_eex-nZmn54nqI%2F-LsknLfJDfMx1uq1awAG%2Fmicrobit-features-bluetooth.png?alt=media\&token=e7e7860c-ef74-490b-a8e2-13dd838ee42d)

## USB

The USB interface allows you to connect the micro:bit to your computer via a micro-USB cable, which will power the device and allow you to download programs onto the micro:bit.

## Battery Adaptor

The battery adaptor allows you to plug in your battery pack to your micro:bit so that you can use it when it is disconnected from your computer.&#x20;

## Credits

The following pages are a tutorial for the [micro:bit](https://microbit.org/). We are not affiliated with or connected with the Foundation in any way. Some images and logos you will see on these pages are taken from the micro:bit website which are provided under a Creative Commons licence.

Content taken from the below websites:

* <https://microbit.org/guide/features/>


# Safety first!

This lesson will guide you on the do's and dont's of handling your micro:bit

### The DO's

* Please handle your micro:bit by its edges.

**The DONT's**

* Do not place any metal objects across the micro:bit battery socket
* Do not place any metal objects on the circuits printed. It may damage the device and cause harm&#x20;
* Do not leave your  micro:bit plugged into any device when not being used.
* Do not use your micro:bit in water or with wet hands
* Please do not leave your micro:bit within reach of babies.
* Do not keep your micro:bit in a place where it is very hot or very cold
* Do not use portable chargers to power up your micro:bit like cellphone chargers
* Do not remove the battery attachment by pulling the wire. You must pinch the connector with your fingers to remove
* Do not use rechargeable batteries with your micro:bit


# Plug in your micro:bit

This lesson will show you how to connect your micro:bit to your computer and view the demo program

## Remove your micro:bit from the box

## Plug the micro:bit into your computer

Take the USB cable and plug the small end into in the micro:bit. Then take the bigger end and plug it into your computer

## micro:bit Hello demo

The micro:bit LED's will first flash, and then it will say "hello"

## micro:bit button demo&#x20;

Your micro:bit will then show the letter "A" and an arrow pointing to the A button. Press the A button on the micro:bit.

Your micro:bit will then show the letter "B" and an arrow pointing to the B button. Press the B button on the micro:bit.

## micro:bit shake demo&#x20;

Your micro:bit will then display the words "shake". Shake your micro:bit a few times, as you shake the micro:bit, the LED's will light up

## micro:bit chase the dot demo&#x20;

Your micro:bit will then display the words "chase the dot". It will show you a blinking light and a light that is always on. You now need to move your micro:bit so that the solid light moves towards the blinking light.

Once to chase the dot, the micro:bit will then flash with a heart. Now you are ready to start coding

## Demo Video

{% embed url="<https://youtu.be/aD8fSlBgjY4>" %}


# My name is?

This lesson will give the kids and introduction the MakeCode editor as well as allow them to code and run their first program

## Open the MakeCode Editor

Ask the kids to on the ***micro:bit*** icon on your toolbar click on the link on the slideshow.

<https://makecode.microbit.org/>

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-LskcML6iX1eVw_Fa0KA%2F-LskclQv7ySUOW6M71CY%2FMakeCode1.png?alt=media\&token=1464773f-ef91-4b77-b6ed-527e2515a128)

Click on "***New Project***". The MakeCode editor will appear

## Quick tour of the MakeCode Editor

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-LsmpE_4BjLduB1EuctQ%2F-LsmuvfdpeKfVIMjtx2R%2Fmakecode-editor1.png?alt=media\&token=c5b2a5d0-f018-473d-b77c-2645c734692f)

{% hint style="info" %}
Explain to the kids about the MakeCode editor.
{% endhint %}

The MakeCode editor consists of the following components

* **Simulator** - on the left side of the screen, you will see a virtual micro:bit that will show you what your program will look like running on a micro:bit. You can also press the buttons to see what your program will do
* **Toolbox** - in the middle of the screen, there are a number of different categories, each containing a number of blocks that can be dragged into the programming workspace on the right. We will use this during the course. A block is like an instruction to tell the code or micro:bit what to do.
* **Workspace** - on the right side of the screen, the grey area, is the Programming Workspace where you will create your program. Programs are constructed by snapping blocks from the Toolbox.
* **Download** - You will use this button to download your code when you are ready to install it to your micro:bit
* **Program Name** - This is the name that you will give your program.

{% hint style="info" %}
Move the show number block to the Workspace. Show them how to drag and snap a block in place.&#x20;

Move the Clear Screen block also and snap it to the forever loop.

Move the Clear Screen block out and show that that it is grey, this means that is it not part of the program

Delete the Clear Screen block tel them this is how you delete the block.
{% endhint %}

## Write you first Program

{% hint style="info" %}
Now lets write our first program
{% endhint %}

Click on the **Basic** (blue) category in the Toolbox

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lsmvc6vqg_qiSNQLp_b%2F-Lsmym5b6kRFVTFqfrGT%2Fmakecode-name1.png?alt=media\&token=ee2c0ce7-ea77-4f2e-9c99-c57bc11f1c3d)

Drag the "**show string**" block to the Workspace. You will see that the block is grey which means that it is not in use.

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lsmvc6vqg_qiSNQLp_b%2F-Lsmym5ay9JvN-9kClg6%2Fmakecode-name2.png?alt=media\&token=60830cd4-3fd4-41c5-8659-1b51451a64c6)

Try to delete the "**show string**" block by dragging it back to the toolbar. As you drag it to the toolbar you will notice a bin icon will appear. Drag the block to the toolbar to delete it.

Now drag the "**show string"** block back to the workspace.

Drag the "show string" block to the "**forever**" block. Once it is dragged it will snap into the **"forever"** block. You will also notice on the Simulator (left hand side), the virtual micro:bit will show a **scrolling hello**&#x20;

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lsmvc6vqg_qiSNQLp_b%2F-Lsmym5_AyVMeeaKFFrf%2Fmakecode-name3.png?alt=media\&token=900660ff-78f6-461a-bd84-fcae813ad015)

Now click on the "**show string**" block when it shows "**hello**" and type in your name.

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lsmvc6vqg_qiSNQLp_b%2F-Lsmym5Z9H6jAh5FqTuu%2Fmakecode-name4.png?alt=media\&token=77fd1d8f-6d72-467a-aabb-076686cf355f)

Again you will see the virtual micro:bit show your name.

Type "**name**" in name field

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lsmvc6vqg_qiSNQLp_b%2F-Lsmym5cY-BF21SyOVcR%2Fmakecode-name.png?alt=media\&token=ab3f176a-5068-4a88-a043-5027bae81b3c)

## Upload your code to your micro:bit

Click the pair device option from the menu and ask the kids to Pair their device.

Then press the **Download** button

You will now see the light flashing on the micro:bit. This means the code is uploading.

Once the code has completed, you will see your name scroll on your mirco:bit.


# Learning Outcomes

In this lesson you would have learnt the following:

1. You now know what a micro:bit is. You know what it looks like and the different components it has on it like the buttons and lights.
2. You know how to plug your micro:bit into your computer using the USB cable
3. You know how to open the MakeCode editor on your computer.
4. You know how to drag blocks to the workspace.
5. You know how to delete blocks.
6. You know how to view the virtual micro:bit in the simulator section of MakeCode.
7. You know how to name your program
8. You know how to pair the micro:bit to your computer and upload your code.


# Lesson 2

This lesson will teach the kids to get more familiar with the MakeCode editor.

### What you will learn in this lesson?

By the end of this lesson you will learn the following:

* Move coding blocks around in the MakeCode editor
* Get more familiar with downloading your code to your computer and uploading it to your micro:bit
* Understand a program logic and how it flows
* Understand the **pause** coding block


# Whats your name again?

This lesson will teach the kids how to connect more coding blocks on MakeCode. It will teach them how to use the LED's on the micro:bit to show icons and symbols

{% hint style="success" %}

## Teachers Notes

In the first part of the lesson the kids will need to display their name again using the micro:bit LED's but this time they will need to create each letter of their name using **show led** coding block. You may need to assist them when they plot the letters on the LED coding block
{% endhint %}

## Open the MakeCode application

Click on the ***micro:bit*** icon on your toolbar or go to <https://makecode.microbit.org/> on your browser.

## Create your new program

Click on "***New Project***"

Click on the **Basic** (blue) category in the Toolbox

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lsmvc6vqg_qiSNQLp_b%2F-Lsmym5b6kRFVTFqfrGT%2Fmakecode-name1.png?alt=media\&token=ee2c0ce7-ea77-4f2e-9c99-c57bc11f1c3d)

Drag the "***show leds***" block to the Workspace and drop it on the ***start*** code block.

In order to make the light come on you will need to select the block that you want to come on from the LED screen. If it is white, then the LED will come on.

Click on the LED's to write the first letter of your name.&#x20;

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lss5_Ai-CGTPLmWld1U%2F-Lss5dnj50aCwkrQRX6s%2Fl2-2.png?alt=media\&token=add72bb8-e303-4a60-bab2-be80082060fc)

*Notice the LED screen on the simulator on the left hand side.*

Drag another **show led** block and place it below the first block. Click the LED's to display the second letter of your name.

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lss5_Ai-CGTPLmWld1U%2F-Lss5dnoDoP-vK-Z9ySk%2Fl2-3.png?alt=media\&token=4fabbe19-74ef-49e3-b21d-a17494c96117)

Continue to do the same by adding another **show led** block to complete your name.

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lss5_Ai-CGTPLmWld1U%2F-Lss5dnp_VDTwjAX4P6f%2Fl2-4.png?alt=media\&token=b9fc3039-16ad-44cf-b48c-c295732a1348)

## Program flow

{% hint style="info" %}
You will notice that the letters are displayed from top to bottom. This is how a program works. It will execute on code block at a time until it gets to the end.
{% endhint %}

## Pair and download your code

Once you have added all the **show led** blocks and you have written your name, type in **name2** in the program name field .

Pair your device and upload your code to your micro:bit as you did in lesson one. You will then see your name appear on the micro:bit


# How fast is your heart beat?

This lesson we will expand on the LED matrix by creating heart symbol. We will also explore the pause coding block as well as switching the LED's off using the clear screen block

{% hint style="success" %}

## Teachers Notes

You will need to explain to the kids how something would blink. This is normally done by switch a light on and off continuously. Give them an example of switching the lights off and on at home.&#x20;

You will also need to explain that the **show icon** block does as well as the **clear screen** block.

You may also need to explain to the kids how multiple block are executed one at a time, from top to bottom.

The **show icon** block is same like the show led block, when you select the drop down you can show the kids the different types of icons.

The **clear screen** simply puts all the LED's off
{% endhint %}

Click on the **home** button on the top of the MakeCode editor

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-LssAbbgeYK7xwGZEYmg%2F-LssDwpk3MHh3x8KQHx6%2Fl2-1-1.png?alt=media\&token=3e254288-b2ef-4cdc-be63-9f058c2a606b)

Click on **New Project**

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-LssAbbgeYK7xwGZEYmg%2F-LssDwpr2bFRtkDFI9ol%2Fl2-1-2.png?alt=media\&token=ad9f2c70-87c3-41b9-b25e-42c3cfdfde34)

You should have a new project created.&#x20;

Click on the **Basic** category and drag the **show icon** code block to the **forever** block

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-LssAbbgeYK7xwGZEYmg%2F-LssDwpskn1yVflkfNpm%2Fl2-1-3.png?alt=media\&token=53817473-5f6b-4791-86e8-43f0bbab71cf)

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-LssAbbgeYK7xwGZEYmg%2F-LssDwptsALafqMVwDwX%2Fl2-1-4.png?alt=media\&token=e46cffb0-f598-4ede-9a70-72d8b41cf157)

{% hint style="info" %}
Look at the simulator, you will see a heart displayed on the LED screen. You will also notice that the heart does not blink. In order for the heart to blink, all the LED's that are ON needs to be switch off, then back on again. Similar to when you switch your lights on and off at home.

To switch off all the LED's you can use the **clear screen** block.
{% endhint %}

To select the **clear screen** block, click on **Basic**, then **more**. You will then see the **clear screen** block.

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-LssAbbgeYK7xwGZEYmg%2F-LssDwpuNEisN405b_vJ%2Fl2-1-5.png?alt=media\&token=b0b10941-2b26-4726-af2d-8d5da2a12bf2)

Drag the **clear screen** block and place it under the **show icon** block.

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-LssAbbgeYK7xwGZEYmg%2F-LssDwpvYZnxOvHgALWi%2Fl2-1-6.png?alt=media\&token=ca2ba5bd-e5d6-4ec9-af05-68baef1fe7ff)

The simulator will now show the heart that is blinking.

{% hint style="info" %}
The way this works is, first the **show icon** block code will run and show the LED's on the screen. Then the **clear screen** block will run and switch all the LED's off. This will then repeat as it is in the **forever** block. So the forever block means your code will loop over and over again.
{% endhint %}

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-LssAbbgeYK7xwGZEYmg%2F-LssDwpw-gvkCilAyXD7%2Fl2-1-7.png?alt=media\&token=fd021b52-cabc-4218-8df0-c4fec624b282)

You will notice that the heart beat is very fast. We we need to slow it down. In order for us to do this, we need to pause for a moment.&#x20;

In order or us to pause in our program, we will need to use the **pause** block.

This can be found under **Basic**, and **pause**

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-LssI0TDH40APwbfmoou%2F-LssLbBmNn83Zsi-pGyK%2Fl2-1-11.png?alt=media\&token=f67a2332-0d60-4bce-b2ba-12a6985e79c5)

Drag the **pause** block and place it underneath the **clear screen** block

Click in the arrow on the pause block and you will see different time options, select 2 seconds

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-LssAbbgeYK7xwGZEYmg%2F-LssDwpxv_TF3I9hl9ng%2Fl2-1-8.png?alt=media\&token=56d5c9fe-d452-4676-b780-31650b9bc4d0)

If you look at the simulator, you will now see that the heart is blinking slower.

Pair your device and Click Download

Your device will now blink an heart.

## Optional coding

If you have some time, ask the kids to play around with the different icons


# Lesson 3

This lesson will teach the kids how to interact and program the buttons

### What you will learn in this lesson?

By the end of this lesson you will learn the following:

* You will understand how buttons work on different devices and the micro:bit
* You will learn how to code your micro:bit to run different programs when you press the different buttons on your micro:bit


# Please switch on the TV

This lesson will give the kids an understanding of how basic buttons work in everyday devices

{% hint style="info" %}

## Teachers Notes

In this lesson you will need to explain to the kids how a simple button works.&#x20;

You can use a TV remote as an example. You can explain that when you press the power button the TV comes on.&#x20;

Then when you press the volume up button, the TV gets louder and when you press the volume down the TV gets softer.

You can also explain that when you press a button on a remote certain actions happen. Each button will run different actions.&#x20;
{% endhint %}


# One, Two, Three

This lesson will teach the kids how to run different code when you press the buttons on the micro:bit

{% hint style="info" %}

## Teachers Notes

In this lesson the kids will code each button on the micro:bit.&#x20;

The program will word as follows:

* When button A is pressed, the LED's will show 1.
* When B is pressed, the LED's will show 2.
* When A+B is pressed, the LED's will show 3.

The kids will use the **show string** block to display the numbers and the **Input -> on button pressed** block to trigger button presses.

The **on button** **pressed** block can be found under the pink **Input** category. This block allows to to select 3 option from the dropdown namely A, B, A+B which corresponds to each button.

You will use 3 of these blocks. Each for one button
{% endhint %}

## Create your new program

Click on the ***micro:bit*** icon on your toolbar or go to <https://makecode.microbit.org/> on your browser.

![](https://blobscdn.gitbook.com/v0/b/gitbook-28427.appspot.com/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-LskcML6iX1eVw_Fa0KA%2F-LskclQv7ySUOW6M71CY%2FMakeCode1.png?alt=media\&token=1464773f-ef91-4b77-b6ed-527e2515a128)

Click on "***New Project***". The MakeCode editor will appear

Delete the **on start** and **forever** blocks by dragging it to the toolbar

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lt6l00Zh0PXFGrgByjM%2F-Lt6lLB0HMlgU9ta9LJK%2F3-1.png?alt=media\&token=3c155ecb-1af3-4aaf-9adf-8996c7bccc81)

## Show 1 when I press button A

{% hint style="success" %}
Kids task

You will need to program your micro:bit so that when you press button A, the number 1 is displayed
{% endhint %}

Click on the pink **Input** category in the toolbox

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lt6l00Zh0PXFGrgByjM%2F-Lt6lLB3pjvpUE0fWP6t%2F3-2.png?alt=media\&token=c6df3e46-9991-464e-a425-084c3a8fa319)

Drag the **on button press** block and move it to your workspace

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lt6l00Zh0PXFGrgByjM%2F-Lt6lLB5tQjkJNUaKjKw%2F3-3.png?alt=media\&token=33666817-893e-4cd2-889c-e4241b2c7e8f)

Your workspace should look like the image below

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lt6m7wq-qxNWGplQLmY%2F-Lt6nEMDi9bz4uXs9ubE%2F3-a.png?alt=media\&token=568c864f-26e8-49cf-94ff-1b74ffcd3c9c)

Find the **show string** block under **Basic**

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lt6m7wq-qxNWGplQLmY%2F-Lt6nEMJaZ9AXF5ZI4sL%2F3-b.png?alt=media\&token=8e10cff7-e855-4f92-8264-3c360f356a9a)

Drag the **show string** block and move it inside the **on button pressed** block&#x20;

Type in **1** in the **show string** block

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lt6l00Zh0PXFGrgByjM%2F-Lt6lLB7jDy7vsg4KQ7x%2F3-5.png?alt=media\&token=999f27fc-d1f4-4a52-a60c-8385e8acce8f)

On the simulator side, press the **A button** and you will see 1 display

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lt6l00Zh0PXFGrgByjM%2F-Lt6lLB84I2t6omtRjfH%2F3-6.png?alt=media\&token=2b4ed718-9a47-4c84-a5f3-23fc928fe1f9)

## Show 2 when I press button B

{% hint style="success" %}
Kids task

You will now need to program your micro:bit so that when you press button B, the number 2 is displayed
{% endhint %}

Drag another **on press button** block to your workspace

Click on the drop down by A and you will see 3 options displayed.&#x20;

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lt6l00Zh0PXFGrgByjM%2F-Lt6lLB9GBao3k8CPMn5%2F3-7.png?alt=media\&token=c67dd360-9eb2-468e-8248-871e1fc2506c)

Select **B** from the dropdown

What this means is that when you press button **B**, something will happen

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lt6l00Zh0PXFGrgByjM%2F-Lt6lLBAhPj4F8kyhjyU%2F3-8.png?alt=media\&token=8f451f0d-f285-434f-9e18-96bd07d5c7a3)

Drag a show string block to the **on button button B pressed** code block.

Type **2** in the **show string** code block.

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lt6l00Zh0PXFGrgByjM%2F-Lt6lLBBKd_MKVrQ9CXc%2F3-9.png?alt=media\&token=d8926a25-32ee-45a6-86fa-821139377f79)

On the simulator side, press **button B** and the LED should display 2

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lt6l00Zh0PXFGrgByjM%2F-Lt6lLBCUaslmLL2qUSE%2F3-10.png?alt=media\&token=df6d2712-0084-4428-b4bf-96e4fe8e935f)

## Show 3 when I press button A+B

{% hint style="success" %}
Kids task

Lastly you will now need to program your micro:bit so that when you press button A and button B, the number 3 is displayed
{% endhint %}

Once again, drag the **on button pressed** code block to your workspace

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lt6l00Zh0PXFGrgByjM%2F-Lt6lLBExbpGzJ--6-Nf%2F3-11.png?alt=media\&token=5e524277-e04b-4387-8250-655af30b20f2)

Select the option A+B from the drop down

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lt6l00Zh0PXFGrgByjM%2F-Lt6lLBF_MCi9Q-wGBFC%2F3-12.png?alt=media\&token=b6b5b887-14f2-4c5b-ba38-07edae22a1a3)

Drag a **show string** code block to the **on button A+B pressed** code block.&#x20;

Type 3 on in the **show string** code block

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lt6l00Zh0PXFGrgByjM%2F-Lt6lLBGa-NQRIn_1uAZ%2F3-13.png?alt=media\&token=464e9558-e578-42c8-b322-068723c43827)

In the simulator, press the **A+B Button** and the LED should display 3

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lt6l00Zh0PXFGrgByjM%2F-Lt6lLBH3pfxpgq9BM1m%2F3-14.png?alt=media\&token=4b40ebdc-3efe-4a21-a861-1d2b7c8cbfd6)

## Save, download and run your code

Save you code as **1 2 3** and press save to download.

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lt6l00Zh0PXFGrgByjM%2F-Lt6lLBIZ5pj3ps2bprU%2F3-15.png?alt=media\&token=fc540a4b-dd77-40bf-8d8c-3affe8ef108c)

Drag your code file named microbit-1-2-3.hex to the MICROBIT(D:) folder to upload your code to your micro:bit.

Test your micro:bit by pressing Button A, then Button B then both button A and button B at the same time.

##


# Keep pressing that buttons

This is a option lesson where you allow the kids to play around and code different things when the buttons are pressed.

{% hint style="info" %}

## Teachers Notes

This is an optional lesson. Allow the kids to experiment to add different strings it icons when the buttons are pressed.
{% endhint %}

## Smiley buttons

{% hint style="success" %}
Kids tasks

In this task you need to show a **happy face** when you press button A and a **sad face** when you press button B

Save you code as **Smiley Buttons**
{% endhint %}

{% embed url="<https://makecode.microbit.org/_hzuPft0JzhtA>" %}

## YES, NO buttons

{% hint style="success" %}
Kids tasks

In this task you need to display&#x20;

* **YES** when button A is pressed
* **NO** when button B is pressed
* **MAYBE** when A+B is pressed

Save you code as **YES NO Buttons**
{% endhint %}

{% embed url="<https://makecode.microbit.org/_0atX6ygax203>" %}


# Lesson 4

This lesson will teach the kids how to define variables and use them on micro:bit

### What will you learn in this lesson?

By the end of this lesson, you will learn the following

* What does a variable mean?&#x20;
* How does it work?
* How to use variables and perform actions on micro:bit?


# Variable, what is that!!

In the lesson you will explain to the kids what a variable is.

{% hint style="info" %}

## Teachers Notes

In this lesson, you will need to explain what is a variable with a simple example of keeping score in a game.&#x20;

You will need a cup and 5 pieces of paper that will fit in the cup. Number each piece of paper from 1 to 5. You will also need a ball to play a game. You can play a quick game of soccer with the kids where you or one kid will kick the ball through the goal posts (you can make this with two chairs)

**Explanation to the Kids:**

Think of the cup as a variable. At first, the cup is always empty. This means it is zero. We will call this cup (or variable) score. This variable will keep track of how many goals is scored.

*Now* *start to play your game. Kick the ball through the goals once.*&#x20;

Then add the number one piece of paper into the cup. Now explain to the kids that you have added a value of 1 to the variable.&#x20;

*Kick the ball through the goals again.*

Then remove the paper 1 and add paper 2 to the cup. Now the score is 2.&#x20;

*Repeat this 5 times until you add the paper 5 to the cup.*

Now explain to the kids that each time you scored a goal you added 1 to the variable or changed the variable value by 1. Each time you wanted to see what the score was, you check with the value of the variable was and that gave you the score.

*Repeat the concept if the kids dont get it first time.*
{% endhint %}


# Step Counter

{% hint style="info" %}

## Teachers Notes

In this lesson, kids will learn how to assign a variable to micro:bit and make code for performing step calculation while the kids walk

* Assign a variable on the micro:bit
* On walking, micro:bit recognizes a shake and add steps
* When button A or B is pressed, micro:bit will display the number of steps recorded
* When A+B is pressed, the variable will be reset to 0
  {% endhint %}

## Create your new program

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-LssAbbgeYK7xwGZEYmg%2F-LssDwpr2bFRtkDFI9ol%2Fl2-1-2.png?alt=media\&token=ad9f2c70-87c3-41b9-b25e-42c3cfdfde34)

Click on "***New Project***". The MakeCode editor will appear

Delete the **forever** blocks by dragging it to the toolbar. Click on **Variables** option from the toolbar

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lu5vvqTsvrn-m1i6D4g%2F-Lu5wDpv2qSP2BS_OVpB%2Fc-2.png?alt=media\&token=10293ab2-ac0c-4167-aa23-f899fc739ac0)

Click **Make a Variable** and give it a name **"step"**

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-LuhzP8Anm9mT6c22H3L%2F-LuhzrBhPviuNCHf52gd%2Fstep-create-variable.png?alt=media\&token=2e027002-4b77-428d-b28c-30d62fd1c150)

Click **Ok**. The variable **step** will now be created

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-LuhzztGFIEpAu1gDpSb%2F-Lui5fH8oBsiQArHEJps%2Fstep-create-variable-complete.png?alt=media\&token=d64e37aa-9b2d-4792-90fc-6fbca0f14073)

Now you will have to initialize variables on start. Drag **set variable to 0 option** to the **on start** block

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-LuhzztGFIEpAu1gDpSb%2F-Lui5j2aqrXauaeQJLVN%2Fstep-initialize-variable.png?alt=media\&token=61e64f3e-05aa-464f-92dc-c9888f5f4f3f)

Now we will have to calculate number of steps based on walking pattern. When we walk with the micro:bit it shakes. We will use the **on shake** option. Drag **on shake** option from **Input** section

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lui5mI4tsNhBHbyio8l%2F-Lui6qTgV1bz_lMq3UH3%2Fstep-on-shake-drag.png?alt=media\&token=6dde1332-105a-4d4f-8b9f-4b8cbd57779f)

Now open **Variables** section and drag **change step by 1** option to the **on shake** block

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lui7FCVYNFGsZ6_B9HO%2F-Lui7O0UX-kWxjRFp0f_%2Fstep-onshake-change.png?alt=media\&token=a408743f-7671-4378-917a-aab420e006c7)

Now micro:bit will start calculating number of steps when you walk. We will have to display the number of steps calculated when you press button **A** or **B**. Drag **on button A is pressed** block from the **Input** section.&#x20;

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lui7FCVYNFGsZ6_B9HO%2F-Lui7yeDGuDgN7JhG7xY%2Fstep-drag-abutton.png?alt=media\&token=5049e0ad-148d-4121-9450-63f5e60fbd6e)

Now we will have to display the number of steps calculated. For this drag **show string** option from **Basic** section to the block. Drag the **step** from **Variables** section to the block. Perform the same action for **button B**

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lui85QlMEgdZ7mvT99M%2F-Lui8t1R9B9Pv27gNay3%2Fstep-display-buttona.png?alt=media\&token=5eda3066-0505-4e8d-b815-de4b0dcd37b1)

We now need to be able to reset the steps counted. To perform this action drag **on button A+B pressed** option from **Input** section

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-LuiCG7Rk4_QUNyFzwWy%2F-LuiCVVv2E5MEI4pACap%2Fstep-on-ab-press.png?alt=media\&token=2eb0e7ea-cabe-49c8-8c19-f6640935e2ce)

Drag the **set steps to 0** option from **Variables** section

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-LuiCG7Rk4_QUNyFzwWy%2F-LuiEPHr1PsztzWDdlo7%2Fstep-reset.png?alt=media\&token=b657014e-aacd-4679-adb2-91951059ad07)

## Save, download and run your code

Save you code as **Step\_Counter** and press save to download.

Drag your code file named microbit-1-2-3.hex to the MICROBIT(D:) folder to upload your code to your micro:bit.

Test your micro:bit by pressing button A or B. micro:bit will display zero. Walk around for a while and then press press Button A or B once, see if micro:bit displays number of steps that you have walked. Now press A+B together and then press button B to check if the steps have been initialized again.


# 1 + 1 = 2

{% hint style="info" %}

## Teachers Notes

In this lesson, the kids will learn how to assign variable to each button and perform an addition function.&#x20;

* Assign a variable to button A
* Assign a variable to button B
* Value for each variable will be assigned based on number of taps on the particular button
* When A+B is pressed, the LED's will show the sum of values of variables A and B
* Shaking the micro:bit will reset the variables
  {% endhint %}

## Create your new program

Click on the ***micro:bit*** icon on your toolbar or go to <https://makecode.microbit.org/> on your browser.

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-LssAbbgeYK7xwGZEYmg%2F-LssDwpr2bFRtkDFI9ol%2Fl2-1-2.png?alt=media\&token=ad9f2c70-87c3-41b9-b25e-42c3cfdfde34)

Click on "***New Project***". The MakeCode editor will appear

Delete the **forever** blocks by dragging it to the toolbar. Click on **Variables** option from the toolbar

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lu5vvqTsvrn-m1i6D4g%2F-Lu5wDpv2qSP2BS_OVpB%2Fc-2.png?alt=media\&token=10293ab2-ac0c-4167-aa23-f899fc739ac0)

Click **Make a Variable** and give it a name **"A"**

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lu5vvqTsvrn-m1i6D4g%2F-Lu5wZF9QYUTcbx4qwfx%2Fc-4.png?alt=media\&token=7a2d0456-b2a2-423b-9cb2-0d3f2f5c245c)

Click **Ok**. The variable A will now be created

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lu5vvqTsvrn-m1i6D4g%2F-Lu5wol6hCBf1RujiDgZ%2Fc-5.png?alt=media\&token=76809894-ad70-4ffd-bddb-3744b7ef33a7)

Follow the same steps again to create variable "B"

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lu5vvqTsvrn-m1i6D4g%2F-Lu5x1OZcc81GAMXy9wt%2Fc-6.png?alt=media\&token=dc930763-af67-49c3-96b7-288aed002fd7)

Now you will have to initialize variables on start. Drag **set variable to 0 option** to the **on start** block. Select the dropdown and select variable A. Similarly pefrorm the same step for variable B.&#x20;

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lu5xHlQ-UH6-E-61EoW%2F-Lu5xdO7csKse_ip701e%2Fc-7.png?alt=media\&token=29410fc5-653c-45e5-aa6c-5542267fdb93)

Now we have initialized the variable. We will have to now make code for the variable to assign values based on number of taps we perform on a button. If we press button A the variable A should increase value by 1

To perform this function, drag **on button A pressed** option from **Input** toolbar. From the **Variables** toolbar, drag **change A by** option and change the value to **1**.

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lu5yyGUMvDVLBqLVPcl%2F-Lu5z7fnhZGca7Dx8hVM%2Fc-8.png?alt=media\&token=614b6829-04b7-47ee-980f-1a6eba2f444c)

Repeat the same step for button B

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lu5zAvV37sraceRZ3Aw%2F-Lu6-CiiAqZ0ii4kbGuT%2Fc-10.png?alt=media\&token=400a89fd-a04c-4120-a1d1-6187c99dd62c)

Now we must perform the addition function when button A and B are pressed together. Drag the **on button A+B pressed** option from the **Input** toolbar

Drag show string option from the Basic Toolbar

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lu5zAvV37sraceRZ3Aw%2F-Lu6-vDiwSby9EuoONiP%2Fc-11.png?alt=media\&token=c9c5aea9-6732-4f82-87e8-681f851a6fe1)

Now we will have to perform a mathematical calculation of the variables. Open the **Math** toolbar and drag **0 + 0 option** to the code editor

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lu60JAfS9RQdr4DIW2k%2F-Lu60WAk3dQzHGXypyeL%2Fc-12.png?alt=media\&token=4937e938-c247-4526-bb66-20731bc7a7f5)

Now replace the zeros with variables A and B by dragging **A** and **B** from the **Variables** toolbar

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lu60Yr7V_iOzqZ-JEnR%2F-Lu6130J3InO_OCpFrev%2Fc-13.png?alt=media\&token=16dfce11-b124-42d4-99f2-ebde21e47d21)

Now you must be able to reset the calculator after addition function is completed. We can reset the variables as we shake the micro:bit. To perform this function drag **on shake** option from **Input** toolbar. Add **set A to 0** and **set B to 0** options to on shake from **Variables** toolbar

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-Lu619eFDEiIxlU5s0kS%2F-Lu61jdlAdObe-ZzGpQ9%2Fc-14.png?alt=media\&token=05e8f958-956a-4b9a-823f-c32b69208fde)

## Save, download and run your code

Save you code as **Calculator** and press save to download.

Drag your code file named microbit-1-2-3.hex to the MICROBIT(D:) folder to upload your code to your micro:bit.

Test your micro:bit by pressing Button A once, then Button B once then both button A and button B at the same time. Your micro:bit will add 1 + 1 and display value 2


# Blinking an LED

## What will we do

Lets start by making our LED blink on and off. The way to make an LED blink is to follow this sequence of code instructions over and over again:

* Turn the LED on
* Delay for a period of time
* Turn the LED off
* Delay for a period of time

## Parts List

You will need the following parts:

* **1x** micro:bit
* **1x** Micro B USB Cable
* **1x** Breadboard
* **1x** Jumper Wire
* **1x** LED&#x20;
* **1x** Resistor

## Wiring it up

This example we use a red LED but you can use any colour LED you prefer.&#x20;

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-M6Go-lcGViu0ntSzAUD%2F-M6H940zhZQkehLWx2RA%2Fmicrobit%20-%20blinking%20led.png?alt=media\&token=a894feb1-f069-4cd5-be89-1d75976789d4)

Ensure that the LED are the right way around, with the longer positive leads (anodes) to the left.

## Block Coding

{% embed url="<https://makecode.microbit.org/_dmFPWeUw9Ye7>" %}


# Traffic Signal

## What will we do

This example uses three LEDs to make a model traffic light signal. You can use all red LEDs if you like, but its more realistic if you use red, yellow and green.

The LEDs cycle around in the sequence red, green, yellow and then back to red again

## Parts List

You will need the following parts:

* **1x** micro:bit
* **1x** Micro B USB Cable
* **1x** Breadboard
* **3x** Jumper Wire
* **1x** Red LED&#x20;
* **1x** Yellow LED&#x20;
* **1x** Green LED&#x20;
* **3x** Resistors

## Wiring it up

To add the extra LEDs and resistors, wire them up as shown in the breadboard layout below.

![](https://1854716099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LskXJjPT2bXMIodrtZq%2F-M6GkzsmzDxpA2Hx02Ww%2F-M6Glxrp7Cez1WLETXxy%2Fmicrobit%20-%20traffic%20lights.png?alt=media\&token=6ce3c1f2-ca4b-433c-9ad1-f38990537f2f)

Ensure that the LEDs are the right way around, with the longer positive leads (anodes) to the left.

## Block Coding

{% embed url="<https://makecode.microbit.org/_CUKipEHhmTP5>" %}


