1. Real-World Problem & System Architecture
Non-invasive precision apiculture powered by Digital Signal Processing (DSP) and Edge Machine Learning.
INMP441 I2S Mic + DHT22
Captures crisp 16 kHz 24-bit digital audio directly from the brood chamber alongside brood temperature and humidity.
MFCC Feature Extraction
Slices audio into short frames and computes Mel-Frequency Cepstral Coefficients (MFCCs) to form a compact acoustic fingerprint.
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.
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. 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
3V3pin. - 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 likedriver/i2s.h, or use "By Arduino pin (default)" withD2, D3, D4. Our starter code below uses explicit ESP32-S3 GPIO numbers so I2S works reliably. - Ground the INMP441 L/R Pin: Leaving
L/Rfloating causes random silence or noise. ConnectingL/Rdirectly toGNDlocks 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.
BROOD: 34.5C | INT: 54 dB
ON — Stable
OFF — Normal
Deep Sleep Battery Life Estimator
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.
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.
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.
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.
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.
// ============================================================================
// 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.
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.