-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVehicle Emission Monitoring System
49 lines (42 loc) · 1.73 KB
/
Vehicle Emission Monitoring System
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
#define BLYNK_TEMPLATE_ID "TMPL3XzrSSZbz"
#define BLYNK_TEMPLATE_NAME "Vehicle Emission Monitoring System"
#define BLYNK_AUTH_TOKEN "o-JQekJHjb-Su4GFbt-kZOSu_GIiutFS"
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "****"; // Enter your WiFi name
char pass[] = "********"; // Enter your WiFi password
int smoke = A0; // Sensor for detecting gas (vehicle emission)
int redLed = D1; // Red LED to indicate emission beyond threshold
int greenLed = D2; // Green LED to indicate safe emission levels
int sensorThres = 360; // Threshold for emission detection
BlynkTimer timer;
void sendSensor() {
int data = analogRead(smoke);
Blynk.virtualWrite(V0, data); // Send data to Blynk app
Serial.print("Pin A0: ");
Serial.println(data);
if (data > sensorThres) { // If the emission exceeds the threshold
digitalWrite(redLed, HIGH); // Turn on the red LED (unsafe emission)
digitalWrite(greenLed, LOW); // Turn off the green LED
Blynk.logEvent("emission_alert", "Vehicle Emission Exceeds Threshold");
} else { // If the emission is below the threshold
digitalWrite(redLed, LOW); // Turn off the red LED
digitalWrite(greenLed, HIGH); // Turn on the green LED (safe emission)
}
}
void setup() {
pinMode(smoke, INPUT); // Smoke sensor
pinMode(redLed, OUTPUT); // Red LED
pinMode(greenLed, OUTPUT); // Green LED
digitalWrite(redLed, LOW); // Ensure red LED is off at startup
digitalWrite(greenLed, HIGH);// Ensure green LED is off at startup
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
timer.setInterval(2500L, sendSensor); // Check sensor every 2.5 seconds
}
void loop() {
Blynk.run();
timer.run();
}