COLLEGE PROJECT TINYML AUDIO ARDUINO NANO ESP32 LOW-POWER IOT

Acoustic Beehive Health & Queen-Loss Monitor

Monitor honeybee colony health non-invasively using an INMP441 digital I2S microphone and Arduino Nano ESP32. By converting raw hive buzz into MFCC audio spectrograms and running a compact 1D-CNN locally, the device detects queen loss and pre-swarming—then sends a Wi-Fi MQTT alert and returns to ultra-low-power deep sleep.

BoardArduino Nano ESP32
Sampling16 kHz I2S Digital
AI MethodMFCC + 1D-CNN
Est. Cost₹2,200 / $26

1. Real-World Problem & System Architecture

Non-invasive precision apiculture powered by Digital Signal Processing (DSP) and Edge Machine Learning.

Why Traditional Hive Inspection Fails: To check if a queen bee is alive or if a colony is preparing to swarm, beekeepers must pry open the hive lid, puff smoke, and pull out brood frames. Opening the hive breaks the colony's tightly regulated 34–35°C brood microclimate, stresses the bees, risks accidentally crushing the queen, and reduces honey yield. Acoustic Edge-AI listens from inside the hive continuously without disturbing a single frame.
STAGE 1

INMP441 I2S Mic + DHT22

Captures crisp 16 kHz 24-bit digital audio directly from the brood chamber alongside brood temperature and humidity.

STAGE 2

MFCC Feature Extraction

Slices audio into short frames and computes Mel-Frequency Cepstral Coefficients (MFCCs) to form a compact acoustic fingerprint.

STAGE 3

On-Device TinyML CNN

A quantized 1D-CNN runs directly on the ESP32-S3 core, classifying states locally with zero raw audio uploaded to the cloud.

STAGE 4

Wi-Fi MQTT + Deep Sleep

Publishes a tiny JSON health packet to the beekeeper's dashboard, updates the OLED/LEDs, and enters Deep Sleep for 60 minutes.

Acoustic Signature Reference

Healthy (Queenright) ~200–250 Hz

Produces a calm, steady, low-frequency wing-beat hum with low spectral variance and stable brood nest temperature (33–35.5°C). Indicates a thriving, queenright colony.

Queenless Colony 200–1000+ Hz

Within hours of losing their queen, workers emit a noticeably louder, restless "roar" with broadband high-frequency transients and distressed worker piping spikes.

Pre-Swarming 300–500 Hz + Pulses

Days before swarming, the dominant buzz shifts upward to 300–500 Hz accompanied by rhythmic queen "tooting" and "quacking" pulses (~400–550 Hz) and elevated hive heat.

2. Interactive Real Wiring Diagram (Arduino Nano ESP32)

Use the filter buttons to isolate Power rails, the I2S Digital Audio Bus, the I2C OLED display, or the DHT22 & Status LEDs.

3.3V RAIL COMMON GND 10kΩ USB-C ESP32-S3 NORA-W106 I2S + TinyML Arduino Nano ESP32 3.3V Logic Only 3V3 GND D2 / GPIO5 D3 / GPIO6 D4 / GPIO7 D5 / GPIO8 GND A4 / GPIO11 A5 / GPIO12 D6 / GPIO9 D7 / GPIO10 INMP441 I2S MEMS Mic L/R → GND (Left) VDD GND L/R SCK WS SD DHT22 Brood Temp & RH VCC DATA GND 0.96" SSD1306 OLED BEEHIVE AI QUEENRIGHT 228 Hz | 95% T:34.6C RH:58% I2C Addr: 0x3C VCC GND SDA SCL 220Ω + − Green LED (Healthy) 220Ω + − Red LED (Alert) 3.3V GND / L-R I2S SCK (D2) I2S WS (D3) I2S SD (D4) DHT22 / Green LED I2C SDA (A4) I2C SCL (A5) Red LED (D7)
All Connections Active: The INMP441 streams digital audio over 3 dedicated I2S lines (D2, D3, D4), the SSD1306 OLED uses hardware I2C (A4, A5), the DHT22 reads brood temperature on D5 with a 10kΩ pull-up resistor, and D6/D7 drive the status LEDs.

3. Complete Pinout Table & Hardware Safety Notes

Reference both the Arduino silkscreen label (D/A) and underlying ESP32-S3 GPIO number when wiring and coding.

