Build it step by step
0 of 7 doneWire the PIR
VCC to 5V, GND to GND, OUT to D2.
Wire the lights
Red through 220 ohms to D5, green through 220 ohms to D6, short legs to GND.
Turn the PIR hold adjuster
To the shortest setting.
Upload the sketch
The green light blinks for a minute while the PIR settles.
Wave a hand
The red light comes on.
Keep still
It stays red for five minutes, or ten seconds in test mode.
Wait
It goes green.
How do you build a room occupied door sign?
A PIR sensor above a door switches a red occupied light and a green free light, holding the red light for several minutes after the last movement so a person sitting still is not shown as absent. You need Arduino Nano, PIR Motion Sensor HC-SR501, LED 5 mm red, LED 5 mm green, Resistor 220 Ω × 2, Jumper wires male to male (40 pcs, 20 cm) and Breadboard 830 Tie Points. It takes 7 steps and about 100 minutes.
- Level
- Beginner
- Time
- About 100 min
- Parts
- 7
Parts list
- Development BoardsBuyArduino Nano × 1
- SensorsBuy
- SemiconductorsBuyLED 5 mm red × 1
- SemiconductorsBuyLED 5 mm green × 1
- PassivesBuyResistor 220 Ω × 2
- PrototypingBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| PIR VCC | Nano 5V | Power at 5 V |
| PIR GND | Nano GND | Common ground |
| PIR OUT | Nano D2 | High when it sees movement |
| Red LED long leg | 220 ohm resistor to Nano D5 | Occupied light |
| Red LED short leg | Nano GND | Return |
| Green LED long leg | 220 ohm resistor to Nano D6 | Free light |
| Green LED short leg | Nano GND | Return |
Code
A PIR sensor reacts to the change in heat radiation when a warm body moves, and sets its output high. Someone reading or sitting at a desk moves very little, so the sensor alone would say the room is empty after a few seconds. The program fixes this by remembering the time of the last movement and keeping the red light on for five minutes afterwards, and the green light shows only when nothing has moved for the whole of that time. The module needs about a minute to settle after power-up, so the green light blinks while the program waits. The module also has two small adjusters, one for its own hold time and one for sensitivity; turn the hold time to the shortest so the program has control and set the sensitivity to suit the room. Put it where it sees the seat and not the door, and away from heaters and sunshine. This is a courtesy sign. It is not a security device and not a safety device, because it can be fooled, and it must not be used to decide whether it is safe to enter anywhere. It records nothing about anyone.
Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
const int PIR = 2;
const int RED = 5;
const int GREEN = 6;
const unsigned long HOLD_MS = 5UL * 60UL * 1000UL; // stay red for 5 minutes after the last movement
// For a quick test, change HOLD_MS to 10000 (ten seconds), then change it back.
unsigned long lastMotion = 0;
bool everSeen = false;
void setup() {
pinMode(PIR, INPUT);
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
// The sensor needs about a minute to settle: blink green while it does
for (int i = 0; i < 60; i++) {
digitalWrite(GREEN, i % 2);
delay(1000);
}
}
void loop() {
if (digitalRead(PIR) == HIGH) {
lastMotion = millis();
everSeen = true;
}
bool occupied = everSeen && (millis() - lastMotion < HOLD_MS);
digitalWrite(RED, occupied);
digitalWrite(GREEN, !occupied);
delay(100);
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Power on | Green blinks for about a minute |
| Move in front of it | Red on, green off |
| Sit still for a minute | Stays red |
| Wait for the hold time | Green on, red off |
| Move again | Red again at once |
If it does not work
Always red
Turn down the sensitivity and keep the sensor away from heaters.
Never red
Check PIR OUT on D2 and 5 V on the PIR.
Goes green while someone sits still
Make the hold time longer in the program.
LED never lights
Check the leg direction and the resistors.
Flickers at start
It is still settling, wait a minute.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the room occupied door sign?
Arduino Nano, PIR Motion Sensor HC-SR501, LED 5 mm red, LED 5 mm green, Resistor 220 Ω × 2, Jumper wires male to male (40 pcs, 20 cm) and Breadboard 830 Tie Points.
How long does the room occupied door sign take to build?
About 100 minutes for a beginner maker, in 7 steps.
How do I know the room occupied door sign works?
Power on: Green blinks for about a minute. Move in front of it: Red on, green off. Sit still for a minute: Stays red.
Always red: what should I check?
Turn down the sensitivity and keep the sensor away from heaters.
Never red: what should I check?
Check PIR OUT on D2 and 5 V on the PIR.
Goes green while someone sits still: what should I check?
Make the hold time longer in the program.
LED never lights: what should I check?
Check the leg direction and the resistors.
