Project Name:-Android app control LED via bluetooth communication
Today i am going to control LED by Android app through Bluetooth communication.
Component required
- computer
- arduino with cable
- Bluetooth module (HC-05)
- RGB led
- android phone
And a software named arduino ide in computer.
According to Wikipedia"Bluetooth is the wireless technology standard for exchanging the data over a short distance (using a short wave length) from the fixed and the mobile device and building the personal area networks(PANs)"
Bluetooth Module HC-05 is easy to use serial port protocol ,designed for wireless serial connection to exchange the data.
Fig :- Bluetooth module HC-05
We need controller or transmitter to send the command to the receiver (i.e HC-05 module), here we use android app "Bluetooth terminal" in android phone to send the command to HC-05 module via Bluetooth connection.
download the Bluetooth terminal from play store.
Circuit
fig bluetooth module HC-05 interfacing with arduino
connect the tx and rx pin to 10 and 11 pin of an arduino ashown in figure connect an
RGB led in any pin for example, let it is connect in pin no. 5,6 and 7.
Code
#include <SoftwareSerial.h>
int led1=5;
int led2=6;// pin define
int led3=7;
SoftwareSerial myserial(10,11);
void setup() {
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT);
Serial.begin(9600);
myserial.begin(9600);
myserial.println("connect A B C or any other");
// put your setup code here, to run once:
}
void loop()
{
if (myserial.available())
{
int val=myserial.read();
Serial.println(val);
if(val=='a')
{
digitalWrite(led1,HIGH);
digitalWrite(led2,LOW);
digitalWrite(led3,LOW);
Serial.println("a");
}
else if(val=='b')
{
digitalWrite(led1,LOW);
digitalWrite(led2,HIGH);
digitalWrite(led3,LOW);
Serial.println("b");
}
else if(val=='c')
{
digitalWrite(led1,LOW);
digitalWrite(led2,LOW);
digitalWrite(led3,HIGH);
Serial.println("c");
}
else
{
digitalWrite(led1,HIGH);
digitalWrite(led2,HIGH);
digitalWrite(led3,HIGH);
Serial.println("other alphabet");
}
}
}
Now connect the phone to the system via bluetooth communication.
Then if we enter input ''a" then only led1 will ON,similarly, for B led2 will ON and for C led3 will ON.