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
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
2016-08-01 18.32.35.jpg
2016-08-01 20.40.39.jpg
2016-08-01 18.33.47.jpg
2016-08-01 18.33.58.jpg
2016-08-01 18.35.33.jpg
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
Screen Shot 2017-08-02 at 10.52.13 PM.png
2016-08-01 21.26.11.jpg
2016-08-01 21.19.11.jpg
2016-08-01 21.18.54.jpg
2016-08-01 21.19.34.jpg
  1. 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
/**
 * 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
      }
  }
}

Video Demonstration

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!