loading

Hi friends, in this instructables I am going to show you how to remotely control LED connected to Arduino using a mobile or tablet on Bluetooth. So lets start !!!

Step 1: The Things You Need -

1.) Arduino UNO.

2.) Laptop/PC with Arduino IDE pre-installed.

3.) USB B Type cable.

4.) LED of any color.

5.) HC - 05 or HC - 06 Bluetooth Module.

6.) Connecting wires.

7.) "What's Up Arduino" app. Click here to know more about the app.

Step 2: The Schematic -

This schematic is used with the help of the software Fritzing Beta.

Step 3: The Code -

/******sketch for WhatsUpArduino App*******/

#include <SoftwareSerial.h> // import the serial library

SoftwareSerial chat(10, 11); // RX, TX
void setup() {
  chat.begin(9600);
}

void loop() {
  if (chat.available()){
    String readStr = "";
    readStr=chat.readString();
    //pinMode
    if(readStr.startsWith("pinMode")){
      String pin=readStr.substring(readStr.indexOf("(")+1,readStr.indexOf(","));
      int pinNo=pin.toInt();
      String mode=readStr.substring(readStr.indexOf(", ")+2,readStr.indexOf(")"));
      if(mode=="INPUT"){
        pinMode(pinNo, INPUT);}
      if(mode=="OUTPUT"){
        pinMode(pinNo, OUTPUT);}
      if(mode=="INPUT_PULLUP"){
        pinMode(pinNo, INPUT_PULLUP);}
      chat.println("done");
    }
    //digitalWrite
    if(readStr.startsWith("digitalWrite")){
      String pin=readStr.substring(readStr.indexOf("(")+1,readStr.indexOf(","));
      int pinNo=pin.toInt();
      String value=readStr.substring(readStr.indexOf(", ")+2,readStr.indexOf(")"));
      if(value=="HIGH"){
        digitalWrite(pinNo, HIGH);}
      if(value=="LOW"){
        digitalWrite(pinNo, LOW);}
      chat.println("done");
    }
    //digitalRead
    if(readStr.startsWith("digitalRead")){
      String pin=readStr.substring(readStr.indexOf("(")+1,readStr.indexOf(","));
      int pinNo=pin.toInt();
      int val=digitalRead(pinNo);
      if(val==1){        
      chat.println("it's HIGH");}
      if(val==0){       
      chat.println("it's LOW");}
    }
    //analogWrite
    if(readStr.startsWith("analogWrite")){
      String pin=readStr.substring(readStr.indexOf("(")+1,readStr.indexOf(","));
      int pinNo=pin.toInt();
      String val=readStr.substring(readStr.indexOf(", ")+2,readStr.indexOf(")"));
      int value=val.toInt();
      if(pinNo==10 || pinNo==11){
        chat.println("You were trying to write on pins which are used by bluetooth RX/TX");// analog write/PWM on pins used by bluetooth can interrupt communication.
      }else{
        analogWrite(pinNo, value);
        chat.println("done");
      }
    }
    //analogRead
    if(readStr.startsWith("analogRead")){
      String pin=readStr.substring(readStr.indexOf("(")+1,readStr.indexOf(","));
      int pinNo=pin.toInt();
      int val=analogRead(pinNo);
      chat.println("it's " + String(val));
    }
    
  }
  
}
\/********end of sketch**********\/

Step 4: Use the App -

Download the 'What's Up Arduino Free' app in to your mobile or tablet. This app can be used to send different commands to Arduino. In this tutorial we will be using only the 'digitalWrite' command to ON/OFF the LED.

Power ON your Arduino with HC-05 and open the app in your mobile. If Bluetooth of your mobile is not ON the app will ask your permission to make it ON. When you switch ON the Bluetooth the mobile will scan other Bluetooth devices and list all the devices including your Arduino HC-05. Please note that only 'paired' Bluetooth devices are shown in the list.

If you are not able to see your module then try 'pairing' it with your mobile by tapping on '+' button in this app. This button will open Bluetooth settings of the mobile/tablet which will scan your Arduino HC-05 module and show it (if you are using HC-05 then it will appear in the list with same name as shown in photos). When you see your device in the list tap on it to 'pair' the module with mobile. Use 0000 or 1234 as the password to pair. After successful pairing you will be able to see your module in the 'Paired devices' list.

Tap on the HC-05 in the paired list which you want to connect. On tapping, a command page will open as shown in the photos. The screen shows various commands which can be sent to Arduino. Tap on the 'connect' button on this page to connect to the Arduino HC-05. On successful connection proceed further.

We want to use pin 13 to make the LED ON/OFF so first set pin 13 to 'OUTPUT' mode. Tap on the 'pinMode' tab and select 'OUTPUT' option and then select number 13 (pin 13) so an appropriate command "pinMode(13, OUTPUT)" message is created automatically. Send this message to Arduino by tapping on 'send' button. Arduino will respond with 'done' message to indicate successful execution after which you can proceed for next command to make LED ON.

We want to make pin 13 high to switch LED ON so tap on the 'digitalWrite' tab, select 'HIGH' option and then tap on number 13. send this message to Arduino, the Arduino will respond with 'done' message and LED connected to pin 13 will glow ON.

To switch off the LED, go to the 'digitalWrite' tab, choose 'LOW' option then tap on 13 and send the message which will switch off the LED.

Note: THE FREE EDITION OF THIS APP WILL BE RUNNING ONLY FOR 2 MINUTES. IF YOU WANT TO USE THE APP FOR LONGER THEN YOU WILL HAVE TO DOWNLOAD THE 'PRO' VERSION OF THE APP FROM HERE.

Step 5: Suggestions -

You can also connect a relay instead of the LED to control home appliances.

THANK YOU :-)

About This Instructable

368views

12favorites

License:

More by soardr:Simple LED Blink Using ESP8266 Voice Controlled LED Unlock Your Door Using Phone Or Tablet 
Add instructable to: