LD2410 Presence sensor with MQTT

Finally finished my office presence sensor project. Sharing here if anyone finds it useful. Code isn’t as clean as I would like but nothing ever is. Feel free to ask questions if you are interested. GitHub - mitchell-johnson/mqtt-presence-sensor: an Arduino implementation of a ld2410 presence sensor with MQTT integration.

One thing that is still not working for me although it should be afaik is the entities are still not showing up as a single device. it’s not a problem for me but annoying.

How is this LD2410C sensor working for you? No false positives? Using the LD2410 on a ESP-8266 mini with esphome and getting loads of false positive.

once I updated the sensitivity I have 0 false positives. I have my sensitivity settings in the repo.

Gate Moving Targets Stationary Targets
0 50 50
1 40 40
2 40 40
3 40 40
4 40 40
5 90 90
6 100 100
7 100 100
8 100 100

obviously it depends on your use case

I tried to compiled with a esp8266 d1 mini with a LD2410 since I only have those on hand atm, but getting a compiling error. Something about the wifi if I remembered correctly.

I have ordered a esp32 S2 mini and LD2410C. Will be arriving in about a month. The lego case is neat. How is the esp32 secure inside of it? Is it just butt up against the lego blocks???

I have a d1 handy and could try it out. From memory you need to swap the wifi lib for
#include <ESP8266WiFi.h>

It’s hot glued into the lego.

I’ve changed to #include <ESP8266WiFi.h> and encountered another error about serial.

I tried compiling on the D1 and see the same errors you do. given you have the S2 coming I won’t try make it work but for future people it should be possible to make work with the d1 with some config changes.

hey. I am still waiting on my parts. Just wondering if you will be expanding this code? Like adding other sensors? Particularly AHT11 or bme280 sensor??

Not planning to at this stage. I do have a few SHT30’s that im planning to use but was just going to add that to a new codebase as they are going to be different devices. Im willing to help you build that out if you wanted to give the code a shot first. ChatGPT should get you pretty far with my code as a baseline.

Hello. I receiving compiling errors. I have tried selecting these 2 boards in Arduino.

ESP32 Dev Module

C:\Users\Duc\Documents\Iot\Arduino\MR-LD2410-mqtt\MR-LD2410-mqtt.ino: In function 'void connectMqtt()':
MR-LD2410-mqtt:52:18: error: 'LED_BUILTIN' was not declared in this scope
     digitalWrite(LED_BUILTIN, LOW);
                  ^~~~~~~~~~~
C:\Users\Duc\Documents\Iot\Arduino\MR-LD2410-mqtt\MR-LD2410-mqtt.ino: In function 'void loop()':
MR-LD2410-mqtt:489:1: error: expected '}' at end of input
 }
 ^
C:\Users\Duc\Documents\Iot\Arduino\MR-LD2410-mqtt\MR-LD2410-mqtt.ino:242:1: note: to match this '{'
 {
 ^
Multiple libraries were found for "WiFi.h"
 Used: C:\Users\Duc\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.17\libraries\WiFi
 Not used: C:\Program Files (x86)\Arduino\libraries\WiFi
exit status 1
'LED_BUILTIN' was not declared in this scope

ESP32 Dev Module

C:\Users\Duc\Documents\Iot\Arduino\MR-LD2410-mqtt\MR-LD2410-mqtt.ino: In function 'void loop()':
MR-LD2410-mqtt:489:1: error: expected '}' at end of input
 }
 ^
C:\Users\Duc\Documents\Iot\Arduino\MR-LD2410-mqtt\MR-LD2410-mqtt.ino:242:1: note: to match this '{'
 {
 ^
Multiple libraries were found for "WiFi.h"
 Used: C:\Users\Duc\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.17\libraries\WiFi
 Not used: C:\Program Files (x86)\Arduino\libraries\WiFi
exit status 1
expected '}' at end of input

I am not sure if this is correct, but I have suppressed the errors by adding

#define LED_BUILTIN 15

and adding a closing } at the end of the code.

So I tried to upload the code. The log shows it is writing and when it finished, it errors out with this. I don’t see the device in my wifi network. I guess it didn’t upload successfully.

Leaving...
WARNING: ESP32-S2FNR2 (revision v1.0) chip was placed into download mode using GPIO0.
esptool.py can not exit the download mode over USB. To run the app, reset the chip manually.
To suppress this note, set --after option to 'no_reset'.
An error occurred while uploading the sketch

Sorry you had issues with the code. I’ll update it on GitHub. I have never seen that issue before with the S2 although one of mine did have issues being recognised and I had to reset it with a tool. Although I forgot exactly how I did that sorry.