#include "Wire.h"
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16, 2);
const int analogInPin = A0;
int redLed = 14;
int blueLed = 13;
const byte PiezoBuzz = 12;
int sensorValue = 0;
void setup()
{
Serial.begin(115200);
Serial.println("Serial OK");
Wire.begin(4, 5);
pinMode(redLed, OUTPUT);
pinMode(blueLed, OUTPUT);
pinMode(PiezoBuzz, OUTPUT);
}
void loop()
{
sensorValue = analogRead(analogInPin);
if (sensorValue >= 300)
{
digitalWrite(blueLed, HIGH);
digitalWrite(redLed, LOW);
tone (PiezoBuzz, 1000);
delay(100);
noTone(PiezoBuzz);
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Alert High gas:");
lcd.setCursor(0, 1);
lcd.print(sensorValue);
}
else
{
digitalWrite(blueLed, LOW);
digitalWrite(redLed, HIGH);
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Gas value:");
lcd.setCursor(0, 1);
lcd.print(sensorValue);
}
Serial.print("sensor = " );
Serial.println(sensorValue);
delay(1000);
}