Build your own Clapper like switch [Homeyduino English version]

Build your own Clapper like switch [Homeyduino English version]

Who remembers this handy invention from the 80s-90s? The ‘Clapper’ switch. A switch that could turn devices on or off simply by clapping.

In the meantime surpassed by modern day technology, but at the time a futuristic piece of home automation. If you are not familiar with this, be sure to watch the legendary commercial:

As a project today we will be making a modern version of the ‘Clapper’ this time, because although it is an old concept, there are many modern applications for it. Certainly when you link it to Homey via Homeyduino , you can not only use it to turn devices on or off, but also use it to start or stop complete smart home ‘flows’.

This project will run on both the Homey Pro as well as on the Homey Bridge.

Supplies: on Amazon or Aliexpress:

If you prefer to buy on Aliexpress, you can use these links:

Connection diagram  

Follow the diagram below to connect the sensors to your board:

SensorWemos D1 Mini pin
Homeyduino Clapper Switch connection diagram Fritzing |
Connection diagram “Clapper Switch”

Arduino IDE

Install Arduino IDE, this is the software needed to put the code on your Wemos D1 Mini board. First we need to install the Homeyduino Library for this to work.

Open a new window, on the top bar click Sketch > Use Library > Manage Libraries.

Arduino IDE, first install the Homeyduino library |
Arduino IDE, first install the Homeyduino library

In the screen that opens, search for Homeyduino and then click install.

Look up: ESP8266 and install this as well.

Wemos D1 Mini board

You probably need to install this board before you can use it, so you can do this as follows:

Go to: Tools > Board > Board Management.

Install board Arduino |

In the search window you then search for Wemos D1 mini and install it.

Install board Arduino |

Homeyduino Code

When you have followed the steps above, open a new Arduino IDE screen and replace the text with the code below. Make sure you enter the correct network data here (see red text)

If you plan to place multiple Sound sensors in your house, it is important that you give them all a unique name, so that Homey recognizes them as different sensors.

// Code for Homeyduino made by Smart Home Blog 
// Take a look at my site for more Homeyduino en other Smart Home projects.
// Original code:

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <Homey.h>

int soundSensor = D2;
int claps = 0;
long detectionSpanInitial = 0;
long detectionSpan = 0;
boolean ClapState = false;

void wifi() {
  if (WiFi.status() != WL_CONNECTED) {
    WiFi.begin("<SSID>", "<PASSWORD>");
    uint8_t timeout = 30;
    while (WiFi.status() != WL_CONNECTED) {
      if (timeout<1) break;
    if (WiFi.status() == WL_CONNECTED) {
      //Print IP address
      Serial.print("Connected to WiFi! (");
void setup() {
  Homey.begin("Sound sensor"); // pick a name for your sensor
  pinMode(soundSensor, INPUT);
void loop() {
  bool clap_on = !digitalRead(soundSensor); 
  bool clap_off = !digitalRead(soundSensor); 
  int sensorState = digitalRead(soundSensor);
  if (sensorState == 0)
    if (claps == 0)
      detectionSpanInitial = detectionSpan = millis();
    else if (claps > 0 && millis()-detectionSpan >= 50)
      detectionSpan = millis();
  if (millis()-detectionSpanInitial >= 400)
    if (claps == 2)
      if (!ClapState)
          ClapState = true;
        Serial.println("Light on");
        else if (ClapState) 
          ClapState = false;
        Serial.println("Light off");
    claps = 0;

Check if correct board is selected

Before we write the code to the board, we have to check if we have selected the right board in Arduino IDE, otherwise you won’t get it to work. In our case that is the “LOLIN(Wemos) D1, R2 and Mini”

When this is all correct, we click on the arrow in the icon bar (second icon from the left) > Upload.

Choosing the right board in Arduino |
Selecting the right board in Arduino

Testing the code

Now that you have successfully uploaded the code, we will immediately test it. We do this by opening the Serial Monitor in Arduino IDE, click on Tools and then Serial Monitor or use the keyboard shortcut CTRL+SHIFT+M.

A screen will then open on which you can read the values ​​from the sensor. When you clap twice in a row this should be readable on the Serial Monitor. Also experiment with one or three claps, so you will see that the code is correct and will detect little or no false ‘claps’.

Serial Monitor Clapper Switch |
You can test whether the sensor is working properly via the Serial Monitor. It should show: light on or light off after you clap.

Linking it to Homey 

You can now link the sensor to Homey via the Homey app.

Link Homeyduino sensor to Homey |
Click on ‘Devices’
Link Homeyduino sensor to Homey |
Click on ‘Homeyduino’
Link Homeyduino sensor to Homey |
Click on ‘Arduino’
Link Homeyduino sensor to Homey |
Then click on ‘Install’
Link Homeyduino sensor to Homey |
Choose the right sensor, in our case ‘Sound Sensor’

Homey example flow

Homeyduino Clapper Switch Flow Setting |
Select as ‘Trigger’ “Boolean”
Homeyduino Clapper Switch Flow Setting |
And then enter ‘clap_on’ or ‘clap_off’ here. The first time the sensor detects clap, it switches the ‘clap_on’ and the second time ‘clap_off’.
Homeyduino Clapper Switch Flow |
The ‘clap_off’ ‘Trigger’ allows you to set an action that you want to perform when the sensor detects a second clap. To do this, enter ‘clap_off’ as ‘Boolean trigger’.


Hopefully you’ve got your own ‘Clapper’ like switch working. If you know of any fun, crazy, funny or special applications for this, please leave a comment.

More projects coming soon! Sign up here so you don’t have to miss anything!

Mike | Huisvanvandaag

Geef een reactie

Dit keer wederom een nieuwe Multi sensor en wel een combinatie van een CO2-, licht-…
Translate »