Arduino Clap Switch (Clapper)
by OnTheBrink in Circuits > Arduino
19714 Views, 40 Favorites, 0 Comments
Arduino Clap Switch (Clapper)
Hello! Today I'm going to show you how to build a clap switch with a basic circuit and Arduino board.
Parts
For this project, you will need:
- Osepp sound sensor
- LED (1)
- Jumpers (6)
- 10k resistor
- Breadboard
- Arduino Uno
- USB B Cable
Check out a video I made on this project:
The Circuit
Alright, so this circuit is pretty simple. Here's hot you got to do:
- Plug in the sound sensor into your breadboard.
- Connect the ground pin of the sensor to a GND terminal of the Arduino, the Vin pin to the 5V bus of the Arduino, and the Analog pin to the A0 pin of the Arduino.
- Now you need to set up the LED. Hook up your 10k resistor to the Gnd pin of the Arduino and the cathode of the LED.
- After you've done that, connect a jumper for PWM pin 11 of the Arduino to the anode of the LED.
Once you have successfully built the circuit, upload the code.
The Code
Now that you have your circuit built, all you have to do is upload the code to the board. Open the Arduino IDE and upload this code, and Ouila, you now have a working Clapper. That's pretty much it for this project. Thanks for reading and, as always, Happy Making!
int micPin = A0; // microphone sensor input
int ledPin = 11; // select the pin for the LED int micValue = 0; // variable to store the value coming from the mic sensor
void setup() { Serial.begin(9600);
}
void loop() { // read the value from the sensor:
micValue = analogRead(micPin);
micValue = constrain(micValue, 0, 100); //set sound detect clamp 0-100 // turn the ledPin on
int ledbrightness = map(micValue, 0, 100, 0, 255);
Serial.print("incoming value from microphone =");
Serial.println( micValue);
analogWrite(ledPin, ledbrightness);
delay(100); }