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 theSensorvariable), and stores it in thesensorvariable. TheSerial.println(sensor)function prints the value ofsensorto the serial monitor.sensor = map(sensor, 0, 1024, 0, 100); -
The
map(sensor, 0, 1024, 0, 100)function maps thesensorvalue 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
pinValueis 1. If it is, then it checks if thesensorvalue 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
sensorvalue is greater than 50, then it assumes that a gas leak has been detected, triggers a notification using theBlynk.logEvent()function, sets thealert_sentflag 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 thesensorvalue to a virtual pin
(represented byV1).} else { digitalWrite(Yellow, LOW); digitalWrite(Buzzer, LOW); digitalWrite(Green, LOW); bool alert_sent = false; } -
If the
pinValuevalue is not 1, then the system assumes that the gas concentration level is normal, turns off all LEDs and the buzzer, and resets thealert_sentflag to false.
