Skip to main content
  1. Blogs/

On-Device Elephant Detection with Edge Impulse and ESP32

·728 words·4 mins
Owen O'Hehir
Author
Owen O’Hehir
Dublin-based embedded Linux, IoT and Matter consultant. Helping startups and product teams design, prototype and ship connected devices.

On-Device Elephant Detection with Edge Impulse and ESP32
#

Human-elephant conflict is one of the leading causes of elephant deaths across Southeast Asia. When herds move through farmland, the consequences for both people and animals can be severe. Early warning gives communities time to respond before a confrontation develops.

ELOC (Elephant Locator) is an open-source, solar-powered acoustic monitor that listens continuously for elephant vocalisations — trumpets and low-frequency rumbles — and triggers an alert when one is detected. The project is led by LIFsCode on the software side and EDsteve on hardware and coordination, with researchers from Colombo University and Gadjah Mada University, in collaboration with the International Elephant Project. I contributed across several areas of the firmware over the course of 2024.

The Hardware
#

The device is built around the ESP32-WROVER-E — 240MHz, 8MB PSRAM, 16MB flash — in an IP66-rated weatherproof enclosure with solar charging and Li-Ion battery support. Audio is captured by an ICS-43434 I2S MEMS microphone, a 24-bit part with a 65dBA SNR and response down to 10Hz. The low-frequency extension matters because elephant rumbles sit partly in infrasound territory, with some vocalisations detectable from over 500 metres.

I2S Audio Capture
#

The ESP32 captures audio from the ICS-43434 over I2S using DMA transfers into a ring buffer, keeping the CPU free between captures. Sampling rate is configurable: 16kHz for normal ML inference operation (~18mA), or 44.1kHz for full-quality archiving and training data collection (~35mA). In deployment, 16kHz is the default to stretch solar budget.

My work here included simplifying the I2S microphone library by removing an unnecessary parent class, fixing configuration items that had accumulated — redundant bitShift and fixSPH0645 settings were removed and replaced with a clean volume gain via config — and making the board configuration properly board-dependent rather than hardcoded.

Edge Impulse ML Integration
#

The classifier runs via the Edge Impulse C++ SDK, compiled in as a static library. The pipeline is straightforward: I2S samples are windowed, an MFCC feature vector is computed, the neural network runs inference, and a detection event fires if the elephant class clears a configured confidence threshold.

The 8MB PSRAM on the WROVER-E gives enough headroom to hold the audio ring buffer and the inference arena simultaneously without memory pressure. Inference draws 23–70mA depending on model size.

I updated the SDK to include a new ML model (an 80-file changeset) and built out testing infrastructure around it: a WAV file reader that loads recordings from SD card, a method to run WAV files through the ML pipeline, and serial output formatting to make inference results readable during bench testing. This made it possible to validate classifier behaviour against known recordings without needing a live microphone — useful for regression testing when the model is updated.

Testing Infrastructure
#

The project uses PlatformIO with a unit test suite running on-device. I added mock classes for hardware peripherals to allow logic to be tested in isolation, added robot framework test capability, and extended the test suite to cover CPU frequency changes, sample rate transitions, and ESP32Time behaviour. I also wrote test documentation to make the process reproducible.

Getting the build reliable across platforms was its own task — I added a script to auto-detect the correct upload and monitor port depending on OS, fixed a pre-build script that was breaking Windows builds, and updated the espressif32 SDK version in the PlatformIO config.

Time and Storage
#

Two other areas I worked on: time management and SD card handling.

For time, I modified the ESP32Time utility library and refactored the existing time code around it. The device can now have system time set via Unix timestamp with timezone support, which matters for accurate timestamping of detection events in the field. Uptime reporting was also moved to use this library for consistency.

For SD card, I added speed testing to characterise card performance (write speed varies significantly between cards, which affects whether audio can be written without dropping), centralised SD mount state and space checking, and added guards when opening files to catch card removal during operation.

Outcome
#

By early 2023, 28 devices had been through field testing in Sumatra and Borneo, with over 3,000 labelled elephant vocalisations in the training dataset. The project is open source and actively maintained — worth a look if you’re working on bioacoustic monitoring or wildlife AI on constrained hardware.