Internet of Things (IoT)
Architecture & Domains
IoT Platforms
IoT + Arduino
MCQ
Arduino and Bluetooth Module to control LED
IoT Project using Arduino and Bluetooth Module to control LED through Android App
Let's build an IoT project using Arduino (Arduino UNO) and Bluetooth Module HC-05 to control a LED light. In this project, we will use an Android smartphone to send Bluetooth signal to the Bluetooth module.
Hardware Requirements
- Arduino UNO board
- USB cable for connecter Arduino UNO
- Bluetooth Module HC-05
- Jumper wires male to female
- LED
- AC 220v/120v home appliances or 9v Hi-Walt Battery
Software requirements
- Arduino software
- Android Studio
The Working principle of Arduino-Bluetooth Module
In this project, there are three main components used; an Android Smartphone, Bluetooth transceiver, and an Arduino.
The Android app is built to send serial data to the Bluetooth Module HC-05 by pressing ON button. As Bluetooth Module HC-05 works on serial communication. It receives the data from the app and sends it through TX pin of Bluetooth module to RX pin of Arduino. The uploaded code inside Arduino checks the data received. If the receive 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
For doing the programming for Arduino board, we need to download Arduino software. This can be done from Arduino official site https://www.arduino.cc/
Download the Arduino software according to your OS compatibility (Windows Installer).
Click Download
After successful download, run the setup and follow the instructions.
When it asks to install the driver software, click to install
After installation, open the software, and if it generates a security alert then allow it.
Write a program for Arduino UNO board, if received data is equal to 1, LED turns on and if data is equal to 0, LED turns OFF.
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 your program and compile it.
Connect your Arduino device to your Laptop (or Monitor) via Arduino UNO USB cable. Remove all the other connections with Arduino UNO device such as Bluetooth Module and LED while uploading the program in Arduino UNO.
After compiling the code, upload it in Arduino UNO device. Before uploading the code in Arduino, UNO device makes sure that your Arduino serial port is selected otherwise, it generates an error message "Serial port not selected".
To select your serial port, open Device Manager > Ports >Arduino Uno, and then upload your code.
Download the Android app's .apk file and install it on your Android smartphone. Click Here to Download
Step to connect with Android app with Bluetooth Module
1. Open Bluetooth connecter app and allow turning on Bluetooth of the device.
2. Search for Bluetooth device for making the pair.
3. To pair with Bluetooth HC-05 module, enter a pin 0000 or 1234.
4. Select pair device HC-05 to connect with Android app.
5. Control LED device.
While clicking "ON" button it sends data 1 to Bluetooth module and this data is transmitted from the Bluetooth module to Arduino device and it turns ON the LED. When clicking "OFF", Android app sends data 0 to Bluetooth module, and this data is transmitted from the Bluetooth module to Arduino and it turns OFF the LED.