Connecting to -esp8266

I refer some of the coding from this website ( and some from (Events, Notifications and the use of "Flag" variables).

In the notification code:

void notification() {
  int sensor = analogRead(Sensor);
  Serial.print("Temperature = ");
  • The analogRead(Sensor) function reads the value from an analog pin (represented by the Sensor variable), and stores it in the sensor variable. The Serial.println(sensor) function prints the value of sensor to the serial monitor.

    sensor = map(sensor, 0, 1024, 0, 100);
  • The map(sensor, 0, 1024, 0, 100) function maps the sensor 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 the sensor 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!");
       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 the Blynk.logEvent() function, sets the alert_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 the sensor value to a virtual pin
    (represented by V1 ).

      } 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 the alert_sent flag to false.