Components and supplies
PIR Motion Sensor (generic)
HC-05 Bluetooth Module
LDR (LIGHT DEPENDENT RESISTER)
LED (generic)
Arduino UNO
Temperature Sensor
Relay (generic)
Jumper wires (generic)
Apps and platforms
Arduino IDE
Windows 10
Project description
Code
CODE FOR HOME AUTOMATION
c_cpp
TYPED ON ARDUINO IDE
1 2 3float x,y; //TEMP 4#define trigPin 12 //ULTRA 5#define echoPin 10 6int ledPin= 13; 7int duration, distance; //ULTRA 8 9#include<Servo.h> //servo 10Servo my; //servo 11 12char val; //bluetooth 13 14void setup() { 15 Serial.begin(9600); 16 pinMode(2,INPUT); //IR GATE FIRST 17 pinMode(3,INPUT); 18 my.attach(11); //servo 19 20 pinMode(4, OUTPUT); //IR GATE FIRST 21 22 23 pinMode(7,OUTPUT); //TEM 24 pinMode(8,INPUT); //pir 1 25 pinMode(9,OUTPUT); //LED 1 26 // pinMode(10,INPUT); //pir 2 27 //pinMode(11,OUTPUT); //LED2 28 pinMode(trigPin, OUTPUT); //12 PIN ULTRA 29 pinMode(echoPin, INPUT); //10 PIN ULTRA 30 pinMode(ledPin, OUTPUT); //13 PIN ULTRA 31 32 33 34 pinMode(3,OUTPUT); //bluetooth 35} 36 37 38 39void loop() { 40 x=analogRead(0); //TEMP 41 y=((x/1024)*5)*100; 42 Serial.println(y); 43 delay(500); 44 45 if(y>44) 46 { 47 digitalWrite(7,1); 48 } 49 else 50 { 51 digitalWrite(7,0); 52 delay(500); 53 } 54 //TEMP 55 56 57if(digitalRead(8)==HIGH) //pir 58 { 59 digitalWrite(9,HIGH); 60 } 61 else 62{ digitalWrite(9,LOW);} 63 64 65 66 67 digitalWrite(trigPin, HIGH); //ULTRA 68 delayMicroseconds(10); 69 digitalWrite(trigPin, LOW); 70 duration = pulseIn(echoPin, HIGH); 71 distance = (duration/2) / 29.1; 72 73 if (distance >= 10 || distance <= 0) 74 { 75 // Serial.println("no object detected"); 76 77 78 digitalWrite(ledPin,LOW); 79 } 80 else 81 { 82 Serial.println("object detected \ 83"); 84 Serial.print("distance= "); 85 86 Serial.print(distance); 87 digitalWrite(ledPin,HIGH); 88 } //ULTRA 89if(digitalRead(2)==HIGH) //gate first 90 { 91 my.write(0); //servo 92 93 94 } 95 else 96 { 97 my.write(90); //servo 98 } 99 100 analogRead(5); //ldr 101 float a = analogRead(5); 102 Serial.println(a); 103 104 105 if (a <=200) { 106 107 digitalWrite(4,1); 108 Serial.println("LDR is DARK, LED is ON"); 109 110 111 } 112 else { 113 114 digitalWrite(4,0); 115 Serial.println("-----"); 116 117 118 } //ldr 119 120 121 122if (Serial.available()) //bluetooth 123{ 124 val = Serial.read(); 125 Serial.println(val); 126 127 128 if(val == 'TV') 129 digitalWrite(3,HIGH); 130 131 else if(val == 'tv') 132 digitalWrite(3,LOW); 133 134 } //bluetooth 135 136 137} 138
CODE FOR HOME AUTOMATION
c_cpp
TYPED ON ARDUINO IDE
1 2 3float x,y; //TEMP 4#define trigPin 12 //ULTRA 5#define 6 echoPin 10 7int ledPin= 13; 8int duration, distance; //ULTRA 9 10#include<Servo.h> 11 //servo 12Servo my; //servo 13 14char val; //bluetooth 15 16void 17 setup() { 18 Serial.begin(9600); 19 pinMode(2,INPUT); //IR GATE FIRST 20 pinMode(3,INPUT); 21 22 my.attach(11); //servo 23 24 pinMode(4, OUTPUT); //IR GATE FIRST 25 26 27 28 pinMode(7,OUTPUT); //TEM 29 pinMode(8,INPUT); //pir 30 1 31 pinMode(9,OUTPUT); //LED 1 32 // pinMode(10,INPUT); //pir 33 2 34 //pinMode(11,OUTPUT); //LED2 35 pinMode(trigPin, OUTPUT); //12 36 PIN ULTRA 37 pinMode(echoPin, INPUT); //10 PIN ULTRA 38 pinMode(ledPin, OUTPUT); 39 //13 PIN ULTRA 40 41 42 43 pinMode(3,OUTPUT); 44 //bluetooth 45} 46 47 48 49void loop() { 50 x=analogRead(0); 51 //TEMP 52 y=((x/1024)*5)*100; 53 Serial.println(y); 54 delay(500); 55 56 57 if(y>44) 58 { 59 digitalWrite(7,1); 60 } 61 else 62 { 63 digitalWrite(7,0); 64 65 delay(500); 66 } 67 //TEMP 68 69 70if(digitalRead(8)==HIGH) 71 //pir 72 { 73 digitalWrite(9,HIGH); 74 } 75 else 76{ digitalWrite(9,LOW);} 77 78 79 80 81 82 digitalWrite(trigPin, HIGH); //ULTRA 83 delayMicroseconds(10); 84 85 digitalWrite(trigPin, LOW); 86 duration = pulseIn(echoPin, HIGH); 87 distance 88 = (duration/2) / 29.1; 89 90 if (distance >= 10 || distance <= 0) 91 { 92 93 // Serial.println("no object detected"); 94 95 96 digitalWrite(ledPin,LOW); 97 98 } 99 else 100 { 101 Serial.println("object detected \ 102"); 103 Serial.print("distance= 104 "); 105 106 Serial.print(distance); 107 digitalWrite(ledPin,HIGH); 108 109 } //ULTRA 110if(digitalRead(2)==HIGH) 111 //gate first 112 { 113 my.write(0); //servo 114 115 116 117 } 118 else 119 { 120 my.write(90); //servo 121 } 122 123 analogRead(5); 124 //ldr 125 float a = analogRead(5); 126 Serial.println(a); 127 128 129 130 if (a <=200) { 131 132 digitalWrite(4,1); 133 Serial.println("LDR 134 is DARK, LED is ON"); 135 136 137 } 138 else { 139 140 digitalWrite(4,0); 141 142 Serial.println("-----"); 143 144 145 } //ldr 146 147 148 149 150if (Serial.available()) //bluetooth 151{ 152 153 val = Serial.read(); 154 Serial.println(val); 155 156 157 if(val == 'TV') 158 159 digitalWrite(3,HIGH); 160 161 else if(val == 'tv') 162 digitalWrite(3,LOW); 163 164 165 } //bluetooth 166 167 168} 169
Downloadable files
BLUEPRINT FOR PROJECT
BLUEPRINT FOR PROJECT
Comments
Only logged in users can leave comments