Control the Arduino LED using Bluetooth 

Have you ever wondered how your wireless sound system works?


Well, it supports Bluetooth connection which allows you to control it remotely from your smartphone. You can send commands to adjust volume, control the RGB light, and more.


In this tutorial we will use the HC-05 Bluetooth module to send data to the Arduino via your smartphone. This data will be used to control the Arduino's built-in LED on and off. 


It is a very interesting project Let's see!


Overview


Bluetooth is a wireless technology that allows two devices to communicate with each other. It can be used to connect a variety of devices, including phones, computers, and headphones.


It is typically used to connect devices that are close together, such as when you're using wireless headphones or connecting your phone to a speaker. It may also be used to transfer files between your computer and your phone.


Getting the items


For this project you will need the following components you can buy them from our store. 

Sale Off
Voltaat Arduino Uno R3 (Voltaat Version)
45 QAR
Sale Off
Voltaat HC-05 Bluetooth Module
33 QAR
Sale Off
Voltaat Jumper Wires - Male to Female (40 Pack)
10 QAR

Wiring it up


To set up the Bluetooth module in the correct way, follow the instructions below. The image demonstrates how to connect the wires between the Bluetooth module and the Arduino. Once the Bluetooth module and the Arduino are connected to each other, connect the Arduino to your computer using the USB cable.


Connections from the Bluetooth to the Arduino:

• Bluetooth VCC pin → Arduino 5V pin

• Bluetooth GND pin → Arduino GND pin

• Bluetooth TX pin → Arduino pin 0 (RX)

• Bluetooth RX pin → Arduino pin 1 (TX)


Coding


The function of this sketch is to control the Arduino's built-in LED via your smartphone using the Bluetooth connection. When you send the character 'o', whether capital or small, the LED will turn on. But if you send the character ‘f’, whether it is capital or small, the LED will turn off.


The Arduino has a small built-in LED that is connected to pin 13. When the pin is high, the LED is on. When the pin is low, the LED is off. This LED may be used as an indicator in many projects without the need for an external one. You may also use it to test your board.


In order to send the character from your smartphone to the Arduino via the Bluetooth connection, you'll need to download an app. We'll go through it in more detail after the code section.


The code is basic and clear. You do not need to download any libraries.


Let's put it to the test together!


/*
Voltaat learn (http://learn.voltaat.com)
Link for full tutorial: https://bit.ly/3FCBSyT

Tutorial: Control the Arduino LED using Bluetooth

The function of this sketch is to control the Arduino's built-in LED
via your smartphone using the Bluetooth connection

Connections from the Bluetooth to the Arduino:
• Bluetooth VCC pin → Arduino 5V pin
• Bluetooth GND pin → Arduino GND pin
• Bluetooth TX pin → Arduino pin 0 (RX)
• Bluetooth RX pin → Arduino pin 1 (TX)

*/


//Define inputData variable
char inputData;

//Commands inside void setup run once
void setup(){
//Start the serial monitor at 9600 baud rate (9600 bits per second)
Serial.begin(9600);
//LED_BUILTIN is defined as an output
pinMode(LED_BUILTIN,OUTPUT);

}

//Commands inside void loop run forever
void loop(){
///If there is data available
while(Serial.available()>0){
//Read data that was sent from your phone ans assign it to inputData variable
Serial.println(inputData);
//If the received character 'o' is capital or small
if(inputData =='o'|| inputData =='O'){
//Turn on the Arduino LED
digitalWrite(LED_BUILTIN,HIGH);
//Print to serial monitor
Serial.println("Received, Arduino LED is tuned ON");
}
//If the received character 'f' is capital or small
elseif(inputData =='f'|| inputData =='F'){
//Turn off the Arduino LED
digitalWrite(LED_BUILTIN,LOW);
//Print to serial monitor
Serial.println("Received, Arduino LED is tuned OFF");
}
}
}

Testing it out




Now you must have correctly wired the Bluetooth to the Arduino as we explained in the wiring section, as well as uploaded the code to your Arduino board.


If an error appears while uploading the code to your Arduino board, try to upload the code before wiring.


For the next step, you need to download an app that allows you to send data via Bluetooth to your Arduino through a terminal.

The app is available to download from Google Play store for free. You can download it from here!


Unfortunately, the HC-05 doesn't work with the iPhone. For the iPhone, you need to use the BLE 4.0 Bluetooth module. It works exactly the same.


After installing the app on your smartphone, simply open it. The app will ask you to provide it with access to your phone's Bluetooth, which you must do.


The app will ask you to choose the Bluetooth name, which will be HC-05 by default. If it asks you to enter a password, try 1234 or 0000 as the password.


The connection to the HC-05 Bluetooth module will take a while.


Now look at the HC-05's built-in LED. If it is blinking fast, it means there is no connection, but if it is blinking every 5 seconds, it means the Bluetooth is connected successfully to your phone.



The app is very simple and has a user-friendly interface. It may be used in many applications. For this tutorial, we will just use the

terminal indicated by the arrow in the next image.



After opening the terminal, it will allow you to send commands to your Arduino over the Bluetooth connection. It is as simple as chatting with your friend. Let’s chat with your Arduino! 


As you see in the previous image, when you send the character ‘o’ to your Arduino, the LED is turned on, but if you send the character 'f', the LED is turned off.

You can develop this code to have more functionality, like controlling an RGB strip or even a robot!


You may now access the serial monitor on your Arduino IDE by clicking on the magnifying glass icon at the top right corner.





The serial monitor will also print the status of the LED according to the data it receives. 

Resources 


Arduino Code

Fritzing Wiring file

Related Tutorials


In this tutorial, we will use the Arduino to control the servo motor shaft to sweep back and forth across 180 degrees. Let's have a look at it.


In this tutorial, we will use the Arduino to control a relay on and off every three seconds. You can use the same code to control a fan to be turned on and off automatically every 10 minutes to save power!


LCDs are used in a range of everyday applications, including the automobile radio and the house air conditioning remote. They display data and let you control it through menus.