ESP32 wakeup with sound sensor

beavis6511
Posts: 1
Joined: Sat Oct 21, 2023 3:28 pm

ESP32 wakeup with sound sensor

Postby beavis6511 » Sat Oct 21, 2023 3:37 pm

Hello,

I would like to wake up my esp32 (in deep sleep) when the sound sensor detects a sound.
The output of the sensor is not 0/1 but a voltage value, according to the sound level.
Is it possible to do this ?
I've tried with this code but it is not working. After going to sleep, it wakes up immediately

Code: Select all

#define SENSOR_PIN 33
#define S_TO_MS_FACTOR 1000
#define ALIVE_TIME_S  5 // Time in seconds to stay alive, before going to deep sleep

int lastState = HIGH;  // the previous state from the input pin
int currentState;      // the current reading from the input pin

RTC_DATA_ATTR int bootCount = 0;
unsigned long timer = 0;
bool timer_started = false;

void setup() {
  Serial.begin(115200);
  pinMode(SENSOR_PIN, INPUT);

  Serial.println("Setup");

  ++bootCount;
  Serial.println("Boot number: " + String(bootCount));

  esp_sleep_enable_ext0_wakeup(GPIO_NUM_33, 0); //1 = High, 0 = Low
}

void loop() {
  
  // Deep Sleep 
  if (!timer_started) {
    Serial.println("Start timer");
    timer = millis();
    timer_started = true;
  }

  if (millis() - timer >= (ALIVE_TIME_S * S_TO_MS_FACTOR)) {
    Serial.println("going to sleep...");
    timer_started = false;
    esp_deep_sleep_start();
  }

}
Thanks !

MicroController
Posts: 1735
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: ESP32 wakeup with sound sensor

Postby MicroController » Sun Oct 22, 2023 10:03 am

a voltage value, according to the sound level.
Is it possible to do this ?
Sounds like you'd want to use the ULP to read the voltage level via the ADC, like in this example.

Who is online

Users browsing this forum: Google [Bot] and 63 guests