How to Use Arduino and Bluetooth Module to Control LED Project(DETAILED)
by avaqsemi in Circuits > Arduino
297 Views, 0 Favorites, 0 Comments
How to Use Arduino and Bluetooth Module to Control LED Project(DETAILED)
In this article, I will demonstrate how to build an IoT project using Arduino (Arduino UNO) and Bluetooth module HC-05 to control LED lights. In this project, we will use an Android smartphone to send a bluetooth signal to a bluetooth module.
Supplies
- - Arduino UNO Motherboard
- - USB cable for connector Arduino UNO
- - Bluetooth module HC-05
- - Jumper wire male to female
- - LED
- - AC 220v/120v home appliance or 9v Hi-Walt battery
How Arduino Bluetooth Module Works
In this project, three main components are used; Android smartphone, Bluetooth transceiver and Arduino.
The Android application can send serial data to the Bluetooth module HC-05 by pressing the ON button.The Bluetooth module HC-05 is used for serial communication. It receives data from the application and sends it to the RX pin of the Arduino via the TX pin of the Bluetooth module. the code uploaded in the Arduino checks the received data. If the received data is 1, the LED turns ON and if the received data is 0, the LED turns OFF.
Digital Circuit Diagram
Bluetooth Module HC-05 Arduino UNO TX
--------------------------------> RX (Pin 0) RX
--------------------------------> TX (Pin 1) VCC
--------------------------------> 5v GND
--------------------------------> GND LED Pin Arduino UNO Pin 1
--------------------------------> GND Pin 2
--------------------------------> Pin 13
Launch Arduino Software
Write a program for Arduino UNO motherboard, if the received data is equal to 1, the LED is on, if the data is equal to 0, the LED is off. The reference code is as follows:
char data = 0; //Variable for storing received data
void setup()
{
Serial.begin(9600); //Sets the baud for serial data transmission
pinMode(13, OUTPUT); //Sets digital pin 13 as output pin
}
void loop()
{
if(Serial.available() > 0) // Send data only when you receive data:
{
data = Serial.read(); //Read the incoming data and store it into variable data
Serial.print(data); //Print Value inside data in Serial monitor
if(data == '1') // Checks whether value of data is equal to 1
digitalWrite(13, HIGH); //If value is 1 then LED turns ON
else if(data == '0') // Checks whether value of data is equal to 0
digitalWrite(13, LOW); //If value is 0 then LED turns OFF
}
}
Save the Above Program and Compile It
Connect the Arduino device to the laptop (or monitor) via the Arduino UNO USB cable. Remove all other connections from the Arduino UNO device (such as the Bluetooth module and LED) when uploading the program to Arduino UNO.
After compiling the code, upload it to the Arduino UNO device. Before uploading the code to Arduino, the UNO device ensures that the Arduino serial port is selected, otherwise an error message "Serial port not selected" will be generated.
To select the serial port, please open "Device Manager" -> "Ports" -> "Arduino Uno" and then upload the code.
Bluetooth Module to Connect Android Applications
1. Open the Bluetooth connector application, and then turn on Bluetooth for your device.
2. Search the Bluetooth device for pairing.
3. To pair with Bluetooth HC-05 module, please enter :0000 or 1234.
4. Select the paired device HC-05 to connect to the Android application.
Control the LED Device
When you click the "ON" button, it sends data 1 to the Bluetooth module, which is transferred from the Bluetooth module to the Arduino device, and turns on the LED. This data is transferred from the Bluetooth module to the Arduino and turns off the LED.