Sound Activated Switch –

I have already made some devices using SeeedStudio’s Seeeduino Nano microcontroller boards and Grove Sensors. In this post I am going to show you how to make a simple sound activated electronic switch on Arduino’s microcontroller platform.

Seeeduino Nano (v1.0)

The Seeeduino Nano is SeeedStudio’s compact version of the Arduino Nano. Something that makes the Seeeduino Nano stand out is the USB-C connector. Seeeduino Nano also has a Grove I2C connector built in. SeeedStudio offers a variety of add-on Grove sensor modules that are part of their Grove ecosystem. So, with the Seeeduino Nano, you can simply plug in one Grove I2C module in the dedicated I2C connector instead of having to figure out which pin to put a jumper wire in.

Getting started with Seeeduino Nano is as easy getting started with a regular Arduino. Seeed Wiki provides ample instructions on how to do that through the Arduino IDE’s Board Manager interface Seeeduino Nano is essentially a compact Arduino Uno which is fully compatible with the Arduino Nano.

Grove Sound Sensor (v1.6)

The microphone sound sensor – Grove Sound Sensor (v1.6) – is built around the popular dual-op amp IC LM358 and provides an analog signal output. The recommended operating voltage is 5V what makes it compatible to almost all 5V Arduino microcontroller boards. Maybe it works on 3.3V but I have not tried it yet.

To understand the functionality of the Grove Sound Sensor module, you must take a closer look into the schematic of the sensor module that shows you how the electronic components are wired together. The following picture shows the schematic of the Grove Sound Sensor (v1.6) module. This picture was originally taken from the web, but I polished it slightly for clarity.

As you can see, the main sound sensor component of the module is an electret microphone, which works together with the LM358 audio amplifier circuitry. The final output is an analog (counts on the level of the sound input) so it can be easily sampled and tested by a microcontroller.

More to the point, the LM358 IC does not have a true rail-to-rail (0V to Vcc) output. The datasheet specifies an output voltage swing of 0V to (Vcc – 1.5V). This means that when Vcc = 5V, the largest possible analog reading is around 715. To get a wider output range, one rail-to-rail op-amp should be used. If this is wrong, please teach me.

In the next session we will look at using the Seeeduino Nano and Grove Sound Sensor combination to build a sound activated timer switch. Before going into the project, keep in mind that you can use an Arduino Uno or Nano board in lieu of the Seeeduino Nano board, but you should stay with the Grove Sound Sensor module. Even though another sound sensor module which is ready to provide an analog signal output can be employed here, I will not get into that at this time.

Sound Activated Timer Switch Code

Since the Grove Sound Sensor produces a varying voltage, we can use the microcontroller’s analog-to-digital converter (ADC) to handle that voltage. So, here is a simple Seeeduino Sketch, also compatible with Arduino Uno/Nano, that reads the voltage from the sound sensor module connected to A0 which is then displayed on the Arduino IDE’s Serial Monitor. Further, the D13 output goes HIGH for a finite period when the sound level crosses a predefined threshold.


#define SOUND_IN A0 // Sound Input =

#define SW_OUT 13 // Switch Output =

#define THRESHOLD_VALUE 600 // Current
Threshold = 2.929V!

void setup()





void loop()


int sensorValue =



if(sensorValue > THRESHOLD_VALUE)



delay(3000);// D13 Delay = 3 Seconds




void pins_init()


pinMode(SW_OUT, OUTPUT);



void turnOnSW_OUT()




void turnOffSW_OUT()





This is a random Serial Monitor screen capture:

Below you can see a casual snap of my test setup (more on this shortly).

So now you have a crude sound activated timer device. What you can do next is to add a relay driver at the output of your setup to wakeup external electrical loads like warning lamps or alarms when there is a loud sound. The trigger input of the relay driver circuitry must be connected to the D13 pin of Seeeduino Nano.

As for the relay and its driver circuit, you can either build one yourself or buy a readymade “active-high input” relay module without taking pains – do it wisely anyway. Below is the picture of such a compact relay module – the Grove Relay ( The Grove relay v1.1 has an operating voltage of 5V while the next version v 1.2 is for 3.3V to 5V operation. The maximum switching current is 5A at 250VAC (maximum) switching voltage.

Sound Activated Toggle Switch Code (Clap Switch Code)

You can now use the same hardware setup you already built to create a simple clap-operated toggle switch. Below is the code for that interesting application.


long long int last_states = 0;

void setup() {

pinMode(13, OUTPUT);

pinMode(A0, INPUT);


void loop() {

last_states = last_states << 1;

if(analogRead(A0) > 600){ // Clap

if(last_states == 0){

digitalWrite(13, !digitalRead(13));







Anyone clapping his/her hands loud enough and not too far away from the microphone can activate the switching process. In this code, a simple trick is used to desist the clap switch from responding to an unwanted sound, say a loud music bit. So, the built in LED (D13 LED) will toggle (off-on-off-on…) only when the microphone picks up a gentle clap. Hope this make sense!

Grove Shield for Arduino Nano (v1.0)

Many readers may have already noticed that I built my quick test prototype in a different way. Of course, it was. I made it with a special Grove Shield because I had one in my hand at that time.

Moreover, the pretty useful shield helps us get rid of breadboard and jumper wires by pulling out the pins of the motherboard and expands to 8 Grove connectors. So, you can easily add more connector types to the Seeeduino Nano using the Grove Shield for Arduino Nano v1.0 ( .

When using this shield, it would be better to change the switch output from D13 to some other I/O of Seeeduino Nano, D6 for example, as it will help to keep the overall wiring neat and nifty.

On a different note, you can use a pricey sound level meter, or an Android SPL Meter App for acoustic measurements, while similar experiments. The spectrum of frequencies provided by a real time analyzer can help you to optimize your advanced audio electronics projects (see

Going Further…

Of course, you can create more projects by tweaking the basic ideas presented in this post. As a quick pointer, no dedicated filter has been used here so the switch will respond to big sounds like clapping that comes within a certain interval. But if a good bandpass filter is used then this issue could be avoided. The sound frequency of a hand clap is typically within the 2.2 to 2.8 kHz range (

Finally, like every other project, this one is not without its limitations and can be improved upon. So, suggestions are invited for further improvements on this basis. Keep inspiring me 😊

Tailpiece: The experiments presented in this article were performed using components sponsored by SeeedStudio last year. But this is a regular post with no commercial objectives!

Leave a Comment