Devices & Components
Arduino Uno Rev3
HC-05 Bluetooth Module
Female Header 8 Position 1 Row (0.1")
Mini breadboard
4 Channel SPDT relay
Arduino Wireless Proto Shield
AC Load
Software & Tools
MIT App Inventor 2
Arduino IDE
Project description
Code
Home automation code
arduino
1#include<SoftwareSerial.h> 2SoftwareSerial BTserial(3,2); // TX|RX 3//Declaration of variables 4String msg = ""; 5String v1 = ""; 6 7int light_1 = 11; 8int light_2 = 10; 9int light_3 = 9; 10int light_4 = 8; 11void setup() { 12 // put your setup code here, to run once: 13 //set up our serial and bluetooth serial monitors 14 Serial.begin(9600); 15 BTserial.begin(9600); 16} 17 18void loop() { 19 // put your main code here, to run repeatedly: 20 // check it bluetooth serial is connected and available 21 if (BTserial.available() > 0){ 22 msg = BTserial.parseInt();// decode the integer sent from phone through BT serial. 23 } 24 // check the integer and give corresponding output 25 if(msg == "11"){ 26 digitalWrite(light_1,LOW); 27 } 28 if(msg == "10"){ 29 digitalWrite(light_1,HIGH); 30 } 31 if(msg == "21"){ 32 digitalWrite(light_2,LOW); 33 } 34 if(msg == "20"){ 35 digitalWrite(light_2,HIGH); 36 } 37 if(msg == "31"){ 38 digitalWrite(light_3,LOW); 39 } 40 if(msg == "30"){ 41 digitalWrite(light_3,HIGH); 42 } 43 if(msg == "41"){ 44 digitalWrite(light_4,LOW); 45 } 46 if(msg == "40"){ 47 digitalWrite(light_4,HIGH); 48 } 49 Serial.println(v1); 50 delay(500); 51}
Downloadable files
Home automation circuit
Home automation circuit

Home automation circuit
Home automation circuit

Comments
Only logged in users can leave comments