Advertisement
safwan092

Bus People Counter Project using IR sensors

Nov 15th, 2018
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  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 d = 0;
  16. int count = 0;
  17.  
  18. void setup() {
  19.  
  20. pinMode(isObstaclePin, INPUT);
  21. pinMode(isObstaclePin3, INPUT);
  22. pinMode(buzzerPin, OUTPUT);
  23. digitalWrite(buzzerPin,1);
  24. Serial.begin(9600);
  25. Wire.begin();
  26. lcd.begin();
  27. lcd.home();
  28. lcd.setCursor(0, 0);
  29. lcd.print(" Scanning... ");
  30.  
  31. }
  32.  
  33. void loop() {
  34. isObstacle = digitalRead(isObstaclePin);
  35. isObstacle3 = digitalRead(isObstaclePin3);
  36.  
  37. if (isObstacle == LOW)
  38. {
  39. a = 1;
  40.  
  41. }
  42. else if (isObstacle3 == LOW)
  43. {
  44. d = 1;
  45. }
  46.  
  47. calc();
  48.  
  49.  
  50. }
  51.  
  52.  
  53. void calc() {
  54. if (a == 1) {
  55. count = count + 1;
  56. digitalWrite(buzzerPin,1);
  57. a = 0;
  58. Serial.println(count);
  59. lcd.setCursor(0, 0);
  60. lcd.print(" ");
  61. lcd.setCursor(0, 0);
  62. lcd.print(count);
  63. delay(700);
  64. }
  65. else if (d == 1) {
  66. if (count == 2){digitalWrite(buzzerPin,0);}
  67. else{digitalWrite(buzzerPin,1);}
  68. count = count - 1;
  69. d = 0;
  70. Serial.println(count);
  71. lcd.setCursor(0, 0);
  72. lcd.print(" ");
  73. lcd.setCursor(0, 0);
  74. lcd.print(count);
  75. delay(700);
  76.  
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement