-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNew_Sensor_Combined_Code.ino
164 lines (155 loc) · 3.05 KB
/
New_Sensor_Combined_Code.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#include<Servo.h>
#include<LiquidCrystal.h>
#include<dht.h>
dht DHT;
#define DHT11_PIN A0
LiquidCrystal lcd = LiquidCrystal(5,6,7,8,9,10);
int Rain_In = A1;
int Motion_input_sensor_1 = A2;
int Motion_input_sensor_2 = A3;
int Soil_moisture_pin = A5;
int Gas_sensor_pin = A4;
int Rain_Digital_In = 2;
int Buzz_Pin = 3;
int YELLOW = 12;
int Vibr_Pin = 4;
int RED = 13;
Servo rubo;
int motion_1 = 0;
int motion_2 = 0;
void setup()
{
Serial.begin(9600);
lcd.begin(16,2);
//pinMode(Rain_In,INPUT);
pinMode(Motion_input_sensor_1,INPUT);
pinMode(Motion_input_sensor_2,INPUT);
pinMode(Soil_moisture_pin,INPUT);
pinMode(Gas_sensor_pin,INPUT);
pinMode(Rain_Digital_In,INPUT);
pinMode(Buzz_Pin,OUTPUT); //for vibration sensor
pinMode(YELLOW,OUTPUT);
pinMode(Vibr_Pin,INPUT);
pinMode(RED, OUTPUT);
rubo.attach(11);
digitalWrite(Buzz_Pin,LOW);
digitalWrite(YELLOW,LOW);
digitalWrite(RED,LOW);
}
void loop()
{
Temp_and_Humid_Sensor();
Vibration_Sensor();
PIR_Sensor();
Gas_Sensor_Module();
Soil_Moisture_Sensor();
Servo_Control();
Rain_Sensor();
}
void Gas_Sensor_Module()
{
int Gas_In = analogRead(Gas_sensor_pin);
Serial.print("Gas_Val = ");
Serial.println(Gas_In);
if (Gas_In > 600)
{
digitalWrite(RED,HIGH);
}
else
{
digitalWrite(RED,LOW);
}
delay(100);
}
void Servo_Control()
{
rubo.write(0);
delay(1000);
rubo.write(45);
delay(1000);
rubo.write(0);
delay(1000);
}
void PIR_Sensor()
{
motion_1 = digitalRead(Motion_input_sensor_1);
motion_2 = digitalRead(Motion_input_sensor_2);
Serial.print("Motion_1 = ");
Serial.println(motion_1);
Serial.print("Motion_2 = ");
Serial.println(motion_2);
if(motion_1 == 1 || motion_2 == 1)
{
digitalWrite(YELLOW,HIGH);
delay(10);
digitalWrite(YELLOW,LOW);
delay(10);
}
else
{
digitalWrite(YELLOW,LOW);
}
delay(100);
}
void Vibration_Sensor()
{
long measurement = pulseIn(Vibr_Pin, HIGH);
delay(10);
Serial.print("Measurement = ");
Serial.println(measurement);
if (measurement > 1000)
{
digitalWrite(Buzz_Pin, HIGH);
}
else
{
digitalWrite(Buzz_Pin, LOW);
}
delay(10);
}
void Temp_and_Humid_Sensor()
{
int chk = DHT.read11(DHT11_PIN);
lcd.setCursor(0,0);
lcd.print("Temp = ");
lcd.print(DHT.temperature);
lcd.print(" ");
lcd.print((char)223);
lcd.println("C ");
lcd.setCursor(0,1);
lcd.print("Humidity =");
lcd.print(DHT.humidity);
lcd.print("%");
delay(100);
}
/*void Soil_Moisture_Sensor()
{
// Soil Moisture Sensor
int soil_moisture_val = analogRead(Soil_moisture_pin);
soil_moisture_val = map(soil_moisture_val,1023,0,0,100);
Serial.print("Moisture = ");
Serial.print(soil_moisture_val);
Serial.print("%");
delay(1000);
}
void Rain_Sensor()
{
// Rain Sensor
int Rain_Val = analogRead(Rain_In);
bool blsRaining = !(digitalRead(Rain_Digital_In));
if(blsRaining)
{
blsRaining = "YES";
//digitalWrite(buzz,HIGH);
//delay(1000);
}
else
{
blsRaining = "NO";
}
Serial.print("Raining?:");
Serial.print(blsRaining);
Serial.print(", Moisture Level:");
Serial.println(Rain_Val);
delay(100);
}*/