DEV Community

張旭豐
張旭豐

Posted on

5 Sound Sensor Projects That React to Noise and Silence

5 Sound Sensor Projects That React to Noise and Silence

Build audio-reactive systems: clapper light switch, door knock detector, noise level meter, voice message display, and parking counter

Hero

Project 1: Clapper Light Switch

Goal: Turn lights on/off with two claps

Clapper Light Switch

Hardware

KY-038, Arduino Nano, 5V relay, Lamp

Code

#define SOUND_PIN  A0
#define RELAY_PIN  7
#define THRESHOLD  300

int clapCount = 0;
unsigned long lastClap = 0;

void setup() {
  pinMode(RELAY_PIN, OUTPUT);
}

void loop() {
  int val = analogRead(SOUND_PIN);
  if (val > THRESHOLD) {
    if (millis() - lastClap > 300) {
      clapCount++;
      lastClap = millis();
    }
  }
  if (clapCount == 2) {
    digitalWrite(RELAY_PIN, !digitalRead(RELAY_PIN));
    clapCount = 0;
  }
}
Enter fullscreen mode Exit fullscreen mode

Project 2: Door Knock Detector

Goal: Alert when someone knocks on your door

Door Knock Detector

Hardware

KY-038, Arduino Nano, Buzzer, LED

Code

#define SOUND_PIN  A0
#define BUZZER_PIN 8
#define THRESHOLD  400

void setup() { pinMode(BUZZER_PIN, OUTPUT); }

void loop() {
  if (analogRead(SOUND_PIN) > THRESHOLD) {
    tone(BUZZER_PIN, 880, 500);
    delay(1000);
  }
}
Enter fullscreen mode Exit fullscreen mode

Project 3: Office Noise Meter

Goal: Display real-time noise level on LCD

Office Noise Meter

Hardware

KY-038, Arduino Nano, 16×2 LCD

Code

void loop() {
  int noise = analogRead(SOUND_PIN);
  lcd.clear();
  lcd.setCursor(0, 0); lcd.print("Noise Level:");
  lcd.setCursor(0, 1); lcd.print(noise);
  delay(200);
}
Enter fullscreen mode Exit fullscreen mode

Project 4: Voice Message Sign

Goal: Display custom message when you speak

Voice Message Sign

Hardware

KY-038, Arduino Nano, MAX7219 LED matrix

Code

#define SOUND_PIN  A0
bool activated = false;

void loop() {
  if (analogRead(SOUND_PIN) > 350 && !activated) {
    scrollText("Welcome!");
    activated = true;
    delay(3000);
    activated = false;
  }
}
Enter fullscreen mode Exit fullscreen mode

Project 5: Parking Counter

Goal: Count cars entering a lot by engine sound

Parking Counter

Hardware

KY-038, Arduino Nano, 16×2 LCD

Code

int cars = 0;
bool counting = false;

void loop() {
  int sound = analogRead(SOUND_PIN);
  if (sound > 400 && !counting) {
    cars++;
    counting = true;
    lcd.clear();
    lcd.print("Cars: ");
    lcd.print(cars);
  }
  if (sound < 200) counting = false;
}
Enter fullscreen mode Exit fullscreen mode

How It Works

// WF1 Run #044 - Basic Sound Detection
#define SOUND_PIN  A0

void setup() {
  Serial.begin(115200);
  pinMode(SOUND_PIN, INPUT);
}

void loop() {
  int value = analogRead(SOUND_PIN);
  Serial.println(value);
  delay(100);
}
Enter fullscreen mode Exit fullscreen mode

Troubleshooting

Problem Cause Fix
False triggers Ambient noise too high Adjust THRESHOLD value; add simple band-pass filter
Slow response Delay too long Reduce delay to 50ms or use interrupt-driven detection
Relay chatters Power supply noise Add 100uF capacitor across relay VCC and GND

Start Here

Affiliate disclosure: As an Amazon Associate, I earn from qualifying purchases.

KY-038 Sound Sensor
Arduino Nano
5V Relay Module
16×2 LCD I2C

Next Step: From Scene to Sensor, Without Writing Code

I offer a personalized interactive device design guide at Fiverr:

👉 https://www.fiverr.com/phd_hfchang/generate-an-arduino-interactive-prototypef

Tags: Arduino Sound Sensor Clapper Knock Detector

Top comments (0)