Bluetooth Interfacing with Arduino UNO and LCD
Hello friends this is my second post in the blog. In this tutorial I will show you how you can control or interface Bluetooth with Arduino UNO and LCD to make home automation.
Ok lets start,
For this project you will need the following components:
* 4.7 k ohm resistor
* 2 k ohm resistor
* Arduino UNO
* 16x2 LCD
* Bluetooth module etc.
* ST Terminal app
Ok lets look the circuit in bread-board:
I have used resistor in this circuit to divide the voltage because not all but few Bluetooth module needs 3.3 v for rx pin. Arduino can receive 3.3 v data coming from Bluetooth tx pin so we are not using any external circuit for it.
Ok after looking this circuit you think that wheres the Bluetooth module and relay to control the load as a output. Sorry, for not including Bluetooth module and relay to control AC loads by the way I have some problem to include Bluetooth module and output load for this. Hope you understand...
By the way to control this you need app to send data from mobile.
CODE:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int led=8;
int fan=9;
int waterpump=10;
int tx=1;
int rx=0;
char inSerial[15];
void setup(){
lcd.begin(16,2);
Serial.begin(9600);
pinMode(led, OUTPUT);
pinMode(fan, OUTPUT);
pinMode(waterpump, OUTPUT);
pinMode(tx, OUTPUT);
pinMode(rx, INPUT);
allpinslow();
lcd.print("LOADING");
delay(1500);
lcd.clear();
}
void loop(){
int i=0;
int m=0;
delay(500);
if (Serial.available() > 0) {
while (Serial.available() > 0) {
inSerial[i]=Serial.read();
i++;
}
inSerial[i]='\0';
Check_Protocol(inSerial);
}}
void allpinslow()
{
digitalWrite(led, LOW);
digitalWrite(fan, LOW);
digitalWrite(waterpump, LOW);
}
void Check_Protocol(char inStr[]){
int i=0;
int m=0;
Serial.println(inStr);
if(!strcmp(inStr,"led")){ //Led ON
allpinslow();
digitalWrite(led, HIGH);
Serial.println("led ON");
lcd.print("led is on");
for(m=0;m<11;m++){
inStr[m]=0;}
i=0;}
if(!strcmp(inStr,"fan")){ //fan ON
allpinslow();
digitalWrite(fan, HIGH);
Serial.println("fan ON");
lcd.print("fan is on");
for(m=0;m<11;m++){
inStr[m]=0;}
i=0;}
if(!strcmp(inStr,"waterpump")){ //waterpump ON
allpinslow();
digitalWrite(waterpump, HIGH);
Serial.println("waterpump ON");
lcd.print("waterpump is on");
for(m=0;m<11;m++){
inStr[m]=0;}
i=0;}
else{
for(m=0;m<11;m++){
inStr[m]=0;
}
i=0;
}}
By the way I am not including comments in this code because who comes in my blog should be GENIUS.
Ok lets start,
For this project you will need the following components:
* 4.7 k ohm resistor
* 2 k ohm resistor
* Arduino UNO
* 16x2 LCD
* Bluetooth module etc.
* ST Terminal app
Ok lets look the circuit in bread-board:
I have used resistor in this circuit to divide the voltage because not all but few Bluetooth module needs 3.3 v for rx pin. Arduino can receive 3.3 v data coming from Bluetooth tx pin so we are not using any external circuit for it.
Ok after looking this circuit you think that wheres the Bluetooth module and relay to control the load as a output. Sorry, for not including Bluetooth module and relay to control AC loads by the way I have some problem to include Bluetooth module and output load for this. Hope you understand...
By the way to control this you need app to send data from mobile.
CODE:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int led=8;
int fan=9;
int waterpump=10;
int tx=1;
int rx=0;
char inSerial[15];
void setup(){
lcd.begin(16,2);
Serial.begin(9600);
pinMode(led, OUTPUT);
pinMode(fan, OUTPUT);
pinMode(waterpump, OUTPUT);
pinMode(tx, OUTPUT);
pinMode(rx, INPUT);
allpinslow();
lcd.print("LOADING");
delay(1500);
lcd.clear();
}
void loop(){
int i=0;
int m=0;
delay(500);
if (Serial.available() > 0) {
while (Serial.available() > 0) {
inSerial[i]=Serial.read();
i++;
}
inSerial[i]='\0';
Check_Protocol(inSerial);
}}
void allpinslow()
{
digitalWrite(led, LOW);
digitalWrite(fan, LOW);
digitalWrite(waterpump, LOW);
}
void Check_Protocol(char inStr[]){
int i=0;
int m=0;
Serial.println(inStr);
if(!strcmp(inStr,"led")){ //Led ON
allpinslow();
digitalWrite(led, HIGH);
Serial.println("led ON");
lcd.print("led is on");
for(m=0;m<11;m++){
inStr[m]=0;}
i=0;}
if(!strcmp(inStr,"fan")){ //fan ON
allpinslow();
digitalWrite(fan, HIGH);
Serial.println("fan ON");
lcd.print("fan is on");
for(m=0;m<11;m++){
inStr[m]=0;}
i=0;}
if(!strcmp(inStr,"waterpump")){ //waterpump ON
allpinslow();
digitalWrite(waterpump, HIGH);
Serial.println("waterpump ON");
lcd.print("waterpump is on");
for(m=0;m<11;m++){
inStr[m]=0;}
i=0;}
else{
for(m=0;m<11;m++){
inStr[m]=0;
}
i=0;
}}
By the way I am not including comments in this code because who comes in my blog should be GENIUS.
Comments
Post a Comment