กลับไปหน้ารวมไฟล์
automatic-room-light-controller-with-bidirectional-visitor-b63a3c-en.md

Population Math: Bidirectional Visitor Counter

A simple motion sensor (PIR) turns off the lights if you sit too still on the couch. The Bidirectional Visitor Counter solves this by maintaining a strict mathematical tally. The lights only turn off when the Arduino confirms the room population relies at exact zero.

ir_sensor_array_detail_1772704523332.png

The Dual-Sensor Interlock

The system mounts two IR Obstacle Sensors in the door frame, placed 5cm apart (Sensor A on the outside, Sensor B on the inside).

  1. Entering the Room (A -> B):
    • A person breaks Sensor A first. if (A == blocked) { state = Entering; }.
    • Half a second later, they break Sensor B. The Arduino registers a successful sequence and tallies: PeopleCount++.
  2. Exiting the Room (B -> A):
    • A person breaks Sensor B first. if (B == blocked) { state = Exiting; }.
    • Then they break Sensor A. The logic tallies: PeopleCount--.

Controlling Mains Power

  • The Threshold:
    if (PeopleCount > 0) {
      digitalWrite(relayPin, HIGH); // Lights ON
    } else if (PeopleCount == 0) {
      digitalWrite(relayPin, LOW);  // Lights OFF to save power!
    }
    
  • The Physical Relay: The Arduino commands a 5V Songle Relay. Warning: The other side of the relay switches 110V/220V mains electricity to the ceiling lamp. This requires extreme safe wiring practices or the use of an enclosed IoT Power Strip.

Assembly Necessities

  • Arduino Uno/Nano: The logic gate.
  • IR Obstacle Avoidance Sensors (x2) or Laser Diodes + LDRs.
  • 5V Relay Module.
  • A 16x2 LCD (To display the current tally: "People in Room: 3")

ข้อมูล Frontmatter ดั้งเดิม

title: "Automatic Room Light Controller with Bidirectional Visitor"
description: "Count them up! Program a clever logic system using dual laser-tripwires to mathematically count exactly how many people enter and exit a room to control the lights."
category: "Home Automation"
difficulty: "Advanced"