mmWave human presence for under $20?!

Uh, wow:

Immediately out of stock, but presumably not for long. Has anyone played with these? Seems like this plus a simple micro-controller would beat pretty much every home automation presence detection solution on the market today. Any news of pre-made zigbee or zwave devices using similar technology?

6 Likes

I wonder what they mean by this?

Perhaps that it’s not suitable to be powered by a battery for any reasonable amount of time?

Yeah, that’s correct, as noted in the comments down at the bottom on that page. Basically, needs a wired power source.

Has anyone tried ESPhome?

Have anyone tried this one?

I know it’s almost twice the price, but seeing how out of stock they are it might be another good option?

There is sample code for it, so I guess it can be compiled in ESP-Home as c++ code sensor
mmWave Radar Sensor Arduino-Human Presence Detection Wiki - DFRobot

1 Like

Thanks for that! I’ll try to find some reviews about this sensor as I can’t find it in Amazon and returns in Aliexpress aren’t the best for me

@Guinnberg Thought you might be interested in my ESPHome sensor using the DFRobot mmWave. I use it to play a message to remind me to get up if I accidentally sleep in for more than 20 minutes. It works very well.

I have it sitting below my bed and it produces data like this:

Red at 3:25 AM is because I got out of bed.

Things to note:
If you .readPresenceDetection() within loop() it can lock the thread for too long and can cause the ESP32 to drop off the network. By doing it in update() say once or twice a second, it never drops connection.

The rotation of the sensor matters a small amount.

The sensor data is not ideal. It will give random blips once in a while and will turn on and off right after you leave. I process the readings over 25s to get no false positives and almost no false negatives. I think when I roll over onto the edge of the bed every couple weeks I

I used a ESP32-DEVKITC-32D and connected pin TX → 27, RX → 26, G → GND, V → 5V
No other components needed

I added an HTU31D to have temp & humidity as well. SDA → 21 and SCL → 22. Easy to remove from the code. Dangling far away because the ESP was throwing off temperature readings.

Need to add the libaries to your esphome directory:
https://github.com/DFRobotdl/DFRobot_mmWave_Radar
https://github.com/DFRobotdl/DFRobot_mmWave_Radar/archive/refs/heads/master.zip

presence_sensor.h
#include "esphome.h"
#include <HardwareSerial.h>
#include <Wire.h>
#include "DFRobot_mmWave_Radar.h"
#include "Adafruit_HTU31D.h"

using namespace esphome;

static const char *TAG = "PresenceAndMulti";
static const int levels = 25;

HardwareSerial mySerial(1);
DFRobot_mmWave_Radar presenceSensor(&mySerial);
Adafruit_HTU31D htu = Adafruit_HTU31D();

class PresenceAndMultiSensor : public PollingComponent  {
  public:
    Sensor *temperature_sensor = new Sensor();
    Sensor *humidity_sensor = new Sensor();
    Sensor *presence_sensor = new Sensor();

    PresenceAndMultiSensor () : PollingComponent(1000) {}
    

    bool lastLevels[levels] = {0}; //initializes the first to 0 and also all the rest to 0

    bool currentlyInBed = false;
    bool needToPublish = true;

    int ledPin = 2;
    int extLedPin = 32;

    void setup()
    {
        Serial.begin(115200);
        while (!Serial) {
          delay(10); // wait till serial port opens
        }
        Serial.println("Adafruit HTU31D test");

        if (!htu.begin(0x40)) {
          Serial.println("Couldn't find sensor!");
          while (1);
        }

        htu.enableHeater(false);    

        mySerial.begin(115200, SERIAL_8N1, 27, 26);
        //pinMode(ledPin, OUTPUT);
        //pinMode(extLedPin, OUTPUT);

        presenceSensor.factoryReset();    //Restore to the factory settings 
        presenceSensor.DetRangeCfg(0, 5);    //The detection range is as far as 9m
        presenceSensor.OutputLatency(0, 0);
    }

    long long loopIterations = 0;

    long long lastTempReading = 0;

    void loop() override {
      loopIterations++;

      if (millis() - 15000 < lastTempReading) //if it hasn't been 5s, return
        return;


      lastTempReading = millis();

      sensors_event_t humidity, temp;
      htu.getEvent(&humidity, &temp);// populate temp and humidity objects with fresh data

      ESP_LOGI(TAG, "temperature %d, humidity: %d", temp.temperature, humidity.relative_humidity);

      temperature_sensor->publish_state(temp.temperature);
      humidity_sensor->publish_state(humidity.relative_humidity);      
    }

    long long updateIterations = 0;

