Clap Switch Sound Sensor DIY Kit NeoPixel Ring Display


The sketch for this project can be downloaded from my GitHub page here.

This project uses the Clap Switch described in my blog  here and shows how it can be used to step through the display modes in the Adafruit sketch included with the NeoPixel library. I am using a 16 LED NeoPixel ring in this project, if you are using a different number then the number of LEDs needs to be adjusted in the sketch. PIXEL_COUNT is the number of LEDs and PIXEL_PIN is the Arduino pin number connected to DI on the neoPixel ring (in this case Digital pin 5).

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);

You need to download and install the Adafruit NeoPixel library from here, I have uploaded my modified version of the Adafruit buttoncycler sketch on my GitHub page here. The original Adafruit sketch used a push switch to change the display, I modified the sketch to use the output from the Clap Switch. With the sketch (clapSwitch_buttoncycler.ino) loaded the NeoPixel display should be OFF. Clap your hands and the LED on the clap switch should go OFF. The NeoPixel ring will start flashing in one of nine patterns, it will continue until you clap again. The ring will stop at the end of the current cycle (which in the case of some of the rainbow patterns may take a few seconds). Clap to start the display running again.

The Sketch::

The sketch is modified from the Adafruit buttoncycler sketch, the code to operate from a push button has been removed and new code to monitor the clap switch has been added. My original code had to be modified slightly as it required two Claps to switch the display ON or OFF. The modified code uses one Clap to start the display and one to stop. The variable trigger is flipped between TRUE and FALSE, with the red LED on the clap switch showing the state (ON = trigger TRUE). The value is checked at the start of the main loop, however, with some of the displays that run for some time, trigger will not be checked until the current display has finished. This will result in a delay before the display is stopped.

The clap switch output turns the on-board LED, on pin 13, ON and OFF to indicate when the variable trigger has been read.



Please note that for illustration purposes the NeoPixel ring is shown as being powered by the Arduino. For normal use the NeoPixel ring should be supplied from an external stabilised 5 volt supply.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: