DIY Snapper - Snap Activated Light - With ESP32
by TechMartian in Circuits > Arduino
4483 Views, 21 Favorites, 0 Comments
DIY Snapper - Snap Activated Light - With ESP32
![t.jpg](/proxy/?url=https://content.instructables.com/FKJ/9O8Q/J5V3S5TU/FKJ9O8QJ5V3S5TU.jpg&filename=t.jpg)
![output_G6C4EZ.gif](/proxy/?url=https://content.instructables.com/FBT/D61X/J5V3S0E0/FBTD61XJ5V3S0E0.gif&filename=output_G6C4EZ.gif)
This turns on and off an LED by listening to a snap sound. The sound board is calibrated to listen to a snap, and toggles an LED on and off.
The Sparkfun Sound Detector board is quite special and different from all the other sound detector boards available in the market since it possesses three different output pins, where the user can customize the type of signal they want to receive, through three options: Gate, Envelope, and Audio.
This snapper uses the Gate pin to process audio signals.
Tools and Materials
![2016-08-01 21.12.44.jpg](/proxy/?url=https://content.instructables.com/FS0/KAFK/J5V3S0ZF/FS0KAFKJ5V3S0ZF.jpg&filename=2016-08-01 21.12.44.jpg)
![2016-08-01 18.32.35.jpg](/proxy/?url=https://content.instructables.com/FHQ/GS4H/J5V3S11E/FHQGS4HJ5V3S11E.jpg&filename=2016-08-01 18.32.35.jpg)
![2016-08-01 20.40.39.jpg](/proxy/?url=https://content.instructables.com/F2E/7JF7/J5V3S11A/F2E7JF7J5V3S11A.jpg&filename=2016-08-01 20.40.39.jpg)
![2016-08-01 18.33.47.jpg](/proxy/?url=https://content.instructables.com/FKS/POTD/J5V3S11R/FKSPOTDJ5V3S11R.jpg&filename=2016-08-01 18.33.47.jpg)
![2016-08-01 18.33.58.jpg](/proxy/?url=https://content.instructables.com/FOT/LL3M/J5V3S11Q/FOTLL3MJ5V3S11Q.jpg&filename=2016-08-01 18.33.58.jpg)
![2016-08-01 18.35.33.jpg](/proxy/?url=https://content.instructables.com/FH4/KTDF/J5V3S11G/FH4KTDFJ5V3S11G.jpg&filename=2016-08-01 18.35.33.jpg)
![2016-08-01 21.13.39.jpg](/proxy/?url=https://content.instructables.com/FO1/RJUW/J5V3S10K/FO1RJUWJ5V3S10K.jpg&filename=2016-08-01 21.13.39.jpg)
- ESP32 Development Board
- Sound Detector Board
- 5mm LED
- 100Ω resistor
- 5 pieces of jumper wires
Circuitry
![Screen Shot 2017-08-02 at 10.48.18 PM.png](/proxy/?url=https://content.instructables.com/FBZ/R9WV/J5V3S0ET/FBZR9WVJ5V3S0ET.png&filename=Screen Shot 2017-08-02 at 10.48.18 PM.png)
![Screen Shot 2017-08-02 at 10.52.13 PM.png](/proxy/?url=https://content.instructables.com/FTZ/90DR/J5V3S0EY/FTZ90DRJ5V3S0EY.png&filename=Screen Shot 2017-08-02 at 10.52.13 PM.png)
![2016-08-01 21.26.11.jpg](/proxy/?url=https://content.instructables.com/F9U/B2MQ/J5V3S0ZX/F9UB2MQJ5V3S0ZX.jpg&filename=2016-08-01 21.26.11.jpg)
![2016-08-01 21.19.11.jpg](/proxy/?url=https://content.instructables.com/FMS/8ULH/J5V3S0ZU/FMS8ULHJ5V3S0ZU.jpg&filename=2016-08-01 21.19.11.jpg)
![2016-08-01 21.18.54.jpg](/proxy/?url=https://content.instructables.com/FUR/Z4OC/J5V3S0ZR/FURZ4OCJ5V3S0ZR.jpg&filename=2016-08-01 21.18.54.jpg)
![2016-08-01 21.19.34.jpg](/proxy/?url=https://content.instructables.com/FKU/9PJC/J5V3S0ZW/FKU9PJCJ5V3S0ZW.jpg&filename=2016-08-01 21.19.34.jpg)
- Connect the "Gate" pin from the Sound Detector Board to the pin D2 or IO24 on the ESP32.
The gate pin outputs a digital binary signal whether a relatively loud sound has been detected. We are using this pin as opposed to the envelope or audio pin so that programming will be simpler and that we will receive a cleaner signal from the sound board.
2. Connect the VCC pin from the sound detector board to the "3V3" pin on the ESP32 board.
3. Connect the GND pin from the sound detector board to the "GND" on the ESP32 board.
Coding
![Screen Shot 2017-08-07 at 1.24.21 AM.png](/proxy/?url=https://content.instructables.com/FX0/1GU0/J5Y816DJ/FX01GU0J5Y816DJ.png&filename=Screen Shot 2017-08-07 at 1.24.21 AM.png)
/** * Snapper by Tech Martian */ const int soundGate = 2; //declare the binary gate pin of the sound detector
const int ledPin = 5; // declare the LED pin.
int toggle = 0; // initialize a toggle variable to be not-toggled
void setup() { pinMode (soundGate, INPUT); // declare the soundGate pin to be a digital output pin pinMode (ledPin, OUTPUT); // declare the ledPin to be a digital output pin
}
void loop() {
if (digitalRead(soundGate) == HIGH) { // if a clap is detected
if (toggle == 0) { // check if the LED has already been toggled off digitalWrite (ledPin, HIGH); // turn on LED toggle = 1; // toggle to turn off next clap } else { // otherwise turn off LED digitalWrite (ledPin, LOW); toggle = 0; // toggle to turn on next clap } }
}
Downloads
Video Demonstration
![Snapper - Snap activated light](/proxy/?url=https://content.instructables.com/FE7/70NJ/J5V3S0D1/FE770NJJ5V3S0D1.jpg&filename=Snapper - Snap activated light)
Snap Snap! [Light turn on]
Snap Snap! [Light turn off]
Oddly enough, there's a lot of satisfaction that can be gained by watching this circuit work!