AR-183ArduinoBeginnerPremium

Arduino Clap Lamp: Clap Twice to Turn It On, Twice to Turn It Off (KY-038 Sound Sensor + Relay)

Clap twice and the lamp turns on; clap twice again and it turns off. The KY-038 sound sensor catches the claps and a relay switches the lamp. A single clap or three claps in a row do not count, so talking, a slammed door or music leave the lamp alone. After each switch the code stops listening for a moment so the relay's own click is not taken for a clap. The Serial Monitor prints every clap and the lamp state.

0.0(0)
Arduino Clap Lamp: Clap Twice to Turn It On, Twice to Turn It Off (KY-038 Sound Sensor + Relay)
Walk into the room, clap twice and the light comes on; lie down, clap twice again and it goes off. The sound sensor sees a clap as a pulse and the code measures the time between two claps: too close or too far apart does not count, and a third sound cancels everything as noise. You learn to set the sensor threshold, read sound as pulses, build time windows without waiting and drive a relay safely.

Source Code

Premium Content

The source code, block version and FAQ of this project are open to Premium members.

  • All Project Code
  • Block version
  • Frequently Asked Questions