The Office Presence Detector is a smart device designed to monitor occupancy in an office space using the LD2410 radar sensor and an ESP32 microcontroller. This device connects to a Wi-Fi network, publishes sensor data to an MQTT server, and integrates with Home Assistant for real-time occupancy monitoring. The system can detect presence based on moving and stationary energy thresholds, providing detailed distance and energy readings for both moving and stationary targets.
- Wi-Fi Connectivity: Connects to a Wi-Fi network to communicate with an MQTT server.
- MQTT Integration: Publishes sensor data to an MQTT server for integration with smart home systems like Home Assistant.
- LD2410 Radar Sensor: Utilizes the LD2410 radar sensor to detect presence and measure distance and energy of moving and stationary targets.
- Auto Discovery for Home Assistant: Automatically publishes configuration data for Home Assistant, allowing seamless integration and easy setup.
- LED Indicator: Built-in LED for visual status indication.
- Customizable Thresholds: Allows customization of thresholds for still and moving energy to determine presence.
- ESP32 Development Board
- LD2410 Radar Sensor
- LED (built-in on most ESP32 boards)
- Breadboard and Jumper Wires (for prototyping)
- Wi-Fi Network with internet access
- MQTT Server (e.g., Mosquitto)
- Arduino IDE
- ArduinoJson library
- MQTT library
- ld2410 library (specific to the radar sensor)
ESP32 Pin | Function |
---|---|
32 | RADAR_RX_PIN |
33 | RADAR_TX_PIN |
2 | LED_BUILTIN |
- Connect the LD2410 radar sensor to the ESP32:
- Connect the RX pin of the radar sensor to GPIO 33 of the ESP32.
- Connect the TX pin of the radar sensor to GPIO 32 of the ESP32.
- Connect the power and ground pins of the radar sensor to the 3.3V and GND pins of the ESP32 respectively.
Note that you will likely need to change the sensitivity threasholds in the radar to get it to function well in your envronment. Future plans are to have that configurable via MQTT
- Install the Arduino IDE from arduino.cc.
- Open the Arduino IDE and install the necessary libraries:
- Go to
Sketch
>Include Library
>Manage Libraries...
. - Search for and install the following libraries:
- ArduinoJson
- MQTT
- ld2410 (or the library specific to your radar sensor)
- Go to
- Open a new sketch in the Arduino IDE and copy the provided code into the sketch.
-
Update the Wi-Fi and MQTT configuration variables in the code with your network credentials and MQTT server details:
constexpr char ssid[] = "Your_SSID"; constexpr char password[] = "Your_PASSWORD"; constexpr char mqtt_server[] = "Your_MQTT_Server_IP";
- Connect your ESP32 to your computer using a USB cable.
- Select the correct board and port in the Arduino IDE:
- Go to
Tools
>Board
and selectESP32 Dev Module
. - Go to
Tools
>Port
and select the appropriate port.
- Go to
- Click the
Upload
button to upload the code to your ESP32.
- Open the Serial Monitor in the Arduino IDE (
Tools
>Serial Monitor
). - Set the baud rate to
19200
. - Observe the output to ensure the device is connecting to Wi-Fi and the MQTT server correctly.
- Ensure your MQTT server is running and accessible.
- Autodiscovery should work and it will show up as a device/entity in HA.
- For debugging I reccomend MQTT Explorer app.