Room presence sensor that sees people sitting still
Build it step by step
0 of 7 doneTest the radar
Print presence and distances to serial.
Wire the relay
Switch a small load.
Add the logic
On when present, off after 2 minutes.
Add the display
Show moving and still distances.
Tune the range
Set the gates for your room's size.
Mount it
Facing the room, away from fans and curtains.
Test sitting still
Check it holds the load on.
How do you build a room presence sensor that sees people sitting still?
An LD2410 24 GHz radar notices someone sitting still or sleeping, unlike a PIR, and keeps the lights or AC on only while the room is used. You need ESP32 DevKit V1, LD2410 24 GHz human presence radar, Relay Module 5V and SSD1306 OLED Display. It takes 7 steps and about 120 minutes.
- Level
- Intermediate
- Time
- About 120 min
- Parts
- 4
Parts list
- Development BoardsBuyESP32 DevKit V1 × 1
- SensorsBuy
- InterfacesBuyRelay Module 5V × 1
- DisplaysBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| LD2410 VCC and GND | ESP32 5V (VIN) and GND | Power |
| LD2410 TX | ESP32 GPIO16 (UART2 RX) | Data from the radar |
| LD2410 RX | ESP32 GPIO17 (UART2 TX) | Commands to the radar |
| Relay module VCC and GND | ESP32 5V and GND | Power |
| Relay IN | ESP32 GPIO26 | Switch signal |
| Relay COM and NO | A low-voltage load such as a 12 V fan or LED strip | Switched load |
| OLED SDA and SCL | ESP32 GPIO21 and GPIO22 | Display |
Code
A PIR only sees movement, so it turns lights off on someone reading or sleeping. The LD2410 is a 24 GHz radar that also detects the tiny motion of breathing, so it reports both moving and stationary targets with their distance. The sketch keeps the relay on while anyone is present and turns it off two minutes after the room is empty. It runs at 256000 baud on its own UART. Tune the range and sensitivity in the module's app (HLKRadarTool) or through the library, because radar goes through thin walls and may see people in the next room, and moving curtains and fans can cause false triggers. The relay here switches only a low-voltage load. A mains light or air conditioner must be wired by a qualified electrician, with an approved relay unit in an enclosure and the right fuse. Keep the sensor's view clear and mount it where it faces the room rather than a wall or door. It senses presence only, with no camera or sound. Arduino IDE with the ESP32 boards package 2.0.x, board "ESP32 Dev Module".
Runs on a virtual ESP32 Dev Module 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).
// Presence sensor with the LD2410. Libraries: ld2410 (by ncmreynolds), Adafruit SSD1306, Adafruit GFX. Board: ESP32 Dev Module.
#include <Wire.h>
#include <ld2410.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
ld2410 radar;
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
const int RELAY = 26;
const unsigned long OFF_DELAY = 120000; // off after 2 minutes without anyone
unsigned long lastPresent = 0; bool on = false;
void setup() {
pinMode(RELAY, OUTPUT); digitalWrite(RELAY, HIGH); // most relay boards are active LOW, HIGH = off
Serial.begin(115200);
Serial2.begin(256000, SERIAL_8N1, 16, 17);
radar.begin(Serial2);
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C); oled.setTextColor(SSD1306_WHITE);
}
void loop() {
radar.read();
bool present = radar.presenceDetected();
if (present) lastPresent = millis();
if (present && !on) { on = true; digitalWrite(RELAY, LOW); }
if (on && millis() - lastPresent > OFF_DELAY) { on = false; digitalWrite(RELAY, HIGH); }
static unsigned long last = 0;
if (millis() - last > 500) {
last = millis();
oled.clearDisplay(); oled.setTextSize(1); oled.setCursor(0, 0);
oled.print(present ? "Someone is here" : "Room empty");
if (radar.movingTargetDetected()) { oled.setCursor(0, 16); oled.print("Moving "); oled.print(radar.movingTargetDistance()); oled.print(" cm"); }
if (radar.stationaryTargetDetected()) { oled.setCursor(0, 28); oled.print("Still "); oled.print(radar.stationaryTargetDistance()); oled.print(" cm"); }
oled.setCursor(0, 48); oled.print(on ? "Load ON" : "Load OFF");
oled.display();
}
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Walk in | Load switches on |
| Sit reading for a few minutes | Load stays on |
| Leave | Load turns off after 2 minutes |
| A pet or a fan | May trigger, adjust sensitivity |
If it does not work
Never detects
Check TX and RX are crossed and the baud rate is 256000.
Detects through walls
Reduce the maximum range gate.
False triggers
Lower the gate sensitivity and move the sensor.
Relay logic reversed
Swap HIGH and LOW for your board.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the room presence sensor that sees people sitting still?
ESP32 DevKit V1, LD2410 24 GHz human presence radar, Relay Module 5V and SSD1306 OLED Display.
How long does the room presence sensor that sees people sitting still take to build?
About 120 minutes for a intermediate maker, in 7 steps.
How do I know the room presence sensor that sees people sitting still works?
Walk in: Load switches on. Sit reading for a few minutes: Load stays on. Leave: Load turns off after 2 minutes.
Never detects: what should I check?
Check TX and RX are crossed and the baud rate is 256000.
Detects through walls: what should I check?
Reduce the maximum range gate.
False triggers: what should I check?
Lower the gate sensitivity and move the sensor.
Relay logic reversed: what should I check?
Swap HIGH and LOW for your board.
