JHJiban

Gas Leakage Detections

Dec 3rd, 2020
174
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <LiquidCrystal.h>
  2. LiquidCrystal lcd(5,6,8,9,10,11);
  3.  
  4. int redled = 2;
  5. int greenled = 3;
  6. int buzzer = 4;
  7. int sensor = A0;
  8. int sensorThresh = 400;
  9.  
  10. void setup()
  11. {
  12. pinMode(redled, OUTPUT);
  13. pinMode(greenled,OUTPUT);
  14. pinMode(buzzer,OUTPUT);
  15. pinMode(sensor,INPUT);
  16. Serial.begin(9600);
  17. lcd.begin(16,2);
  18. }
  19.  
  20. void loop()
  21. {
  22.   int analogValue = analogRead(sensor);
  23.   Serial.print(analogValue);
  24.   if(analogValue>sensorThresh)
  25.   {
  26.     digitalWrite(redled,HIGH);
  27.     digitalWrite(greenled,LOW);
  28.     tone(buzzer,1000,10000);
  29.     lcd.clear();
  30.     lcd.setCursor(0,1);
  31.     lcd.print("Gas Leakage!");
  32.     delay(1000);
  33.     lcd.clear();
  34.     lcd.setCursor(0,1);
  35.     lcd.print("Evacuate ASAP!");
  36.     delay(1000);
  37.   }
  38.   else
  39.   {
  40.     digitalWrite(greenled,HIGH);
  41.     digitalWrite(redled,LOW);
  42.     noTone(buzzer);
  43.     lcd.clear();
  44.     lcd.setCursor(0,0);
  45.     lcd.print("Safe.");
  46.     delay(1000);
  47.     lcd.clear();
  48.     lcd.setCursor(0,1);
  49.     lcd.print("Everything Ok.");
  50.     delay(1000);
  51.   }  
  52.      
  53. }
RAW Paste Data