ESP32 wakeup with sound sensor
Posted: 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
Thanks !
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();
}
}