Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // IR Obstacle Collision Detection Module - Henry's Bench
- // Bus People Counter - Dawaerstore.com
- #include <LiquidCrystal_I2C.h>
- #include <Wire.h>
- LiquidCrystal_I2C lcd(0x3F, 20, 4);
- int buzzerPin = 9;
- int isObstaclePin = 2;
- int isObstaclePin3 = 5;
- int isObstacle = HIGH;
- int isObstacle3 = HIGH;
- int a = 0;
- int b = 0;
- int c = 0;
- int d = 0;
- int count = 0;
- void setup() {
- pinMode(isObstaclePin, INPUT);
- pinMode(isObstaclePin3, INPUT);
- pinMode(buzzerPin, OUTPUT);
- digitalWrite(buzzerPin, 1);
- Serial.begin(9600);
- Wire.begin();
- lcd.begin();
- lcd.home();
- lcd.setCursor(0, 0);
- lcd.print(" Scanning... ");
- }
- void loop() {
- isObstacle = digitalRead(isObstaclePin);
- isObstacle3 = digitalRead(isObstaclePin3);
- if (isObstacle == HIGH && isObstacle3 == LOW && a == 0)
- {
- a = 1;
- }
- else if (isObstacle == LOW && isObstacle3 == HIGH && a == 1)
- {
- b = 1;
- }
- else if (isObstacle == LOW && isObstacle3 == HIGH && a == 0)
- {
- c = 1;
- }
- else if (isObstacle == HIGH && isObstacle3 == LOW && c == 1)
- {
- d = 1;
- }
- calc();
- }
- void calc() {
- if (b == 1) {
- lcd.setCursor(0, 0);
- lcd.print(" Count is: ");
- count = count + 1;
- digitalWrite(buzzerPin, 1);
- a = 0;
- b = 0;
- c = 0;
- d = 0;
- Serial.println(count);
- lcd.setCursor(0, 1);
- lcd.print(" ");
- lcd.setCursor(1, 1);
- lcd.print(count);
- delay(700);
- }
- else if (d == 1) {
- lcd.setCursor(0, 0);
- lcd.print(" Count is: ");
- if (count == 2) {
- digitalWrite(buzzerPin, 0);
- }
- else {
- digitalWrite(buzzerPin, 1);
- }
- count = count - 1;
- if (count < 0) {
- count = 0;
- }
- a = 0;
- b = 0;
- c = 0;
- d = 0;
- Serial.println(count);
- lcd.setCursor(0, 1);
- lcd.print(" ");
- lcd.setCursor(1, 1);
- lcd.print(count);
- delay(700);
- }
- }
Add Comment
Please, Sign In to add comment