0

Make a Clap-Activated Light with Arduino and a Sound Sensor

Clap on, clap off: build a clap-activated light with Arduino and a sound sensor, switching a lamp with a relay. Full wiring and code included.

A clap-activated light is a fun, impressive project: clap your hands and the light turns on; clap again and it turns off. It uses a sound sensor to “hear” the clap and a relay (or LED) to switch the light — a great science-fair build.

LM393 sound sensor module
The LM393 sound sensor “hears” your clap.

What you’ll need

How it works

The sound sensor has a tiny microphone and a comparator. When a sound is louder than a threshold (set by the on-board trimmer pot), its D0 pin goes HIGH for an instant. The Arduino watches for that pulse and toggles the relay — so each clap flips the light between on and off.

Wiring

  • Sound sensor VCC→5V, GND→GND, D0→D2
  • Relay VCC→5V, GND→GND, IN→D8
  • Wire your lamp through the relay’s COM and NO terminals.

Safety: if you switch mains-voltage appliances, have an adult help and be very careful — for learning, an LED on D8 is perfectly safe.

The Arduino code

int soundPin = 2;   // sound sensor D0
int relayPin = 8;   // relay IN (or an LED)
bool lightOn = false;

void setup() {
  pinMode(soundPin, INPUT);
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, LOW);
}

void loop() {
  if (digitalRead(soundPin) == HIGH) {   // clap detected
    lightOn = !lightOn;                   // flip the state
    digitalWrite(relayPin, lightOn ? HIGH : LOW);
    delay(300);                           // ignore the clap's echo
  }
}

Turn the trimmer pot on the sound sensor until a normal clap triggers it but background noise does not.

Want a ready-made version? Our DIY Sound-Operated Light STEM kit puts this whole project on a neat wooden stand — ask us about it on WhatsApp.

Get the parts

Everything for this project is in stock at Smart Home | Arduino Corner — Shaheen Market, DAV College Road, Rawalpindi — with fast, cash-on-delivery shipping across Pakistan. Get the sound sensor and a relay module to build your own. Browse the full store →

Leave a Reply

Your email address will not be published. Required fields are marked *

Chat with us on WhatsApp