Skip to main content

Building a Clap Sensor

You will build and program a sensor which reacts to your claps! It uses a microphone and a collection of capacitors, resistors and transistors to amplify the sound so that Arduino can detect it and react by turning a light on and off.

Find the Worksheet here: (PDF Document)Clap Sensor Worksheet

The Worksheet requires you to start with a basic template program. Click and drag to select the program below, then copy and paste it into the Arduino Software

Tutorial program

* Clap sensor template program
* Written by Stephen Pithouse on behalf of Warwick Volunteers

int currentSound = 0;
int toggleVal = 1;

void setup() {
pinMode(13, OUTPUT); //Make the Arduino's LED an output
Serial.begin(115200); //Let the Arduino and computer send messages to each other

void loop() {
for (int i = 0; i < 100; ++i) { //Take 100 sound readings
if (analogRead(0) > currentSound) { //Is this sound louder than the others
currentSound = analogRead(0); //Record this sound level

delay(1); //Wait a bit

Serial.println(currentSound); //Send the sound level to the Serial monitor window
currentSound = 0; //reset the recorded sound level