I refer some of the coding from this website (https://srituhobby.com/iot-based-gas-leakage-monitoring-system/) and some from (Events, Notifications and the use of "Flag" variables).
In the notification code:
void notification() {
int sensor = analogRead(Sensor);
Serial.print("Temperature = ");
Serial.println(sensor);
-
The
analogRead(Sensor)
function reads the value from an analog pin (represented by theSensor
variable), and stores it in thesensor
variable. TheSerial.println(sensor)
function prints the value ofsensor
to the serial monitor.sensor = map(sensor, 0, 1024, 0, 100);
-
The
map(sensor, 0, 1024, 0, 100)
function maps thesensor
value from the range of 0-1024 to the range of 0-100. This is done to make the reading more human-readable and understandable.if (pinValue == 1) { if (sensor <= 50) { digitalWrite(Yellow, HIGH); digitalWrite(Green, LOW); digitalWrite(Buzzer, LOW);
-
The code then checks if the value of
pinValue
is 1. If it is, then it checks if thesensor
value is less than or equal to 50. If it is, then the system assumes that the gas concentration level is normal and turns on the yellow LED and turns off the green LED and the buzzer.
} else if (sensor > 50) {
Blynk.logEvent("gas_leak_detected", String("The gas concentration value is ") + sensor);
bool alert_sent = true;
Serial.println("Blynk Alert Notification sent!");
Serial.println();
digitalWrite(Yellow, LOW);
digitalWrite(Green, HIGH);
digitalWrite(Buzzer, HIGH);
}
-
If the
sensor
value is greater than 50, then it assumes that a gas leak has been detected, triggers a notification using theBlynk.logEvent()
function, sets thealert_sent
flag to true, and turns on the green LED and the buzzer while turning off the yellow LED.Blynk.virtualWrite(V1, sensor);
-
The
Blynk.virtualWrite(V1, sensor)
function writes thesensor
value to a virtual pin
(represented byV1
).} else { digitalWrite(Yellow, LOW); digitalWrite(Buzzer, LOW); digitalWrite(Green, LOW); bool alert_sent = false; }
-
If the
pinValue
value is not 1, then the system assumes that the gas concentration level is normal, turns off all LEDs and the buzzer, and resets thealert_sent
flag to false.