Build a smart "Clapper" with SmartThings and Arduino

When my colleague @thegibertchan first set up his homemade “Clapper” in our office, I knew immediately that I had to learn how it was made.

The way it works is simple. A small microphone listens to two claps (within four seconds of each other) and it triggers a switch to turn on or off.

Gilbert even simplified the code so it uses the built-in LED in the our SmartThings Arduino Shield.

I will try to explain how to build it here.

You’ll need the following items:

Maybe the actual Clapper is less expensive, but this one is definitely more fun.

Step 1 - Pair the ThingShield with SmartThings

If you haven’t used Arduino before, make sure you have their software installed. Then download the ThingShield Library and copy the files to your sketchbook location, which is set in the Arduino IDE preferences. By default, the location should be:

Windows: My Documents\Arduino\libraries\SmartThings

OSX: ~/Documents/Arduino/libraries/SmartThings

To join the shield to your SmartThings hub, go to “Add SmartThings” mode in the SmartThings app by hitting the “+” icon in the desired location, and then press the “Switch” button on the shield. You should see the shield appear in the app.

Step 2 - Update the Device Type of the ThingShield

Log into http://graph.api.smartthings.com/ and click on “Devices”. Find your Arduino ThingShield then click on “Edit” on the bottom left of the page.

Select the “Type” drop down menu and choose “On/Off Shield”. Now click “Update”.

Now the shield will be able to accept on and off commands to control a switch. You can test it in the IDE by creating a new device type and selecting “On/Off Shield” from the dropdown. Here is the code for it.

Inside the app, your ThingShield should look like this:

Step 3 - Set up the Arduino with the Clapper code

Fire up your Arduino code editor and paste in this sketch. Read through it if you want. It’s essentially detecting the number of claps from the microphone and then firing on or off commands. After the first clap, the LED turns red and after the second clap it turns green.

One thing you might want to change is the offset variable. I was in a loud room so 250 worked best for me. In our office, that value is set to 100 since it’s pretty quiet there.

Attach your shield on top of your Arduino and grab your mini breadboard. Connect the microphone and attach the three wires like so:

  • Microphone OUT to Arduino A5
  • Microphone GND to Arduino GND
  • Microphone VCC to 5V

It should look exactly like this:

Our shield doesn’t have the best labeling, so you might have to eyeball the Arduino to see where you’re connecting wires.

Load the code onto the Arduino and test it out. Clap twice and you should see red and green LED lights if it’s working.

Step 4 - Connect the ThingShield to the smart outlet

You’re almost done. Go into the mobile app and tap the “+” button. Now tap the magnifying glass in the top right and search for the SmartApp called “The Big Switch”. I prefer this one but you can use any switch-to-switch app.

In the first section under “Where?”, find your shield, and in the second section under “Which?”, find the smart outlet. Click “Install”. It should look like this:

Once that SmartApp is installed, you should be able to clap twice to turn on and off the switch.

Here is Gilbert demoing V1 of the Clapper:

That’s it! Let me know if you build upon or improve it.

Big shoutout to Gilbert for helping me set this up and teaching me how it works.

6 Likes

@mager Making a clapper with Adurino is fun, but may not be a feasible option if I want it in every room. So as an alternative this is what I did,

I bought a cheap clapper that plugs into any wall outlet ($15) and then connected an old cell phone charger to it [The clapper operates two outlets - one with two claps and other with 3 claps]. The power from the cell phone charger (+5V) was connected to a relay ($1) and the contacts of relay were connected across a EcoLink Door/Window Sensor ($25) . So the total set up costed ~$41.

Then I wrote a smart app that can be used to turn a light on or off - It works both ways. If light is on and I clap - The light would go off, and on the other hand, if the light is off and I clap it would go on.

I find this extremely convinient since sometimes when my good night executes and I am still sitting in my living room, I dont have to open my phone or even get up to turn the lights back on - I just Clap! Clap! and the lights come back on :smile:

See the pic of my set up…Working on making a module that does this --> No need to have a bulky set up!!

@April @jody.albritton @alex @erenfra

2 Likes

This looks really cool! By why is the arduino needed at all. Couldn’t you simply hook a sensor up to a smart phone?

You’ve dredged up a very old thread. :slight_smile: These days, most everyone would implement this “clapper” functionality using voice commands from a very low cost Amazon Dot or Google Home Mini. Both of these solutions are much lower cost than the Arduino + ThingShield, have native ST integration, and offer much more than a simple clapper functionality (music, light control, dimming control, weather reports, executing routines, etc…)

PS - The ThingShield is no longer offered for sale by SmartThings. If you want an alternative, try out my ST_Anything project which supports numerous microcontrollers and network connectivity options.

© 2019 SmartThings, Inc. All Rights Reserved. Terms of Use | Privacy Policy

SmartThings; SmartApps®; Physical Graph; Hello, Home; and Hello, Smart Home are all trademarks of the SmartThings, Inc.