-
Notifications
You must be signed in to change notification settings - Fork 0
/
Electro_code.ino.ino
122 lines (109 loc) · 2.29 KB
/
Electro_code.ino.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <IRremote.h>
#include<Servo.h>
Servo servo1;
Servo servo2;
int MQ2pin = A0;
#define TEMPERATURE A2
int pirstate = 0;
#define pir 7
const int gas = 0;
int light = 3;
int light2 = 13;
int fan = 6;
int ls = 0;
int fs = 0;
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
int speed_decider(int temp){
if(temp<20)
return 0;
else if(temp>40)
return 255;
else
return map(temp, 20, 40, 0, 255);
}
void setup()
{
pinMode(light, OUTPUT);
pinMode(fan, OUTPUT);
pinMode(pir, INPUT);
pinMode(light2, OUTPUT);
pinMode(8,INPUT);
pinMode(9,OUTPUT);
pinMode(A3,INPUT);
servo1.attach(5);
servo2.attach(2);
Serial.begin(9600);
irrecv.enableIRIn();
}
void loop() {
digitalWrite(9,LOW);
delayMicroseconds(10);
digitalWrite(9,HIGH);
delayMicroseconds(10);
digitalWrite(9,LOW);
int val=pulseIn(8,HIGH);
Serial.println(val);
float angle = -0.010*val + 103.13;
servo1.write(angle);
int phtr=analogRead(A3);
Serial.println(phtr);
float angle2=0.133*phtr - 0.802;
servo2.write(angle2);
if (irrecv.decode(&results)) {
unsigned int value = results.value;
// Serial.println(value);
if(value == 2295)
{
digitalWrite(light, HIGH);
ls+= 1;
if(ls% 2 == 0){
digitalWrite(light,LOW);
ls = 0;
}
delay(100);
}
if(value == 18615)
{
digitalWrite(6,HIGH);
fs += 1;
if(fs %2 == 0){
digitalWrite(fan, LOW);
fs = 0;
}
delay(100);
}
irrecv.resume();
}
if(fs == 1){
int temperature = analogRead(TEMPERATURE);
temperature = map(temperature, 20, 358, -40, 125);
analogWrite(fan, speed_decider(temperature));
}
pirstate = digitalRead(pir);
Serial.println(pirstate);
if (pirstate == 1) {
digitalWrite(light2, HIGH);
} else {
digitalWrite(light2, LOW);
}
delay(10);
float sensorValue,MQ2pin;
sensorValue = analogRead(MQ2pin);
if(sensorValue >= 850){
digitalWrite(A1,HIGH);
// Serial.print(sensorValue);
// Serial.println(" SMOKE !!!");
}
else{
digitalWrite(A1,LOW);
//Serial.println("Sensor Value: ");
//Serial.println(sensorValue);
}
delay(250);
}
float getsensorValue(int pin)
{
return (analogRead(pin));
}