-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathf1.ino
131 lines (115 loc) · 3.26 KB
/
f1.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
#include <SoftwareSerial.h>
SoftwareSerial mySerial(9, 10);
int redLed_2 = 2;
int greenLed_2 = 3;
int redLed_135 = 5;
int greenLed_135 = 4;
int redLed_7 = 7;
int greenLed_7 = 6;
int k1=0;
int smokeA0_135 = A4;
int smokeA0_2 = A5;
int smokeA0_7 = A3;
int count=0;
int solenoidPin = 12;
int sensorThres_2 =300;
int sensorThres_135 =350;
int sensorThres_7 =350;
void setup() {
pinMode(redLed_2, OUTPUT);
pinMode(greenLed_2, OUTPUT);
pinMode(smokeA0_2, INPUT);
pinMode(redLed_135, OUTPUT);
pinMode(greenLed_135, OUTPUT);
pinMode(smokeA0_135, INPUT);
pinMode(redLed_7, OUTPUT);
pinMode(greenLed_7, OUTPUT);
pinMode(smokeA0_7, INPUT);
pinMode(solenoidPin, OUTPUT);
digitalWrite(solenoidPin, HIGH);
mySerial.begin(9600);
Serial.begin(9600);
}
void loop() {
int analogSensor_2 = analogRead(smokeA0_2);
// delay(400);
int analogSensor_135 = analogRead(smokeA0_135);
//delay(400);
int analogSensor_7 = analogRead(smokeA0_7);
//delay(400);
//Serial.print("Pin A0-MQ2: ");
Serial.print(analogSensor_2);
Serial.print(",");
Serial.print("\t\tPin A0-MQ135: ");
Serial.print(analogSensor_135);
Serial.print(",");
Serial.print("\t\tPin A0-MQ7: ");
Serial.print(analogSensor_7);
Serial.print(",");
// Serial.println("before high");
Serial.println("");
//Serial.println("after high");
//delay(10000);
//Serial.print("high delay ended");
if (analogSensor_2 > sensorThres_2)
{
digitalWrite(redLed_2, HIGH);
digitalWrite(greenLed_2, LOW);
count=count+1;
// Serial.println("inside 1st sensor");
}
else
{
digitalWrite(redLed_2, LOW);
digitalWrite(greenLed_2, HIGH);
}
if (analogSensor_135 > sensorThres_135)
{
digitalWrite(redLed_135, HIGH);
digitalWrite(greenLed_135, LOW);
// Serial.println("inside 2nd sensor");
count=count+1;
}
else
{
digitalWrite(redLed_135, LOW);
digitalWrite(greenLed_135, HIGH);
}
if (analogSensor_7 > sensorThres_7)
{
digitalWrite(redLed_7, HIGH);
digitalWrite(greenLed_7, LOW);
// Serial.println("inside 3rd sensor");
count=count+1;
}
else
{
digitalWrite(redLed_7, LOW);
digitalWrite(greenLed_7, HIGH);
}
delay(1000);
// Serial.println(count);
Serial.println("");
if(analogSensor_2 > sensorThres_2 && analogSensor_135 > sensorThres_135 && analogSensor_7 > sensorThres_7 && k1==0){
k1=1;
SendMessage();
delay(10000);
digitalWrite(solenoidPin, LOW);
Serial.println("stopping vehicle");
delay(10000);
}
if (mySerial.available()>0)
Serial.write(mySerial.read());
}
void SendMessage()
{
mySerial.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(1000); // Delay of 1000 milli seconds or 1 second
mySerial.println("AT+CMGS=\"+91xxxxxxxxxx\"\r"); // Replace x with mobile number
delay(1000);
char text[300]="Dear User, The emission level of your respective vehicle has exceeded the safe emission standards. Please meet the nearest service center and get your vehicle repaired!.";
mySerial.print(text);// The SMS text you want to send
delay(100);
mySerial.print((char)26);// ASCII code of CTRL+Z
delay(1000);
}