Double-clap light switch
Clap twice and the lights come on. Clap twice again to switch them off.
Shop by category
Shop all componentsThe INMP441 is a digital MEMS microphone that sends audio to the ESP32 over the I2S bus. The sketch reads blocks of samples, computes the RMS level and converts it to decibels relative to full scale (dBFS), then maps that to an approximate sound level. Because the microphone is not calibrated, readings are relative, not a certified dB(A) value; to make it closer, compare with a phone sound-level app in a quiet and a loud place and adjust OFFSET. It is useful for noisy classrooms, workshops or deciding whether a room is too loud.
Not suitable for legal or health noise measurements.
Tick anything you already have and the total updates.
INMP441 I2S MEMS microphone module
Follow the colours: red is power, dark grey is ground, blue is a signal.
USB power bank.
sound_meter.inoVerify & upload in Electrolark#include <driver/i2s.h> // legacy I2S driver: works on current ESP32 Arduino cores, with a deprecation note
#include <Wire.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
const i2s_port_t PORT = I2S_NUM_0;
const float OFFSET = 94.0; // calibrate: adds a constant so dBFS maps to roughly dB SPL
int32_t buf[256];
void setup() {
Wire.begin(21, 22);
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
oled.setTextColor(WHITE);
i2s_config_t cfg = {};
cfg.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX);
cfg.sample_rate = 16000;
cfg.bits_per_sample = I2S_BITS_PER_SAMPLE_32BIT;
cfg.channel_format = I2S_CHANNEL_FMT_ONLY_LEFT;
cfg.communication_format = I2S_COMM_FORMAT_STAND_I2S;
cfg.dma_buf_count = 4;
cfg.dma_buf_len = 256;
i2s_pin_config_t pins = {};
pins.bck_io_num = 14; pins.ws_io_num = 15; pins.data_out_num = I2S_PIN_NO_CHANGE; pins.data_in_num = 32;
i2s_driver_install(PORT, &cfg, 0, NULL);
i2s_set_pin(PORT, &pins);
}
void loop() {
size_t bytes = 0;
i2s_read(PORT, buf, sizeof(buf), &bytes, portMAX_DELAY);
int n = bytes / 4;
double sum = 0;
for (int i = 0; i < n; i++) {
float s = (buf[i] >> 8) / 8388608.0; // 24-bit sample scaled to -1..1
sum += s * s;
}
float rms = sqrt(sum / max(n, 1));
float db = 20.0 * log10(max(rms, 1e-6f)) + OFFSET;
oled.clearDisplay();
oled.setTextSize(3); oled.setCursor(0, 4); oled.printf("%.0f dB", db);
int w = constrain(map((int)db, 30, 110, 0, 124), 0, 124);
oled.drawRect(2, 40, 124, 14, WHITE);
oled.fillRect(2, 40, w, 14, WHITE);
oled.display();
}
Check the SD, WS and SCK wiring and that L/R is on GND. Without data the level stays at the floor.
The legacy I2S driver is deprecated on newer cores but still works. The warning is harmless.
Adjust OFFSET. MEMS microphones differ and this meter is not calibrated.
No. It is a relative learning meter and not suitable for legal noise measurement.
It outputs clean digital audio, which avoids noise and gain adjustments.
It can; the same samples can be written to an SD card, which is a good next project.
5 parts: ESP32-WROOM-32 38-Pin Development Board, INMP441 MEMS High Precision Omnidirectional Microphone Module I2S, 0.96" OLED Display 128x64, Solderless Breadboard and Dupont Jumper Wires (40 pcs). On this page you can tick the parts you already have and add only the rest to your cart.
It is a advanced project and takes about 2 hours. The build on this page has 6 steps.
No. This page has the complete, tested code (sound_meter.ino).
About ₹734 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Reading an I2S microphone with the ESP32; Computing RMS and decibels; Calibrating a relative meter against a reference.
Not suitable for legal or health noise measurements.
Ideas that reuse this build: ESP32 OLED internet clock. They are listed under Take it further on this page.
Clap twice and the lights come on. Clap twice again to switch them off.
Plays a friendly ding-dong whenever someone walks into the shop or room.
Beeps and flashes any message in Morse, or key your own by hand.
Turn a membrane keypad into a two-octave piano.
Learning project. Check every circuit and the datasheet of each part before you power it up.