Control Things Using Mobile

In this workhop we will learn how to control things using a mobile app with arduino and bluetooth module .

Problem Statement

We need to get up and walk into the switch board everytime to turn on and off the light or fan etc.

Idea

What if, we have a system that can be contol the light and fan using our mobile phone.

Solution

Build a device that can be controled with mobile app , so we can use the device to trigger the actions on home appliance .


Prototype Building

Using Arduino and Andoird App we can make the idea into a relaity, since the Arduino can turn on and off using programming also it can be attached with bluetooth module, so we can build a mobile app that can be communicate with arduino.

Diagram


Things we need

  1. Arduino Uno
  2. HC-05 Bluetooth Module
  3. Led’s
  4. Jumber Wires
  5. Breadboard

Step 1: Arduino Setup

1.1: Install Arduino IDE

Download the Arduino IDE and install it on your computer.

Arduino IDE Download

1.2 walk-through the Arduino Introduction page to learn basics

If you are new to the arduino system, you can learn the Arduino basics from here , after reading then go to the next step.

Step 2: Coding

2.1 Algorithm

algorithm


2.2 Open Arduino IDE and Start a new Sketch

Arduino IDE Sketch

2.3 Copy and Paste the Code

char data = 0; //Variable for storing received data

void setup()
{
  Serial.begin(9600);         //Sets the data rate in bits per second (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
    if (data == 'A')           //Checks whether value of data is equal to "A"
      digitalWrite(13, HIGH);  //If value is "A" then LED turns ON
    else if (data == 'B')      //Checks whether value of data is equal to "B"
      digitalWrite(13, LOW);   //If value is "B" then LED turns OFF
  }
}


2.4 Code Overview

Syntax Serial.begin(speed); here we used speed as 9600bps.

Syntax pinMode(pin, mode) :- pin : the Arduino pin number to set the mode of, mode : INPUT, OUTPUT, or INPUT_PULLUP.

Syntax digitalWrite(pin, value) , Parameters pin : the Arduino pin number. value : HIGH or LOW.


2.5 Compile the code

You can Compile and verify your code by clicking the Verify button on Arduino IDE, this process will check syntax errors.

verify code

after successful compilation you can see Done Compiling

done verify


2.5 Upload the code into Arduino uno

After successful compilation we can upload the code into Arduino Uno Devlopment board. for that we need click **Upload button.

uploadcode

before upaloading we need to select the devlopment board from the from Arduino IDE Tools -> Board and Port from Arduino IDE Tools -> Port.

selectport

selectboard

here I selected Arduino Uno as board and COM26 as Port.

Then click Upload

doneupload


Step 3: Testing

We can test the project from halfway without bluetooth module by using Serial Monitor .

3.1 Connect LED

Connect the LED Postive pin on Arduino Pin 13 and Negative Pin on Arduino Grond (GND)

arduinoandled

After connecting the LED connect the USB cable and Open Serial Monitor .

serial monitor

Open the Serial Monitor and try enter A or B and press enter or click send button.

send char

You can see logic in action.

test gif


Step 4: Building Android Application

To build Mobile application we are using MIT APP INVENTOR, MIT App Inventor for Android is an open-source web application originally provided by Google, and now maintained by the Massachusetts Institute of Technology (MIT).App Inventor lets you develop applications for Android phones using a web browser and either a connected phone or emulator.

Open MIT APP INVENTOR and Login , and Click Creat Apps to start the devlopment.

Creat Apps


MIT App inventor

Flow chart

MIT App inventor flowchart

App inventor have two part

  1. The App Inventor Designer, where you select the components for your app.
  2. The App Inventor Blocks Editor, where you assemble program blocks that specify how the components should behave. You assemble programs visually, fitting pieces together like pieces of a puzzle.

Here we are going to control LED light by using our phone , for this we need an Application so we are using MIT App inventor.

4.1 UI Devlopment

The App Inventor Components are located on the left hand side of the Designer Window under the title Palette. Components are the basic elements you use to make apps on the Android phone. They’re like the ingredients in a recipe. Some components are very simple, like a Label component, which just shows text on the screen, or a Button component that you tap to initiate an action.

app ui

We need add two Buttons For Turn ON and Turn OFF the LED , and One Listpicker for selecting the bluetooth device. also we need to add the Bluetooth Client it avilable under the Connectivity tab.

app ui

Here is Simple design if the Application User Interface.you can see the components list that we used in the app in right side.

4.2 Adding App Logic

Actually we don’t need any coding to do our app , we just need to arrange some logic blocks in a order . to get into logic you need to click the block button on the right corner .

app logic

we have main two code blocks.

  1. Bluetooth selection
    we are using ListPicker for the bluetooth selection.

app listpicker

ListPicker have two state , one is BeforePicking state,in here we are loading bluetooth names in the list, second is AfterPicking here we are connecting the Bluetooth device that loaded on the ListPicker BeforePicking state , and also we are changing the text of the ListPicker in to Connected when we establish a bluetooth connection.

  1. Button Activity we are using two buttons for contorling LED state

app listpicker

when we click a button bluetooth will transmit a text to device that connectedw with phone(we alredy connected a bluetooth device using ListPicker Bluetooth Selection). here if we press the Button2 it will transmit letter ‘A’ and if we press the Button3 it will transmit letter ‘B’ ,that’s all.

4.3 Download the application

We need to install applicaion on our mobile phone , .apk file can be download by clicking Build button on the top navigavtion panel.

app downlaod

Building Apk will take less than one minute time.

app build

Download the .apk file and install it on your android phone.next upload bluetooth progarmme to your board and connect with bluetooth module.


Setp 5: Interfacing Arduino with Bluetooth Module.

Next we need to connect the Arduino into Bluetooth module.here we are using HC-05 It is based on Bluetooth SPP (Serial Port Protocol) module,designed for transparent wireless serial connection setup.he HC-05 Bluetooth Module can be used in a Master or Slave configuration.This serial port bluetooth module is fully qualified Bluetooth V2.0+EDR (Enhanced Data Rate) 3Mbps Modulation with complete 2.4GHz radio transceiver and baseband. It uses CSR Bluecore 04‐External single chip Rluetooth system with CMOS technology and with AFH (Adaptive Frequency Hopping Feature).datasheet :- https://www.gme.cz/data/attachments/dsh.772-148.1.pdf

hc05

5:1 Pin Description

The HC-05 Bluetooth Module has 6pins. They are as follows:

5:2 Connection Diagram

connection pinout

Connect the arduino on hc-05 bluetooth module with jumbers or breadboard.

Demo

demo



ToDO



Thank You, Hope you enjoyed!

Please share your feedback.