safwan092

project-bus-in-out-lcd-relay-code-test

Nov 16th, 2020
610
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include  <LiquidCrystal.h>
  2. LiquidCrystal lcd (13, 12, 11, 10, 9, 8);
  3.  
  4. #define in A0
  5. #define out A5
  6. #define relay 2
  7.  
  8. int count = 0;
  9.  
  10. void IN()
  11. {
  12.   count++;
  13.   lcd.clear();
  14.   lcd.print("Person In Bus:");
  15.   lcd.setCursor(0, 1);
  16.   lcd.print(count);
  17.   delay(1000);
  18. }
  19.  
  20. void OUT()
  21. {
  22.   count--;
  23.   lcd.clear();
  24.   lcd.print("Person(s)in Bus:");
  25.   lcd.setCursor(0, 1);
  26.   lcd.print(count);
  27.   delay(1000);
  28. }
  29. void setup()
  30. {
  31.   lcd.begin(16, 2);
  32.   lcd.print("The Smart Station");
  33.   delay(2000);
  34.   pinMode(in, INPUT);
  35.   pinMode(out, INPUT);
  36.   pinMode(relay, OUTPUT);
  37.   lcd.clear();
  38.   lcd.print("Person(s)in Bus:");
  39.   lcd.setCursor(0, 1);
  40.   lcd.print(count);
  41. }
  42.  
  43.  
  44. void loop()
  45. {
  46.  
  47.   if (digitalRead(in))
  48.     IN();
  49.   if (digitalRead(out))
  50.     OUT();
  51.  
  52.   if (count <= 0) {
  53.     lcd.clear();
  54.     digitalWrite(relay, LOW);
  55.     lcd.clear();
  56.     lcd.print("Nobody In Bus");
  57.     lcd.setCursor(0, 1);
  58.     delay(200);
  59.   }
  60.  
  61.   else
  62.     digitalWrite(relay, HIGH);
  63.  
  64. }
RAW Paste Data