DIY Bluetooth Controlled Lights: Home Automation Using Arduino Uno

by piyushsuteri in Circuits > Arduino

5032 Views, 12 Favorites, 0 Comments

DIY Bluetooth Controlled Lights: Home Automation Using Arduino Uno

IMG_2691.JPG
Home Autonomation using arduino uno


In this tutorial, we will be exploring how to make a DIY Bluetooth-controlled light using an Arduino Uno and HC-05 Bluetooth module. This project is an excellent introduction to IoT and a great way to learn about electronics and programming. With just a few components and some basic coding skills, you can build your Bluetooth-controlled light that can be operated from your smartphone or tablet. Firstly let me give a brief introduction to the project.


Why to use Bluetooth?

Bluetooth is a wireless communication technology that allows electronic devices to connect and exchange data over short distances. It operates on the 2.4 GHz frequency band and uses radio waves to transmit and receive data between devices. Also, there is one more famous wireless technology which is Wi-Fi. We can also use wi-fi for home autonomation projects. Commonly available modules for wifi are NodeMcu ESP8266 and ESP32 but they are not too easy to use and code, on the other hand, the Bluetooth module is very easy to use and even faster to communicate over short distances. That is why we are going to use a very common Bluetooth Module HC-05 for this project.


Bluetooth controlled Smart lights -

A Bluetooth-controlled smart light using Arduino Uno is an innovative project that combines the power of Bluetooth technology and the flexibility of Arduino microcontrollers to create a smart lighting system that can be controlled wirelessly using a smartphone or tablet. With this project, you can turn on/off your lights with just a few taps on your mobile device. For this project, you will need the following components.

Supplies

IMG_20230316_134437.jpg
IMG_20230316_133108.jpg
IMG_20230316_133740.jpg
IMG_20230316_133159.jpg
IMG_20230316_133542.jpg
IMG_20230316_134137.jpg
IMG_20230316_134305.jpg
IMG_20230316_134335.jpg
IMG_20230316_135117.jpg

Electronic and other materials

2) Arduino Uno (main microcontroller board for this project)

3) Bluetooth module HC-05 (for transferring data using Bluetooth on your phone to Arduino)

4) Relay module (for switching the LED on and off using Arduino)

5) Some LEDs (to indicate whether lights are on or off)

6) Wires and Jumper wires (to connect everything)

7) Cable ties, Double-sided tape/Glue gun, and Cardboard (to make everything look clean and good)

8) Any electrical device you want to control


Softwares

1) Bluetooth control app(click here to download) (app for Android to send commands to Arduino Uno, it contains various buttons, and if it is pressed smart Light turns on)

2) Arduino IDE (to upload a program in Arduino, it can be either on a laptop or your phone)

Download Code and Controll App

Bluetooth control app- There are many apps available in the Play Store to send data to the Bluetooth module. But I am going to use one of many such apps, named E&E: Home Autonomation app. To download this app click here.

Code- Click here to download the code to be uploaded in Arduino. The code is also attached in this step.

Make the Circuit

Screenshot 2023-03-16 143648.png
IMG_20230316_143931.jpg
IMG_20230316_150900.jpg

Circuit connections are shown in the images above.

1) Start by connecting the LED's anode to Arduino's 13th pin and cathode to Arduino's ground.

2) Connect the Bluetooth module as shown in the image.

3) Connect the relay module's signal pin to pin 12 of Arduino, Vcc to +5v of Arduino, and ground to Arduino's ground

4) Connect External device to relay modules connection terminal. According to my code, your device's one of the two wires (of the power supply) must be connected to no (normally open) terminal of the Relay module, and the other wire from the power supply (extension board) can be connected to the common terminal of your relay. It is as simple as connecting any device to a switch, relay is also a switch but an electrically controllable switch. I would recommend you make these circuit connections only after disconnecting your appliance from the power source completely. You can connect any device to the relay module to wirelessly turn on or off.

