দুমুখো ভিজিটর কাউন্টার (LCD তে ঢোকা-বের হওয়া)Bidirectional Visitor Counter using Arduino
দরজার দুই পাশে দুইটা IR beam; ঢুকলে আগে A তারপর B ভাঙে, বেরোলে আগে B তারপর A। ছোট্ট একটা state machine পার্থক্য ধরে — তাই LCD তে সবসময় ভেতরে কতজন আছে তা-ই দেখায়, দোকানের occupancy counter-এর ক্লাসিক সংস্করণ।
Two IR beams across the doorway; whoever walks in breaks A then B, whoever leaves breaks B then A. A four-state machine tells the difference, so the LCD always shows how many people are actually inside — the classic shop-occupancy counter.
সার্কিট ডায়াগ্রাম · Circuit diagram
যা যা লাগবে · Parts you need
- 1 × Arduino Uno Arduino Uno
- 2 × IR obstacle sensor (FC-51) IR বাধা সেন্সর (FC-51)
- 1 × LCD 16x2 with I2C LCD ১৬x২ (I2C)
- 10 × Jumper wires জাম্পার তার
তার লাগানো · Wiring
| IR obstacle sensor (FC-51) VCC | → | Arduino Uno 5V |
| IR obstacle sensor (FC-51) GND | → | Arduino Uno GND |
| IR obstacle sensor (FC-51) OUT | → | Arduino Uno D2 |
| IR obstacle sensor (FC-51) VCC | → | Arduino Uno 5V |
| IR obstacle sensor (FC-51) GND | → | Arduino Uno GND |
| IR obstacle sensor (FC-51) OUT | → | Arduino Uno D3 |
| LCD 16x2 with I2C VCC | → | Arduino Uno 5V |
| LCD 16x2 with I2C GND | → | Arduino Uno GND |
| LCD 16x2 with I2C SDA | → | Arduino Uno A4 |
| LCD 16x2 with I2C SCL | → | Arduino Uno A5 |
Code (Arduino C++)
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Bidirectional visitor counter: two IR beams across the doorway.
// beam A breaks first, then B -> someone walked IN (+1)
// beam B breaks first, then A -> someone walked OUT (-1)
// The little state machine remembers which beam broke first, so walking through
// in either direction counts once — and only once.
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int beamA = 2, beamB = 3;
int inside = 0;
int state = 0; // 0 idle · 1 past A · 2 past A then B · 3 past B · 4 past B then A
void show() {
lcd.setCursor(0, 0); lcd.print("Inside: "); lcd.print(inside); lcd.print(" ");
Serial.print("Inside: "); Serial.println(inside);
}
void setup() {
pinMode(beamA, INPUT); pinMode(beamB, INPUT);
lcd.init();
lcd.backlight();
Serial.begin(9600);
}
void loop() {
bool a = digitalRead(beamA) == LOW; // LOW = this beam is interrupted (someone in it)
bool b = digitalRead(beamB) == LOW;
switch (state) {
case 0: if (a && !b) state = 1; else if (b && !a) state = 3; break;
case 1: if (b) state = 2; else if (!a) state = 0; break;
case 2: if (!a && !b) { inside++; show(); state = 0; } break;
case 3: if (a) state = 4; else if (!b) state = 0; break;
case 4: if (!a && !b) { if (inside > 0) inside--; show(); state = 0; } break;
}
delay(30);
}
আরো project · More projects
- ক্ল্যাপ সুইচ: হাততালি দিলেই বাতি অন-অফClap switch: one clap toggles the lamp
- MOSFET দিয়ে DC মোটরের গতি নিয়ন্ত্রণ (PWM)DC motor speed control with a MOSFET (PWM)
- স্মার্ট পার্কিং: কোন স্লট খালি তার হিসাবSmart parking: free-slot counter per floor
- পড়ে যাওয়া ধরার এলার্ম (MPU6050)Elderly fall detection (MPU6050 freefall alarm)