Waking up the ESP32-C3 from deep sleep

How can I configure the ESP32-C3 to wake up from deep sleep via the radar trigger signal connected to GPIO4? I have it set to enter deep sleep after a 60-second delay if no radar trigger occurs. However, it keeps waking up automatically even without a radar trigger—or even when the radar module is completely disconnected—and I am unsure if this is due to instability in the ESP32-C3’s underlying firmware or some other issue.


deep_sleep:
  id: deep_sleep_1
  sleep_duration: 0s
  wakeup_pin:
    number: GPIO4
    inverted: false
    allow_other_uses: true
    mode:
      input: true
      pullup: false    
      pulldown: false


binary_sensor:
  - platform: status
    name: "86box4 Status"
    id: device_status

  - platform: gpio
    name: "LD021 PIR"
    id: pir_gpio4
    device_class: occupancy
    pin:
      number: GPIO4
      allow_other_uses: true
      mode:
        input: true
        pullup: false
        pulldown: false
      inverted: false
    filters:
      - delayed_on: 100ms
      - delayed_off: 500ms
    on_state:
      then:
        - if:
            condition:
              binary_sensor.is_on: pir_gpio4
            then:
              - logger.log: "on"
              - script.stop: check_and_sleep
            else:
              - logger.log: "off,60s"
              - script.execute: check_and_sleep


script:
  - id: check_and_sleep
    mode: restart
    then:
      - logger.log: "check_and_sleep "
      - delay: 60s
      - if:
          condition:
            binary_sensor.is_off: pir_gpio4
          then:
            - logger.log: "60s"
            - lambda: |-
                gpio_deep_sleep_hold_en();
            - deep_sleep.enter: deep_sleep_1
          else:
            - logger.log: "60s"

Depending on how the radar module works, you probably need to enable either the internal pull-up or pull-down resistors on GPIO4. I’d start with enabling the latter first.

I actually tried connecting a 10k-ohm pull-up or pull-down resistor, but the problem persisted; it still wakes up automatically even without a trigger signal. I’m not sure if it’s a code issue.

What are you after with this? I expect it wakes up esp immediately, after 0us.

Actually, this code suggestion came from AI. How should I improve it? Commenting out that line didn’t seem to solve the problem.

Simply remove that line. Or set long duration.
You could also split the “radar” output to two different gpios and eliminate all the “allow other use”.
And verify what kind of output your “radar” gives.

I tried it, but the problem persists; I’m even starting to suspect there might be an issue with my ESP32-C3 SuperMini.

What is the board between esp32 and PIR?

This is a custom debugging board I built; the original plan was to integrate radar-based wake-up functionality into a wall-mounted “86-style” panel that also features a clock display. The idea was to use the radar to detect human movement at night and trigger light automation via Home Assistant. However, since this is currently just an integration test board, the specific wake-up features and associated code haven’t been enabled yet.

I see AM312, not radar.
And estimate very bad wifi connection, C3 chip antenna should be outside of the PCB.

Also, the AM312 signal pin will be at 5V, which the ESP32 will not like.

I’ll give it a try. Actually, I started out testing with the LD021 radar module, but since that didn’t work, I switched to the AM312. Thanks a lot!

I suggest you to desolder that esp and connect it directly to sensor.
Then test just with binary sensor to verify you get clean signal.
If you are happy with that, split the output to wake-up pin.

The PIR sensor’s output pin goes high at 3.1V; I’ve verified this with a multimeter.The voltage should be compatible.

AM312 module supposed to have supply range up to 12V and 3V3 output. One should verify that though.

OK,Thank you !

Since it’s fed by 5V, I would expect the output to be at 5V as well. Never mind, it looks like it will always be 3.3V out. Which is fine for the ESP32.

I think you’re right—a pull-down resistor is needed. Also, the resistor wired in series with the OUT pin on the AM312 module I bought was way too large—20k ohms. It became stable after I swapped it for a 360-ohm resistor combined with a pull-down resistor; 1k or 10k ohms might work too, but 20k definitely didn’t cut it. I’m just not sure if there might be other issues.

But shouldn’t be. That pir is push-pull type. And if you leave the 20k series resistor in place and add pull-down (even esp internal), you are technically making a voltage divider and that doesn’t work.
So if the original circuit doesn’t work, just lower the resistor value to 4k7 for example.
360 ohm sounds unnecessary low and if you combine that with strong pull-down, you might damage the PIR.
If you need pull-down, use really weak one.

Yes, you’re absolutely right. In fact, after I swapped out the 20k resistor on the RS312 module, the GPIO pin could detect the signal even without an external 20k pull-down resistor; the resistance was likely low enough to ensure a stable low-level signal at the GPIO pin. It seems like replacing the module’s resistor with a 360-ohm one and connecting it directly to the GPIO pin—without an external pull-down—would also work fine, given the GPIO’s high impedance. However, when using the LD021 radar module, I feel it’s more stable to include a 10k pull-down resistor.