Projects / Cooker whistle counter

Cooker whistle counter

Beginner2.2 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. NANOMAX4466

    Wire the microphone

    VCC to 5V, GND to GND, OUT to A0.

  2. NANO

    Wire the display

    5V or 3V3, GND, SDA to A4, SCL to A5.

  3. NANO

    Wire the buzzer

    Plus to D8, minus to GND.

  4. NANO

    Wire the button

    D2 to GND.

  5. NANO

    Upload the sketch

    Stay quiet for two seconds while it listens to the room.

  6. NANO

    Test with a whistle or a high tone

    The count goes up after half a second.

  7. NANO

    Set the target

    Short press steps from 1 to 9, hold to reset.

In short

How do you build a cooker whistle counter?

A small microphone module near a pressure cooker counts the whistles and shows the count on a display, with a beep when the number you set is reached. You need Arduino Nano, MAX4466 microphone module, SSD1306 OLED Display, Passive buzzer, Tactile push button 6 mm, Jumper wires male to male (40 pcs, 20 cm) and Breadboard 830 Tie Points. It takes 7 steps and about 130 minutes.

Level
Beginner
Time
About 130 min
Parts
7

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
MAX4466 VCCNano 5VPower at 5 V
MAX4466 GNDNano GNDCommon ground
MAX4466 OUTNano A0Sound signal, centred at about half the supply
OLED VCCNano 5VPower (check your OLED accepts 5 V, otherwise use 3V3)
OLED GNDNano GNDCommon ground
OLED SDA and SCLNano A4 and A5I2C, address 0x3C
Passive buzzer +Nano D8Tone output
Passive buzzer -Nano GNDReturn
ButtonNano D2 and GNDShort press: set the target. Hold: reset the count

Code

A pressure cooker whistles when the steam is released, and some recipes say to turn the heat down after a certain number of whistles. This build listens and counts them. The MAX4466 is a microphone with an amplifier, and its output swings above and below half the supply voltage as the sound goes up and down. The program watches the signal for forty milliseconds at a time and measures the difference between its highest and lowest values, which grows with the loudness. At start-up it listens to the kitchen and sets the threshold to four times the background level. A whistle must stay above the threshold for half a second to count, and the sound must stay below it for a second before the next whistle can be counted, so one long whistle is not counted several times. A short press of the button sets the target from one to nine, and a long press resets the count. This is a helper only, not a safety device: it can miss a whistle or count noise. Always stay in the kitchen when cooking under pressure, follow the cooker maker's instructions, and never rely on this to turn off a stove.

Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

Adafruit_SSD1306 oled(128, 64, &Wire, -1);

const int MIC = A0, BUTTON = 2, BUZZER = 8;
int target = 3;
int count = 0;
int threshold = 150;
unsigned long loudSince = 0;
unsigned long quietSince = 0;
bool counted = false;                              // this whistle has already been counted

int peakToPeak() {
  int lo = 1023, hi = 0;
  unsigned long start = millis();
  while (millis() - start < 40) {                  // watch the signal for 40 ms
    int v = analogRead(MIC);
    if (v < lo) lo = v;
    if (v > hi) hi = v;
  }
  return hi - lo;
}

void draw(int level) {
  oled.clearDisplay();
  oled.setTextColor(SSD1306_WHITE);
  oled.setTextSize(1);
  oled.setCursor(0, 0);
  oled.print("Whistles   target ");
  oled.print(target);
  oled.setTextSize(4);
  oled.setCursor(40, 14);
  oled.print(count);
  oled.drawRect(0, 54, 128, 10, SSD1306_WHITE);
  oled.fillRect(2, 56, constrain(level * 124L / 600, 0, 124), 6, SSD1306_WHITE);
  oled.display();
}

void setup() {
  pinMode(BUTTON, INPUT_PULLUP);
  pinMode(BUZZER, OUTPUT);
  Wire.begin();
  if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { while (true) {} }
  int quiet = 0;                                   // measure the kitchen noise first
  for (int i = 0; i < 40; i++) quiet = max(quiet, peakToPeak());
  threshold = max(150, quiet * 4);
  quietSince = millis();
}

void loop() {
  int level = peakToPeak();
  unsigned long now = millis();

  if (level > threshold) {
    if (loudSince == 0) loudSince = now;
    quietSince = 0;
    if (!counted && now - loudSince > 500) {       // a real whistle lasts at least half a second
      counted = true;
      count++;
      if (count == target) {
        for (int i = 0; i < 4; i++) { tone(BUZZER, 2000, 400); delay(600); }
      }
    }
  } else {
    if (quietSince == 0) quietSince = now;
    loudSince = 0;
    if (counted && now - quietSince > 1000) counted = false;   // quiet for a second: ready for the next
  }

  if (digitalRead(BUTTON) == LOW) {
    unsigned long pressed = millis();
    while (digitalRead(BUTTON) == LOW) {}
    if (millis() - pressed > 1000) count = 0;      // long press resets
    else target = target % 9 + 1;                  // short press: 1 to 9
  }
  draw(level);
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Start in a quiet roomCount 0
Whistle for a secondCount 1
Whistle again after a pauseCount 2
Reach the targetFour beeps
Hold the buttonCount back to 0

If it does not work

Counts by itself

Move the microphone away from the fan and the burner noise, or raise the 4 in the threshold.

Never counts

Turn the microphone gain screw up a little, or lower the 4.

Counts one whistle twice

Lengthen the one-second quiet time.

Display blank

Check the I2C wires and address 0x3C.

Beeps at the wrong number

Check the target on the top of the display.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the cooker whistle counter?

Arduino Nano, MAX4466 microphone module, SSD1306 OLED Display, Passive buzzer, Tactile push button 6 mm, Jumper wires male to male (40 pcs, 20 cm) and Breadboard 830 Tie Points.

How long does the cooker whistle counter take to build?

About 130 minutes for a beginner maker, in 7 steps.

How do I know the cooker whistle counter works?

Start in a quiet room: Count 0. Whistle for a second: Count 1. Whistle again after a pause: Count 2.

Counts by itself: what should I check?

Move the microphone away from the fan and the burner noise, or raise the 4 in the threshold.

Never counts: what should I check?

Turn the microphone gain screw up a little, or lower the 4.

Counts one whistle twice: what should I check?

Lengthen the one-second quiet time.

Display blank: what should I check?

Check the I2C wires and address 0x3C.