Introduction:
In my previous article I explained working with Ultra Sonic Sensor, and in this article I'll show you the connection between Arduino and Android using Bluetooth Module.
Requirements:
- Arduino Uno
- Bluetooth Module HC-05
- Android Phone
- Mit App Invertor
- Led
Connections:
Bluetooth Module to Arduino:
- Vcc to 5v
- Gnd to Gnd
- Rx pin to Tx Pin
- Tx pin to Rx Pin
- Led to Digital Pin 5
MIT App Invertor:
- Go to MIT App Invertor 2.
- Start new project.
- And the design the app for our BT Connection.
- In the left side corner we have the palette windows in that we have the reqired tools just drag and drop and complete the desing process .
- After that we want to make the code for our design part go to Blocks section and make the following code that shown in the figure2.
Figure 1: Designer
BLOCKS WINDOW
Figure 2: Blocks
Arduino BT Program:- int ledpin = 5;
- String readString;
- void setup()
- {
- Serial.begin(9600);
- pinMode(ledpin, OUTPUT);
- }
-
- void loop()
- {
- while (Serial.available())
- {
- delay(4);
- char c = Serial.read();
- readString += c;
- }
- if (readString.length() > 0)
- {
- Serial.println(readString);
- if (readString == "ON")
- {
- digitalWrite(ledpin, HIGH);
- }
- if (readString == "OFF")
- {
- digitalWrite(ledpin, LOW);
- }
- readString = "";
- }
- }
Output:
Explanation:
Intialize the variable ledpin=5 declare the string as readString.
void Setup()
In the Setup() function set the baud rate 9600 it sends the data bits per/sec and set the pinMode to led as OUTPUT and.
void loop():
In the loop() function we want to make the conditions of how BT works based upon our conditions of how the bluetooth will act.
Serial.available:
- Serial.available is the one type of the function.
- Serial is used for the communication between the arduino and the other devices like computer,mobile phone etc.
- All the Arduino board have RX pin and the TX pin.
- Based up on these pin the BT make communication between the Arduino .
- And Serial.Read() it reads the Incoming serial data from the bluetooth.
- If(readString =="ON") this condition is true the led will ON.
- If(readString =="OFF") the led is OFF.
Conclusion:
And finally, we conclude that we made the Connection between Arduino to Android using a Bluetooth Device.