Controlling LEDs with Arduino Uno and Bluetooth through your phone

Controlling LEDs with Arduino Uno and Bluetooth through your smartphone



Have you ever wanted to control lights with your smartphone? You can control a lighting system with just an Arduino board, a Bluetooth module, and some LEDs! In this blog post, I'll show you how to turn on and off some LEDs using your smartphone.

What are you waiting for?... Let's go!!


What you'll need
  • Arduino Uno Board
  • HC-05  Bluetooth Module
  • LEDs (x3 and preferably different coloured)
  • Resistors (220 Ohm x3)
  • Breadboard & Jumper wires( 4 male-male and 4 male-female)
  • A smartphone
  • USB cable for the Arduino board

 What you'll need to do:


 Step 1: Building a circuit

 In this step, we'll need an Arduino Uno board, 3 LEDs, 3 Resistors, a USB cable, and a Bluetooth module.

 First, take the breadboard, the LEDs and the Resistors.
 
Place the 3 LEDs in any horizontal row on the breadboard. Take the ends of the resistors and place them in front of the short leg of the LEDs, respectively. Insert the other ends of the resistors in the negative row of the breadboard.


















After that, take 4 jumper wires(male-male) and the Arduino board.
 
Insert the ends of 3 jumper wires in front of the long leg of the LEDs, respectively and the other ends into digital pins( 5,6 and 7). Then, insert the end of the last jumper wire in the horizontal row( negative row of the breadboard) and the other end in the GND of the Arduino board.


Then, take the Bluetooth module and 4 jumper wires(male-female).

Connect the VCC to 5V on the Arduino, GND to GND, TXD to RX and RXD to TX using Jumper wires.

Our Circuit is Ready!

Step 2: Writing Code for the Arduino Board

Here's the ready Arduino Code given below👇  
Copy this Directly

int LED1 = 5;
int LED2 = 6;
int LED3 = 7;
void setup() {
 pinMode(LED1, OUTPUT);
 digitalWrite(LED1, LOW);
 pinMode(LED2, OUTPUT);
 digitalWrite(LED2, LOW);
 pinMode(LED3, OUTPUT);
 digitalWrite(LED3, LOW);
 Serial.begin(9600);
 
}

void loop() {
  if (Serial.available() > 0) {
    char command = Serial.read();
   
    if (command == 'A') {
      digitalWrite(LED1, HIGH);
      Serial.println("Led On");
    }
    else if (command == 'a') {
      digitalWrite(LED1, LOW);
      Serial.println("Led Off");
    }
 
    if (command == 'B') {
      digitalWrite(LED2, HIGH);
      Serial.println("Led On");
    }
    else if (command == 'b') {
      digitalWrite(LED2, LOW);
      Serial.println("Led Off");
    }

    if (command == 'C') {
      digitalWrite(LED3, HIGH);
      Serial.println("Led On");
    }
    else if (command == 'c') {
      digitalWrite(LED3, LOW);
      Serial.println("Led Off");
    }
  }
}

Step 3: Make the App necessary to control the LEDs using Bluetooth  
After writing our code, we need to make an app. For this, we'll be using the "MIT- App Inventor". MIT- App Inventor is a website used to create simple apps. Visit the website here👉 https://appinventor.mit.edu/ or simply search MIT- App Inventor.

I'm providing images for better understanding



   This is the homepage. Click on Create Apps!👆

    Create a new project



You might see this default page. This is the part where we design our screen. Later on, we'll code the necessary operations by clicking the 'Blocks' option. 


 
     Add these 3 Horizontal Arrangement blocks to the mobile screen.👆


     
      
     Change their width by clicking Fill Parent, and change their height to 10%


   
      
     Add text blocks into each of the boxes and write texts in them - LED1, LED2 and LED3               respectively. 


     
     
 
    
     Add 6 buttons👆, 2 in each one of the boxes and add text writing ON and OFF as given below. 👇
   


      Now add Bluetooth Client as shown below





  Now, let's add a List Picker so we can see our Bluetooth list(This list will not appear now since we have to code as well afterwards), as shown below.

    Change its text to 'Bluetooth List' and change its width using Parent Fill.  


    After designing our app, we need to code the necessary options. To do that, click on the         'Blocks' option in the upper-right corner.


   This is where we'll be coding and adding operations to make our app work.


   Let me explain to you how this is going to work.
   
   There are 3 LEDs and 2 ON and OFF buttons for each, and then we have our Bluetooth list. 
   We are going to add coding blocks for all of these elements so that they can perform a             certain task. The coding blocks are given below in the image

   
    
  After this, our coding and designing is done.

  Our App is Ready!!!

  Now, we have to download the app and test it.



   Click on 'Android App(.apk)' and the QR code for the App-Installation should appear. Scan this QR code on your desired smartphone, which you must've taken before. This App might not be secure according to your phone, so change its settings and let Google Play authorise our app.  



Step 4: Final Testing of the App and Seeing if it Works 

After our app has been downloaded, let's open it.


    Our App looks like this when opened.👆


    To connect our Bluetooth Module, we first have to switch our Bluetooth mode on.



After that, let's connect our circuit consisting of our Arduino Board, LEDs and the Bluetooth module to our computer using the USB Cable and upload our Arduino code to the board. 
  
The Circuit should light up, and our Bluetooth module shall turn on.
After this, let's click on the Bluetooth list, and a dropdown should appear containing                various Bluetooth devices around us. Let's connect our phone to the Bluetooth Module          named HC-05. 



     Our Screen should look like this after connecting👇

 


  After connecting successfully, we can test our circuit/project by clicking ON        or OFF for every LED.  










    



Comments

Popular posts from this blog

Creating a Home Automation Project Using Xiao board and Wi-Fi

Making a Neon LED Sign Board

Creating a Home Automation Project Using MIT App Inventor