> For the complete documentation index, see [llms.txt](https://docs.kidscode.co.za/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.kidscode.co.za/arduino-lessons/bluetooth-led.md).

# 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.md) 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>

![](/files/-M9FDn-c9VcGtR9NM1ZH)

## 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>

![](/files/-M9FEIyxew4kOY2eX9oh)

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

![](/files/-M9FErs9j2o9vJaJ2Bch)

## 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

![](/files/-M9FHQm45F7axTJ97XMe)

* 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;
