Double-clap light switch
Clap twice and the lights come on. Clap twice again to switch them off.
Shop by category
Shop all componentsRecord the average noise level for each of the last minutes and plot the result as a history graph. Two timescales operate at once. Readings are taken constantly and accumulated into a running total; once a minute that total is divided by the number of samples to give one averaged data point, and the accumulator resets. Averaging before storing is what makes long-term logging possible on a board with 2 KB of RAM, a hundred stored minutes cost a hundred bytes, while storing every raw sample would exhaust memory in seconds.
The ESP32 is a 3.3V board: never connect a 5V signal straight to a GPIO pin.
Every part for this build comes in the Geekobot Titan Kit box, a Geekobot exclusive, together with the parts for all 120 projects, from a first blinking LED to a smart fan and a reaction game. The wiring below is the kit's own wiring.
Tick anything you already have and the total updates.
ESP32 DevKit V1 (38-pin): the brain of every Titan Kit project, with Wi-Fi and Bluetooth
Male-to-female and female-to-female leads for the modules
Sound sensor module: AO gives the loudness, DO switches at the knob setting
ESP32 expansion board from the kit: every GPIO has its own S, V, G header
Follow the colours: red is power, dark grey is ground, blue is a signal.
titan_kit_060_noise_history_logger.inoVerify & upload in Electrolark#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SLOTS 100
Adafruit_SSD1306 display(128, 64, &Wire, -1);
int micPin = 34;
int clearButton = 12;
byte log_[SLOTS];
int stored = 0;
long accumulator = 0;
int samples = 0;
unsigned long slotStart = 0;
unsigned long slotLength = 60000; // One minute per slot
int level()
{
unsigned long start = millis();
int highest = 0;
int lowest = 1023;
while (millis() - start < 30)
{
int sample = analogRead(micPin);
if (sample > highest) highest = sample;
if (sample < lowest) lowest = sample;
}
return constrain(map(highest - lowest, 20, 400, 0, 100), 0, 100);
}
void storeSlot(byte value)
{
if (stored < SLOTS)
{
log_[stored] = value;
stored = stored + 1;
return;
}
for (int i = 0; i < SLOTS - 1; i++)
{
log_[i] = log_[i + 1];
}
log_[SLOTS - 1] = value;
}
void setup()
{
analogReadResolution(10); // ESP32 is 12-bit; use 0-1023 like the examples
pinMode(clearButton, INPUT_PULLUP);
Serial.begin(9600);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C))
{
Serial.println("OLED not found");
while (true) { }
}
display.setTextColor(SSD1306_WHITE);
display.setTextSize(1);
slotStart = millis();
}
void loop()
{
int now = level();
accumulator = accumulator + now;
samples = samples + 1;
if (digitalRead(clearButton) == LOW)
{
stored = 0;
accumulator = 0;
samples = 0;
slotStart = millis();
Serial.println("Log cleared");
delay(300);
}
if (millis() - slotStart > slotLength)
{
byte average = accumulator / samples;
storeSlot(average);
Serial.print("Minute ");
Serial.print(stored);
Serial.print(" average ");
Serial.println(average);
accumulator = 0;
samples = 0;
slotStart = millis();
}
display.clearDisplay();
display.setCursor(0, 0);
display.print("NOISE HISTORY");
display.setCursor(78, 0);
display.print("now ");
display.print(now);
int runningAverage = samples > 0 ? accumulator / samples : 0;
display.setCursor(0, 10);
display.print("Minute avg ");
display.print(runningAverage);
display.print("% ");
display.print((slotLength - (millis() - slotStart)) / 1000);
display.print("s");
// History graph
display.drawLine(14, 22, 14, 58, SSD1306_WHITE);
display.drawLine(14, 58, 127, 58, SSD1306_WHITE);
display.setCursor(0, 20);
display.print("100");
display.setCursor(8, 52);
display.print("0");
for (int i = 0; i < stored; i++)
{
int x = 16 + i;
if (x > 127) break;
int h = map(log_[i], 0, 100, 0, 35);
display.drawLine(x, 58, x, 58 - h, SSD1306_WHITE);
}
if (stored == 0)
{
display.setCursor(20, 36);
display.print("First minute...");
}
display.display();
}
Use a micro-USB data cable (some cables only charge), install the CP210x or CH340 driver if no port appears, pick Tools > Board > ESP32 Dev Module and hold the BOOT button on the board until the upload starts.
The sketch uses INPUT_PULLUP, so one leg goes to the GPIO and the other to GND. Use two legs on opposite sides of the button.
Use the sensor's AO pin on GPIO34 and turn the blue trim pot: the module's LED should flicker when you clap.
Check SDA on GPIO21 and SCL on GPIO22, power from 3V3, and that the sketch uses address 0x3C (some boards are 0x3D).
Two timescales operate at once. Readings are taken constantly and accumulated into a running total; once a minute that total is divided by the number of samples to give one averaged data point, and the accumulator resets. Averaging before storing is what makes long-term logging possible on a board with 2 KB of RAM, a hundred stored minutes cost a hundred bytes, while storing every raw sample would exhaust memory in seconds.
The header shows the instantaneous level and the running average for this minute. A countdown shows when the next data point will be stored. After each minute a new bar appears in the history graph.
Yes. It is project 60 of 120 in the Geekobot Titan Kit, in level 10 (Sound analysis). Every part on the list comes in the kit box, and you can also buy the parts one by one from the list above.
No. Every Titan Kit project is wired on the ESP32 expansion board and the breadboard with jumper wires.
8 parts: ESP32-WROOM-32 38-Pin Development Board, USB Cable, Solderless Breadboard, Dupont Jumper Wires (40 pcs), Tactile Push Button Switch, Generic LM393 Sound Detection Sensor Module – Digital Output, 0.96" OLED Display 128x64 and ESP32 38-Pin Expansion Board. 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 45 minutes. The build on this page has 6 steps.
No. This page has the complete, tested code (titan_kit_060_noise_history_logger.ino).
About ₹881 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Moving averages computation; Accumulating samples before storing; Why averaging is essential for long-term logs on small RAM; Working with two different timescales in one sketch.
The ESP32 is a 3.3V board: never connect a 5V signal straight to a GPIO pin.
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.
Lessons are free to read. Maker (₹499/month) and Pro add quizzes, worked problems and certificates, paid with your Geekobot account. See plans
Learning project. Check every circuit and the datasheet of each part before you power it up.