Bluetooth controlled LED light

Arduino Bluetooth LED control

You will learn how to create a Droid-script Bluetooth control project using an arduino nano, a Bluetooth module, LED and a droid-script app. The circuit diagram and codes for this project is simple and easy to understand

This project works by correctly connecting the circuit together as shown in the circuit diagram, you will then program the arduino with the provided code. For the droid-script blue-tooth app copy or type in the droid-script code correctly in the IDE and run it. When the app is running it will tell you to turn on your blue-tooth after that you should click on connect button to connect to the arduino project, you can now click on the turn on or turn off button to control the LED. You can find the circuit diagram and the codes for this project below.

Circuit Diagram

bluetooth LED controller
hc-05-serial_bb



Materials required:

    1. Arduino Nano.
    2. HC-05 bluetooth module.
    3. An LED.
    4. 1K resistor
    5. A breadboard.
    6. connecting wires.

Software required:

    1. Arduino IDE
    2. Droidsript Mobile App

Explanation of the Circuit Diagram

The connections made in the circuit diagram is very simple. The led is connected to the pin 12 of the arduino, the TX and RX of the blue-tooth module is then connected to the RX and TX of the arduino nano board while the VCC and GND pins from the blue-tooth module is connected to the VCC and GND of the arduino board.

Note: That the TX pin from the blue-tooth module most be connected to the RX pin of the arduino and also the RX pin from the blue-tooth module most be connected to the TX pin of the arduino respectively.

HC-05 Bluetooth Module

HC-05 is a bluetooth module that is mostly used in making bluetooth controlled projects. It has 6 pinouts, the TX, RX, EN, State, VCC and GND pins.

Arduino code here


/*
www.hertzelectroz.com
Author:   Okolo Anthony
Date:      18/12/2018
Project:   Bluetooth controlled LED light
*/

String inputString="";

void setup()                    // run once, when the sketch starts
{
 Serial.begin(9600);            // set the baud rate to 9600, same should be of your Serial Monitor
 pinMode(13, OUTPUT);
}

void loop()
{
  if(Serial.available()){
  while(Serial.available())
    {
      char inChar = (char)Serial.read(); //read the input
      inputString += inChar;        //make a string of the characters coming on serial
    }
    Serial.println(inputString);
    while (Serial.available() > 0)  
    { junk = Serial.read() ; }      // clear the serial buffer
    if(inputString == "on"){         //in case of 'a' turn the LED on
      digitalWrite(13, HIGH);  
    }else if(inputString == "off"){   //incase of 'b' turn the LED off
      digitalWrite(13, LOW);
    }
    inputString = "";
  }
}

DroidScript code here

Below is the droidscript code for the bluetooth app, can copy or typing in this code inside your droidscript mobile app and run it. You can also download the spk file from here: download bluetooth LED controller spk file.




function OnStart()
{
    app.SetOrientation( "Portrait" );
    app.EnableBackKey( false );
    
    lay=app.CreateLayout("linear","VCenter,FillXY");
    
    HeaderLay = app.CreateLayout( "Linear", "Horizontal,VCenter,FillX" );
    HeaderLay.SetBackColor("#AA7CA2");
    HeaderLay.SetSize( 1, 0.1);
    lay.AddChild(HeaderLay);
    
    Headerdisplay=app.CreateText("Bluetooth LED Controller");
    Headerdisplay.SetTextColor("green");
    Headerdisplay.SetTextSize(22);
    HeaderLay.AddChild(Headerdisplay);
    
    bodylay = app.CreateLayout( "Linear", "VCenter,FillX" );
    bodylay.SetBackColor("#FFCCBC");
    bodylay.SetPadding( 0.1, 0.05, 0.1, 0.05 );
    bodylay.SetSize( 1, 0.8 );
    lay.AddChild(bodylay);
    
    footerlay=app.CreateLayout("Linear","Vertical");
    footerlay.SetBackColor("grey");
    footerlay.SetSize(1,0.1);
    lay.AddChild(footerlay);
    
    footerdisplay= app.CreateText("visit us @ www.hertzelectroz.com");
    footerdisplay.SetTextColor("blue");
    footerdisplay.SetSize(22);
    footerlay.AddChild(footerdisplay);
    
    btn = app.CreateButton("connect BT",0.5,-1,"Custom");
    btn.SetOnTouch(btn_ontouch);
    btn.SetBackColor("#a2d3faa3");
    btn.SetTextColor("blue");
    btn.SetTextSize(20);
    bodylay.AddChild(btn);
    
    btnONLed = app.CreateButton("ON LED",0.2,0.07,"Custom");
    btnONLed.SetBackColor( "green" );
    btnONLed.SetSize(0.5,0.1);
    btnONLed.SetTextSize(26);
    btnONLed.SetOnTouch(btnONLed_ontouch);
    bodylay.AddChild(btnONLed);
    
    btnOffLed = app.CreateButton("OFF LED",0.5,-1,"Custom");
    btnOffLed.SetBackColor( "#E74C3C" );
    btnOffLed.SetSize(0.5,0.1);
    btnOffLed.SetTextShadow( 2, 0, 1, "#880000" );
    btnOffLed.SetTextSize(26);
    btnOffLed.SetOnTouch(btnOffLed_ontouch);
    bodylay.AddChild(btnOffLed);
    
    app.AddLayout(lay);
    app.AddLayout(HeaderLay);
    app.AddLayout(bodylay);
    app.AddLayout(footerlay);
    
    bt=app.CreateBluetoothSerial();
    bt.SetOnConnect(bt_onconnect);
    
    }
    
    function btnONLed_ontouch()
    {
      app.Vibrate("100,200");
      
      if(bt.IsConnected(true))
      { 
         // app.SetBluetoothEnabled(true);
       bt.Write("o\n");
       app.ShowPopup("on");
          }
          else
          {
             app.ShowPopup("Please connect");
          }
        }
        
       function btnOffLed_ontouch()
        {
          app.Vibrate("100,200");
          if(bt.IsConnected(true))
          {
              bt.Write("f\n");
              app.ShowPopup("off");
              }
              else
              {
                  app.ShowPopup("Please connect");
                  }
            }
    
    function btn_ontouch()
    {
        app.Vibrate("100,200");
        bt.Connect("HC-05");
        }
        
    function bt_onconnect(ok)
        {
            if(ok) {
            bt.Write("f\n");
            app.ShowPopup( "Bluetooth connected" );
            }
            else app.ShowPopup("Bluetooth Disconnected");
       }


admin

Leave a Reply

Your email address will not be published. Required fields are marked *