5) Make everything clean by using cable ties to arrange wires and double-sided tape to paste all electronics like Arduino uno, Bluetooth module, and relay module on cardboard.

6) Give a complete finish to your project, paint the cardboard, and enclose your circuit in a box.

7) You are ready to go but recheck your circuit connections before powering all things up.


I have used light as my appliance to control wirelessly from my phone, you can use any appliance.

Code It

Download the file attached to this step or copy the code below:


// Bluetooth controlled lights using arudino uno and hc-05 bluetooth module
// This code was originally written for instructables: https://www.instructables.com/member/piyushsuteri/
// Youtube video available at: https://www.youtube.com/@piyushsuteri and https://youtube.com/shorts/8NufHkCCvnI?feature=share
// Author: Piyush Suteri
// 13:14, 16 March 2023
// bluetooth app link: https://play.google.com/store/apps/details?id=com.himanshu.ArduinoAutomation&pli=1
// disconnect tx and rx pins of bluetooth module before uploading this code


#define led_pin 13    // pin to which anode of indication led is connected
#define relay_pin 12  // pin to which signal pin of relay module is connected
char val;             // integer variable which stores data recieved from mobile app via bluetooth

void setup() {                 // put your setup code here, to run once:
  pinMode(led_pin, OUTPUT);    // define led_pin as output
  pinMode(relay_pin, OUTPUT);  // define relay_pin as output
  Serial.begin(9600);          // initalize serial communication
}

void loop() {                // put your main code here, to run repeatedly:
  if (Serial.available()) {  // check if data is recieved from bluetooth module
    val = Serial.read();     // store data recieved from bluetooth in val
    Serial.println(val);     // print value in Serial monitor

    if (val == 'A') {                 // check if data is 1
      digitalWrite(led_pin, HIGH);    // indicate that lights will be on using indicator led
      digitalWrite(relay_pin, HIGH);  // turn on relay
    }

    else if (val == 'a') {           // othervise data recieved is not 0 so turn off relay
      digitalWrite(led_pin, LOW);    // indicate that lights will be off using indicator led
      digitalWrite(relay_pin, LOW);  // turn off relay
    }
  }
}


Above is the code for this project, it is well commented to explain how it works, so we are not going to talk about how will it work. It is time to upload the code in Arduino Uno. Go to Arduino ide and paste this code into a new sketch, save it, and go! Upload this code to the Arduino Uno board. Remember to choose the right com port and board.

Important- In order to upload code you have to disconnect rxd and txd pins of bluetooth module. Arduino is programmed using its rx and tx pins connected to serial convertor ic built in in arduino uno board, so in order to upload code these need to not to be busy.

Working

Home Autonomation using arduino uno

Now once code is uploaded, connect the serial pins of the Bluetooth module to the serial pins of Arduino Uno. Now you will see two LEDs blinking fast in the HC-05 Bluetooth module this is because the Bluetooth module is not connected to your phone via Bluetooth. Go to Bluetooth settings in your phone and search for devices. You will get an hc-05 device, pair it, and then you will be asked for a passcode, you can enter either 0000 or 1234 there and it should pair. Go to the Android app downloaded before and go to the on/off section. Here you will get many buttons, if you have followed this instructable only button 1 will work for controlling your device (light). This is because in code we have only used 'A' and 'a', this is the character sent by phone when you press switch 1. You can edit these character values in code according to the data sent by your Bluetooth control app, The Next step is to click on the connect button find your device and connect to it. After you have paired the Bluetooth module, you will see two LED blink rates slowed down in the Bluetooth module. In the same manner, you can add many devices to control, increasing the number of relays and you will need to edit code only. Any data which is received is printed on a serial monitor. Our smart light is ready to work now. I have made videos and taken photos of my light, they are attached to the steps, and you can see how this works.


Thank you very much for reading my first instructable.

Author: Piyush Suteri