ঘনত্ব অনুযায়ী ট্রাফিক সিগন্যাল (কার অনুযায়ী সবুজ)Density-Based Traffic Light with Arduino
নির্দিষ্ট সময়ের সিগন্যাল সবার সময় নষ্ট করে। এখানে দুইটা IR sensor পাশের রাস্তায় অপেক্ষমাণ গাড়ি গুনে, লাইন যত লম্বা সবুজ বাতি ততক্ষণ — খালি রাস্তায় অল্প, লম্বা লাইনে বেশি। পরে একই লুপে RTC যোগ করলে rush hour বোঝে, ESP32 দিলে দূর থেকে নিয়ন্ত্রণ।
Fixed-timing signals waste minutes. Here two IR sensors count the cars waiting on the side road, and the green time grows with the queue — empty road, short green; long queue, long green. The same loop later takes an RTC for rush hours or an ESP32 for remote control.
সার্কিট ডায়াগ্রাম · Circuit diagram
যা যা লাগবে · Parts you need
- 1 × Arduino Uno Arduino Uno
- 2 × IR obstacle sensor (FC-51) IR বাধা সেন্সর (FC-51)
- 1 × Traffic light module ট্রাফিক লাইট মডিউল
- 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 |
| Traffic light module R | → | Arduino Uno D11 |
| Traffic light module Y | → | Arduino Uno D12 |
| Traffic light module G | → | Arduino Uno D13 |
| Traffic light module GND | → | Arduino Uno GND |
Code (Arduino C++)
// Density-based traffic signal: two IR sensors count the cars waiting on the
// side road. An empty road gets a short green; a long queue gets a long one.
// Fixed timers waste everyone's time — this is the idea behind "smart traffic"
// pilot projects, and the same loop is where you would later add an RTC for
// rush-hour schedules or an ESP32 for remote override.
const int queueA = 2, queueB = 3;
const int rPin = 11, yPin = 12, gPin = 13;
void setup() {
pinMode(queueA, INPUT); pinMode(queueB, INPUT);
pinMode(rPin, OUTPUT); pinMode(yPin, OUTPUT); pinMode(gPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
int queue = (digitalRead(queueA) == LOW) + (digitalRead(queueB) == LOW); // LOW = a car waits under the sensor
int greenMs = 1500 + queue * 1000; // try it: block the sensors, green lasts longer
digitalWrite(gPin, HIGH);
Serial.print("green "); Serial.print(greenMs); Serial.println(" ms");
delay(greenMs);
digitalWrite(gPin, LOW);
digitalWrite(yPin, HIGH); delay(400); digitalWrite(yPin, LOW);
digitalWrite(rPin, HIGH); delay(1200); digitalWrite(rPin, LOW);
}