Dark Mode
Image

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

  1. Arduino UNO board
  2. USB cable for connecter Arduino UNO
  3. Bluetooth Module HC-05
  4. Jumper wires male to female
  5. LED
  6. AC 220v/120v home appliances or 9v Hi-Walt Battery

Software requirements

  1. Arduino software
  2. 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.

IoT project using Arduino and Bluetooth Module to control LED through Android App

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

IoT project using Arduino and Bluetooth Module to control LED through Android App

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/

IoT project using Arduino and Bluetooth Module to control LED through Android App

Download the Arduino software according to your OS compatibility (Windows Installer).

IoT project using Arduino and Bluetooth Module to control LED through Android App

Click Download

IoT project using Arduino and Bluetooth Module to control LED through Android App

After successful download, run the setup and follow the instructions.

IoT project using Arduino and Bluetooth Module to control LED through Android App
IoT project using Arduino and Bluetooth Module to control LED through Android App
IoT project using Arduino and Bluetooth Module to control LED through Android App
IoT project using Arduino and Bluetooth Module to control LED through Android App

When it asks to install the driver software, click to install

IoT project using Arduino and Bluetooth Module to control LED through Android App
IoT project using Arduino and Bluetooth Module to control LED through Android App

After installation, open the software, and if it generates a security alert then allow it.

IoT project using Arduino and Bluetooth Module to control LED through Android App

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.

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 your program and compile it.

IoT project using Arduino and Bluetooth Module to control LED through Android App

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.

IoT project using Arduino and Bluetooth Module to control LED through Android App
IoT project using Arduino and Bluetooth Module to control LED through Android App

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.

IoT project using Arduino and Bluetooth Module to control LED through Android App

2. Search for Bluetooth device for making the pair.

3. To pair with Bluetooth HC-05 module, enter a pin 0000 or 1234.

IoT project using Arduino and Bluetooth Module to control LED through Android App

4. Select pair device HC-05 to connect with Android app.

IoT project using Arduino and Bluetooth Module to control LED through Android App

5. Control LED device.

IoT project using Arduino and Bluetooth Module to control LED through Android App

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.

IoT project using Arduino and Bluetooth Module to control LED through Android App
IoT project using Arduino and Bluetooth Module to control LED through Android App

Comment / Reply From