Arduino code:
/*
* Connections of Arduino and Bluetooth Module HC-05 for this Code:
* Arduino | Bluetooth Module (HC-05)
* 1 | RX
* 0 | TX
* 3V | 3V
* GND | GND
*/
//Technical idEas
// https://youtube.com/channel/UCCJyR_wnt3SxhErsSUP9Wrw
//Home Automation
#include <SoftwareSerial.h> //including library for Software Serial communication
SoftwareSerial mySerial (0, 1); //(RX, TX)
//defining all the pins of Arduino
#define s1 2
#define s2 3
#define s3 4
#define s4 5
void setup()
{
//setting all the pins
pinMode(s1, OUTPUT);
pinMode(s2, OUTPUT);
pinMode(s3, OUTPUT);
pinMode(s4, OUTPUT);
//defining baudrate
Serial.begin(9600);
mySerial.begin(9600);
}
void loop()
{
if(mySerial.available() == 1) //if communication is going on
{
char val = mySerial.read(); //Read the data recieved
Serial.println("Recieved data is " + (String) val);
if(val == 'A')
{
digitalWrite(s1, HIGH);
Serial.println("Switch 1 is ON");
}
if(val == 'a')
{
digitalWrite(s1, LOW);
Serial.println("Switch 1 is OFF");
}
if(val == 'B')
{
digitalWrite(s2, HIGH);
Serial.println("Switch 2 is ON");
}
if(val == 'b')
{
digitalWrite(s2, LOW);
Serial.println("Switch 2 is OFF");
}
if(val == 'C')
{
digitalWrite(s3, HIGH);
Serial.println("Switch 3 is ON");
}
if(val == 'c')
{
digitalWrite(s3, LOW);
Serial.println("Switch 3 is OFF");
}
if(val == 'D')
{
digitalWrite(s4, HIGH);
Serial.println("Switch 4 is ON");
}
if(val == 'd')
{
digitalWrite(s4, LOW);
Serial.println("Switch 4 is OFF");
}
}
}
0 Comments