Infrared door sensor

An IR sensor on the door measures distance again and again. Each reading travels to a microprocessor, which decides whether to open or close the door.

Theory Beginner Sensors · Control ~6 min
The idea

Sense → decide → act

The infrared sensor does not open the door by itself. It only measures how far away a person is. That number is sent continually to a microprocessor.

The microprocessor compares each new reading with a threshold of 1.0 metre. Within range → send an open signal. Farther away → keep the door closed (or close it).

TipThis is a classic sense–decide–act control loop: input from the world, a rule, then an output to an actuator.
IdeaControl loop
door_control.pyPython
THRESHOLD = 1.0
while True:
    distance = ir_sensor.read()
    if distance <= THRESHOLD:
        door.open()
    else:
        door.close()

Watch packets labelled with metres fly from the sensor to the chip.

Interactive

Run the simulation

Watch the person approach, then follow the icons: sensor → microprocessor → motor. Blue packets carry distance; green/red packets carry the door command.

Step 0 / 0
demo.pyPython
Scene · sensor → MCU → motordemo
Ready
Shortcuts: Space play/pause · → step · ← back · R reset
Remember

What this system teaches

Continuous sensing, a simple rule, and an actuator.

Sensor

Data keeps flowing

The IR sensor samples distance in a loop. Each value is a message to the microprocessor — not a one-off event.

Decide

Compare to a threshold

The chip asks: is distance ≤ 1.0? That boolean choice picks the next action.

Act

Signal the door

Only after the decision does the microprocessor send open or close to the door mechanism.