Component Component Pin Nano ESP32 Pin ESP32-S3 GPIO Wire Color Function
INMP441 I2S Mic VDD / GND 3V3 / GND Power Red / Black 3.3V clean digital power supply
INMP441 I2S Mic L/R GND Power Black Selects Mono Left I2S Audio Channel
INMP441 I2S Mic SCK (BCLK) D2 GPIO 5 Blue I2S Serial Bit Clock
INMP441 I2S Mic WS (LRCLK) D3 GPIO 6 Purple I2S Word Select (16 kHz frame clock)
INMP441 I2S Mic SD (DOUT) D4 GPIO 7 Teal I2S 24-bit Serial Audio Data Out
DHT22 Sensor VCC / GND 3V3 / GND Power Red / Black 3.3V power for temperature/humidity
DHT22 Sensor DATA (+10kΩ to 3.3V) D5 GPIO 8 Green Single-wire digital brood climate data
0.96" SSD1306 OLED VCC / GND 3V3 / GND Power Red / Black 3.3V OLED display power
0.96" SSD1306 OLED SDA / SCL A4 / A5 GPIO 11 / GPIO 12 Orange / Amber Hardware I2C bus (Addr 0x3C)
Green LED (+220Ω) Anode (+) / Cathode (−) D6 / GND GPIO 9 Green / Black Healthy Queenright status indicator
Red Alert LED (+220Ω) Anode (+) / Cathode (−) D7 / GND GPIO 10 Red / Black Queenless / Pre-Swarm local warning

