safwan092

Bus Project New Code #3

Apr 13th, 2020
118
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // IR Obstacle Collision Detection Module - Henry's Bench
  2. // Bus People Counter - Dawaerstore.com
  3. #include <LiquidCrystal_I2C.h>
  4. #include <Wire.h>
  5. LiquidCrystal_I2C lcd(0x3F, 20, 4);
  6.  
  7. int buzzerPin = 9;
  8. int isObstaclePin = 2;
  9. int isObstaclePin3 = 5;
  10.  
  11. int isObstacle = HIGH;
  12. int isObstacle3 = HIGH;
  13.  
  14. int a = 0;
  15. int b = 0;
  16. int c = 0;
  17. int d = 0;
  18.  
  19. int in = 0;
  20. int out = 0;
  21.  
  22. int count = 0;
  23.  
  24. void setup() {
  25.  
  26.   pinMode(isObstaclePin, INPUT);
  27.   pinMode(isObstaclePin3, INPUT);
  28.   pinMode(buzzerPin, OUTPUT);
  29.   digitalWrite(buzzerPin, 1);
  30.   Serial.begin(9600);
  31.   Wire.begin();
  32.   lcd.begin();
  33.   lcd.home();
  34.   lcd.setCursor(0, 0);
  35.   lcd.print(" Scanning...    ");
  36.  
  37. }
  38.  
  39. void loop() {
  40.  
  41.   isObstacle = digitalRead(isObstaclePin);
  42.   isObstacle3 = digitalRead(isObstaclePin3);
  43.  
  44.   if (isObstacle == HIGH && isObstacle3 == LOW && a == 0 && b == 0) {
  45.     a = 1;
  46.   }
  47.   else if (isObstacle == LOW && isObstacle3 == HIGH && a == 0 && b == 0) {
  48.     b = 1
  49.   }
  50.  
  51.  
  52.   calc();
  53.  
  54.  
  55. }
  56.  
  57.  
  58.  
  59.  
  60.  
  61. void calc() {
  62.   if (a == 1) {
  63.     lcd.setCursor(0, 0);
  64.     lcd.print(" Count is:    ");
  65.     count = count + 1;
  66.     digitalWrite(buzzerPin, 1);
  67.     a = 0;
  68.     b = 0;
  69.     c = 0;
  70.     d = 0;
  71.     in = 0;
  72.     Serial.println(count);
  73.     lcd.setCursor(0, 1);
  74.     lcd.print("                ");
  75.     lcd.setCursor(1, 1);
  76.     lcd.print(count);
  77.     delay(700);
  78.   }
  79.   else if (b == 1) {
  80.     lcd.setCursor(0, 0);
  81.     lcd.print(" Count is:    ");
  82.     if (count == 2) {
  83.       digitalWrite(buzzerPin, 0);
  84.     }
  85.     else {
  86.       digitalWrite(buzzerPin, 1);
  87.     }
  88.     count = count - 1;
  89.     if (count < 0) {
  90.       count = 0;
  91.     }
  92.     a = 0;
  93.     b = 0;
  94.     c = 0;
  95.     d = 0;
  96.     out = 0;
  97.     Serial.println(count);
  98.     lcd.setCursor(0, 1);
  99.     lcd.print("                ");
  100.     lcd.setCursor(1, 1);
  101.     lcd.print(count);
  102.     delay(700);
  103.  
  104.   }
  105. }
  106.  
  107.  
  108.  
  109. /*
  110.  
  111.   if (isObstacle == HIGH && isObstacle3 == LOW && a == 0)
  112.   {
  113.     a = 1;
  114.   }
  115.   else if (isObstacle == LOW && isObstacle3 == HIGH && a == 1)
  116.   {
  117.     b = 1;
  118.   }
  119.   else if (isObstacle == LOW && isObstacle3 == HIGH && a == 0)
  120.   {
  121.     c = 1;
  122.   }
  123.   else if (isObstacle == HIGH && isObstacle3 == LOW && c == 1)
  124.   {
  125.     d = 1;
  126.   }
  127.  
  128. */
RAW Paste Data