    void update() override {     
      updateIterations++;

      bool presenceVal = presenceSensor.readPresenceDetection();

      ESP_LOGI(TAG, "presence %d", presenceVal);
      //digitalWrite(extLedPin, presenceVal);
      //digitalWrite(ledPin, presenceVal);

      //loop through and move the values over
      for(int i = 0; i < levels - 1; i++)
      {
        lastLevels[i] = lastLevels[i+1];
      }

      //set the latest level
      lastLevels[levels - 1] = presenceVal;      

      //wait for levels to fill with readings
      if (updateIterations < 5)
      {
        return;
      }

      int numBelow = 0; //turns it on
      int numAbove = 0; //turns it off
      
      for(int i = 0; i < levels; i++)
      {
        if(lastLevels[i] == true) 
        {
          numAbove++;
        }
        
        if(lastLevels[i] == false) 
        {
          numBelow++;
        }
      }

      //ESP_LOGI(TAG, "num above: %d. num below: %d", numAbove, numBelow);      
      
      if (numAbove >= levels - 5 && !currentlyInBed) { // 4/5 have to be above
        currentlyInBed = true;
        needToPublish = true; //state has changed
        ESP_LOGI(TAG, "New State: on");  
      } else if (numBelow >= levels && currentlyInBed) { // all have to be below.
        currentlyInBed = false;
        needToPublish = true; //state has changed
        ESP_LOGI(TAG, "New State: off");  
      }
      

      //ESP_LOGI(TAG, "New State: %s", currentlyInBed ? "on" : "off");      
      
      if (needToPublish) {
        presence_sensor->publish_state(currentlyInBed);
        needToPublish = false;
      }      
    }
};
presence_sensor.yaml
esphome:
  name: presence-sensor
  platform: ESP32
  board: esp32dev
  libraries:
    - adafruit/Adafruit BusIO
    - adafruit/Adafruit Unified Sensor
  includes:
    - presence_sensor.h
    - libraries/DFRobot_mmWave_Radar.h
    - libraries/DFRobot_mmWave_Radar.cpp
    - libraries/Adafruit_HTU31D.h
    - libraries/Adafruit_HTU31D.cpp
    
    
# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: "your password"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  power_save_mode: none

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Presence Sensor"
    password: "your password"

captive_portal:
      
# Example configuration entry
sensor:
  - platform: custom
    lambda: |-
      auto my_sensor = new PresenceAndMultiSensor();
      App.register_component(my_sensor);
      return {my_sensor->temperature_sensor,my_sensor->humidity_sensor,my_sensor->presence_sensor};
  
    sensors:
      - name: "Room Temperature"
        unit_of_measurement: °C
        accuracy_decimals: 2
        state_class: measurement
      - name: "Room Humidity"
        accuracy_decimals: 1
        state_class: measurement
      - name: "Bed Occupied"        
        accuracy_decimals: 0


Excuse the mess. I had to redo this 3 times. The first time I put the sensor upside down.

6 Likes

Aqara have just recently released a consumer level presence detector which employs the same millimeter wave radar. Although, only really available in China right now, or Aliexpress if you’re fast enough and don’t mind paying more than it should cost…

3 Likes

Seems to be out of stock everywhere for the next while. Let us know if you know where to buy it. Expected there would at least be a couple units on ebay for quadruple the price, but no.

SeeedStudio says that they’re expecting the $45 60GHz version to ship around May 20. The cheapest version has no date for backorder, though.

Oh! The $28 “Sleep Radar” said “In Stock” for a second and then went to backorder (May 21).

After seeing the code from @phillip1 I’m not fully sure if they use the same chip…

The Aqara version sensor can detect in which direction someone is moving but this one seems to only have an ON/OFF state

The chip can be the same but the software can be different.

Not sure about it though, but generally software can make a huge difference on the same hardware

Yeah, that could be it.

After reading the wiki if the chip, the mention to Co figure the distance covered in blocks of 15cm as opposed to meters from the api they provide.

They also say the gpio 2 provides different readings when presence is detected, not just 1 or 0 as their api.

Maybe it’s a matter of trying it myself, but I’m quite noob in all this and I’m afraid of spending almost 40€ on something that won’t fully work for me…

I’ll try to spend some time and read their cpp code and see if I get more info there

1 Like

The code I posted was for the other chip you were talking about from DFRobot:
https://wiki.dfrobot.com/mmWave_Radar_Human_Presence_Detection_SKU_SEN0395

https://www.dfrobot.com/product-2282.html

The DFRobot one is indeed only on/off.

That said, the seeed one is serial as well so the wiring would be the same but requires a different library as described on their wiki:

https://wiki.seeedstudio.com/Radar_MR24BSD1/#arduino-library-overview

Hope that helps.

1 Like

I was actually referring to the Aqara FP1 being out of stock everywhere with no end in sight!

I bought two 24GHz Human Static Presence Sensors from Seeed today. It’s a really cool find Matthew.
It will arrive in a few days and I will try to ESPHome-them when I have some time. I’m really hoping that the data they produce is good.

2 Likes

It’s pretty hard to get FP1 if it keeps selling out too fast

I just checked the seeed static sensor and even that one’s still out of stock

Meanwhile I’m trying this one by tuya
Should arrive by this week

Moes Tuya Smart ZigBee Human Presence Detector Radar Detection Sensor Photometric 2 in 1 Function Smart Life Ceiling PIR Hub

I haven’t seen any reviews anywhere else on this one, so we’ll see if it performs as advertised

2 Likes

Looking forward for your review on this tuya sensor

What’s the main difference between static and sleep breathing?

Looking forward to seeing your review about it!