Practical Field-Build & Hardware Safety Checklist

  • Strict 3.3V-Only Logic: The Arduino Nano ESP32 is not 5V tolerant on any GPIO pin. Power the INMP441, DHT22, and SSD1306 exclusively from the 3V3 pin.
  • Arduino IDE Pin Numbering Setting: In Arduino IDE, go to Tools → Pin Numbering. Choose "By GPIO number (legacy)" if you pass raw ESP32-S3 GPIOs (5, 6, 7...) to IDF drivers like driver/i2s.h, or use "By Arduino pin (default)" with D2, D3, D4. Our starter code below uses explicit ESP32-S3 GPIO numbers so I2S works reliably.
  • Ground the INMP441 L/R Pin: Leaving L/R floating causes random silence or noise. Connecting L/R directly to GND locks the mic cleanly to the Left I2S channel.
  • Propolis & Moisture Protection: Honeybees coat foreign objects with sticky resin called propolis. Wrap the INMP441 microphone in a tiny breathable cage made of fine stainless-steel mesh (smaller than a bee's proboscis) and keep the main PCB in a weatherproof box outside the hive.

4. Bill of Materials (BOM)

Affordable, widely available components suitable for a college mini-project or final-year capstone.

Component Exact Model / Spec Qty Purpose Approx. Cost (INR / USD)
Microcontroller Arduino Nano ESP32 (with headers) 1 Dual-core ESP32-S3 TinyML inference, Wi-Fi & Deep Sleep ₹1,350 / $16.00
Digital Microphone INMP441 Omnidirectional I2S MEMS Module 1 Low-noise 16 kHz digital audio capture ₹220 / $2.60
Climate Sensor DHT22 (AM2302) + 10kΩ Resistor 1 Brood nest temperature & humidity verification ₹200 / $2.40
OLED Display 0.96" I2C OLED (SSD1306, 128×64) 1 Field status readout during apiary checks ₹210 / $2.50
Status LEDs & Resistors 5mm Green & Red LEDs + 220Ω Resistors 2 each Instant visual health/alert indicators ₹20 / $0.30
Prototyping & Mesh Breadboard, Jumper Wires & Fine SS Mesh 1 set Circuit assembly & propolis-proof mic guard ₹200 / $2.20
Estimated Project Total (Excluding Optional 18650 Battery Pack) ₹2,200 / $26.00

5. Live Acoustic Hive & TinyML Simulator

Test how the MFCC + 1D-CNN classifier reacts to real-time frequency shifts, piping transients, and brood temperature—complete with an animated Waveform & FFT Spectrum analyzer.

TOP: TIME-DOMAIN WAVEFORM (16 kHz I2S) PEAK: 225 Hz
BOTTOM: FFT SPECTRUM (100 Hz → 1000 Hz) DSP WINDOW: 1024-PT HANN
SSD1306 128×64 TINYML ACTIVE
HEALTHY (QUEENRIGHT)
PEAK: 225 Hz | CONF: 96%
BROOD: 34.5C | INT: 54 dB
Green LED (D6)
ON — Stable
Red LED (D7)
OFF — Normal
MQTT TOPIC: apiary/hive01/telemetry QoS 1

        

Deep Sleep Battery Life Estimator

Avg Draw: 0.43 mA Estimated Field Runtime
232 Days

6. Step-by-Step TinyML Workflow (Edge Impulse)

Follow these four steps to train and deploy your acoustic bee classifier without writing complex math from scratch.

1

Record 16 kHz Audio Clips

Collect 10–15 minutes of labeled 16 kHz mono WAV audio (from open bee-sound datasets like OSBH/Nu-Hive or direct I2S serial capture) across 4 classes: healthy, queenless, swarm, and noise.

2

Add MFCC Audio DSP Block

In Edge Impulse, create a 2-second time window (500 ms stride) and add the Audio (MFCC) processing block. Set Low Frequency to 100 Hz and High Frequency to 1500 Hz to focus tightly on bee wing-beat harmonics.

3

Train 1D-CNN Classifier

Add a Classification (Keras) learning block with two 1D convolutional layers and Dropout (0.25). Train for 60 epochs and verify the Confusion Matrix achieves >88% accuracy on unseen test clips.

4

Export & Enable Deep Sleep

Export the Int8-quantized model as an Arduino Library (.zip). Call run_classifier() once per hour on wake-up, publish the predicted label over MQTT, and call esp_deep_sleep_start() to save battery.

7. Copy-Ready Arduino IDE Starter Code (Nano ESP32)

In Arduino IDE, select Arduino Nano ESP32, set Tools → Pin Numbering → By GPIO number (legacy), and install DHT sensor library and Adafruit SSD1306.

beehive_acoustic_monitor.ino • INMP441 I2S (16 kHz) + DHT22 + OLED + Deep Sleep
// ============================================================================
// Acoustic Beehive Health & Queen-Loss Monitor — Arduino Nano ESP32
// Set Arduino IDE -> Tools -> Pin Numbering -> "By GPIO number (legacy)"
// INMP441 I2S: SCK=GPIO5(D2), WS=GPIO6(D3), SD=GPIO7(D4), L/R=GND
// DHT22=GPIO8(D5) | LEDs: Green=GPIO9(D6), Red=GPIO10(D7) | OLED: SDA=11, SCL=12
// ============================================================================

#include <driver/i2s.h>
#include <Wire.h>
#include <DHT.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <math.h>

// ESP32-S3 GPIO Definitions matching the IoTInfo Wiring Diagram
#define I2S_SCK_PIN     5    // D2
#define I2S_WS_PIN      6    // D3
#define I2S_SD_PIN      7    // D4
#define DHT_PIN         8    // D5
#define GREEN_LED_PIN   9    // D6
#define RED_LED_PIN     10   // D7
#define OLED_SDA_PIN    11   // A4
#define OLED_SCL_PIN    12   // A5

#define SAMPLE_RATE     16000
#define SAMPLE_BUFFER   512
#define SLEEP_SECONDS   3600 // Wake once per hour (set to 10 for lab testing)
#define ENABLE_SLEEP    false // Change to true for battery deployment

DHT dht(DHT_PIN, DHT22);
Adafruit_SSD1306 display(128, 64, &Wire, -1);
int32_t i2sBuffer[SAMPLE_BUFFER];

void setupI2SMic() {
  i2s_config_t i2s_config = {
    .mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX),
    .sample_rate = SAMPLE_RATE,
    .bits_per_sample = I2S_BITS_PER_SAMPLE_32BIT,
    .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT, // L/R pin tied to GND
    .communication_format = I2S_COMM_FORMAT_STAND_I2S,
    .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
    .dma_buf_count = 4,
    .dma_buf_len = SAMPLE_BUFFER,
    .use_apll = false
  };
  i2s_pin_config_t pin_config = {
    .bck_io_num = I2S_SCK_PIN,
    .ws_io_num = I2S_WS_PIN,
    .data_out_num = I2S_PIN_NO_CHANGE,
    .data_in_num = I2S_SD_PIN
  };
  i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL);
  i2s_set_pin(I2S_NUM_0, &pin_config);
}

