Clapper

Start 

The clapper will turn an LED on and off using a clap or loud noise. This project uses the analog sound sensor as a digital sensor. Analog sensors are used when the output values can have a wide range. For the clapper, we only care about large changes in the sound level and not the sound level itself.

Modules 

Gather the following parts to complete this project. If your LED module doesn't have an LED on it, then one must be inserted. The Creator Set comes with 3 light emitting diodes, or LEDs. Each LED has a positive side and a negative side. The positive side must be put in the position hole in the LED Modules. The positive LED side (leg) is the longer one. The positive hole on the LED Module has a small ‘+’ next to it. Putting the LED in backwards won’t permanently damage it, but it won’t work until correctly inserted.

LED ModuleLED Module

Parts

All Parts
All Parts
Sound
LED
Cable
PartQuantity
Sound 1
LED 1
Cable 2

Sound Sensor 

Take a cable and unwrap it. Plug one side into the sound sensor socket and the other into Analog socket A0.

All the parts you'll need
All the parts you'll need
Take a cable...
... and unwrap it
Plug one side into the sound sensor socket
... and the other into any Analog socket

Upload

Upload the following code. The example below uses the A0 analog pin. You can use any of them just remember to update the sketch.

Download file Copy to clipboard
1
2
3
4
5
6
7
8
9
10
11
12
13
//If you aren't using A0 as your socket change it below
#define sensorSocket A0

int val;

void setup() {
  Serial.begin(9600);
}

void loop() {
  val = analogRead(sensorSocket);
  Serial.println(val);
}

Observe

Open up the Serial Plotter and check out the what a normal sound level is. Try clapping or talking and watch the sound sensor react. You'll see a big jump in the level of sound. Find a value that the jump goes through but is far away from the ambient sound level.

A clap
A clap
A clap
A snap
A snap

Clapper 

Take a cable and unwrap it. Plug one side into the led socket and the other into any Digital socket.

Take a cable...
Take a cable...
... and unwrap it
Plug one side into the led socket
... and the other into any Digital socket

Upload

Upload the code below. This tutorial uses Digital socket 6. If you are using a different socket update the code after copying it. Set the trigger variable as that value you found from above.

Download file Copy to clipboard
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//If you aren't using A0 as your sound sensor socket change it below
#define soundSensorSocket A0

//If you aren't using pin 6 for your led socket change it below
#define ledSocket 6

int soundState;
int ledState;
int trigger = 600;

void setup()
{
  pinMode(ledSocket, INPUT);
  pinMode(ledSocket, OUTPUT);
}

void loop()
{
  if (analogRead(soundSensorSocket) > trigger) {
    soundState = 1;
  } else {
    soundState = 0;
  }

  ledState = digitalRead(ledSocket);
  if (ledState == 1 && soundState == 1) {
    delay(400);
    digitalWrite(ledSocket, LOW);
  }
  if (ledState == 0 && soundState == 1) {
    delay(400);
    digitalWrite(ledSocket, HIGH);
  }
}

Observe

Try clapping or making a loud noise. The LED will switch its states.

A clap
A clap
A clap
A snap
A snap
A finished project