void sampleAndAnalyze() {
  size_t bytesRead = 0;
  i2s_read(I2S_NUM_0, &i2sBuffer, sizeof(i2sBuffer), &bytesRead, portMAX_DELAY);

  int samples = bytesRead / sizeof(int32_t);
  double sumSq = 0;
  int32_t peak = 0;

  for (int i = 0; i < samples; i++) {
    int32_t val = i2sBuffer[i] >> 14; // Normalize 24-bit left-aligned audio
    sumSq += (double)val * val;
    if (abs(val) > peak) peak = abs(val);
  }

  float rms = sqrt(sumSq / samples);
  float tempC = dht.readTemperature();
  float hum   = dht.readHumidity();

  // Print CSV line for Edge Impulse Data Forwarder / Serial Plotter
  Serial.printf("%.2f,%ld,%.1f,%.1f\n", rms, (long)peak, tempC, hum);

  // Baseline Indicator (Replace with Edge Impulse run_classifier() output)
  bool stressAlert = (rms > 420.0 || peak > 1800);
  digitalWrite(GREEN_LED_PIN, stressAlert ? LOW : HIGH);
  digitalWrite(RED_LED_PIN, stressAlert ? HIGH : LOW);

  // Update OLED Screen
  display.clearDisplay();
  display.setTextSize(1);
  display.setCursor(0, 0);
  display.println("BEEHIVE ACOUSTIC AI");
  display.drawLine(0, 10, 128, 10, SSD1306_WHITE);
  display.setTextSize(2);
  display.setCursor(0, 18);
  display.println(stressAlert ? "ALERT!" : "HEALTHY");
  display.setTextSize(1);
  display.setCursor(0, 42);
  display.printf("RMS:%.0f  Pk:%ld", rms, (long)peak);
  display.setCursor(0, 54);
  display.printf("T:%.1fC  RH:%.0f%%", tempC, hum);
  display.display();
}

void setup() {
  Serial.begin(115200);
  pinMode(GREEN_LED_PIN, OUTPUT);
  pinMode(RED_LED_PIN, OUTPUT);

  Wire.begin(OLED_SDA_PIN, OLED_SCL_PIN);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.setTextColor(SSD1306_WHITE);
  dht.begin();
  setupI2SMic();

  Serial.println("rms_level,peak_amp,temp_c,humidity_pct");

  if (ENABLE_SLEEP) {
    sampleAndAnalyze();
    // TODO: Connect Wi-Fi & publish MQTT JSON here before sleeping
    delay(500);
    esp_sleep_enable_timer_wakeup((uint64_t)SLEEP_SECONDS * 1000000ULL);
    esp_deep_sleep_start();
  }
}

void loop() {
  sampleAndAnalyze();
  delay(1000);
}

8. Viva & Project Evaluation Q&A

Expand these six examiner questions to prepare clear, technical answers for your final presentation.

The INMP441 integrates a high-SNR (61 dB) MEMS acoustic element and a 24-bit ADC directly inside the microphone package, streaming clean digital PCM audio over the I2S bus. Analog microphones suffer from ESP32 ADC non-linearity, Wi-Fi RF hum, and voltage noise along jumper wires—which easily corrupt subtle 200–500 Hz bee buzzing frequencies.
Mel-Frequency Cepstral Coefficients (MFCCs) transform a raw 1D audio waveform into a compact 2D time-frequency matrix that emphasizes perceptually important frequency bands while discarding phase noise. Because MFCCs compress 16,000 samples/second into just a few dozen features, a tiny 1D-CNN can accurately separate a 220 Hz queenright hum from 400 Hz pre-swarm piping using under 60 KB of RAM.
Unlike older boards, the Arduino Nano ESP32 maps Arduino labels (D2, D3, D4...) to different underlying ESP32-S3 silicon pins (GPIO 5, 6, 7...). Low-level ESP-IDF drivers like driver/i2s.h expect raw GPIO numbers. By setting Tools → Pin Numbering → By GPIO number (legacy) in Arduino IDE and documenting both labels in our pinout table, we avoid pin-mismatch bugs.
Active Wi-Fi transmission and I2S audio inference draw roughly ~140 mA, which would drain a 3000 mAh 18650 battery in under 24 hours. Because colony health changes over hours—not milliseconds—we wake the ESP32-S3 for just 10 seconds per hour to sample, infer, and publish MQTT, then enter Deep Sleep (~20–50 μA). This lowers average current below 0.5 mA, extending runtime to several months.
Only the INMP441 microphone and DHT22 probe go inside the hive—placed inside a miniature fine stainless-steel mesh sleeve (<1.5 mm aperture) so bees cannot chew wires or seal the acoustic port with sticky propolis resin. The Arduino Nano ESP32, OLED, and battery stay mounted outside the hive in an IP65 weatherproof enclosure with a small silica-gel pack.
During college lab demos, place the INMP441 microphone inside a small wooden demonstration box containing a Bluetooth speaker playing verified open-source beehive recordings (from the OSBH or Nu-Hive datasets) for Queenright, Queenless, and Pre-Swarming states. Examiners can watch the OLED, LEDs, and live MQTT dashboard switch states in real time as you change the audio track!