Arduino Clap Switch | Arduino Clap ON Clap OFF light | Clap Light Switch

Arduino Clap Switch:

Arduino Clap switch

Arduino Clap Switch | Arduino Clap ON Clap OFF light | Clap Light- In this article, you will learn how to make a Clap Light Switch using Arduino, a sound sensor, a one-channel relay module, and a 110/220Vac bulb. Guys, I am perfectly sure that almost 90% of electronics hobbyists, designers, and programmers might have essentially designed a clap switch in the start. Myself, when I was doing my engineering degree, I designed a clap light switch after learning basic electronics, and at that time I really felt thrilled and so ecstatic.


You will come across so many projects related to Arduino clap switch or Arduino clap ON, clap off a light switch. While some people tend to control light through the usage of a single clap or double claps purely through the application of electronic circuits by means of using 555 timer IC. So, it totally depends on you whether you want to use a programmable controller board like Arduino or you plan to design a clap switch using only electronic components.

If you go with a purely electronic circuit, then as a beginner future modifications will be very hard for you, as you will have to solder and desolder different electronic components. And obviously, if you go with the Arduino then you will only have to make changes in the code. Today I will practically demonstrate how an inefficient clap switch can be converted into an efficient clap switch, only by adding a few lines of code.

Anyway, without changing the hardware, we can control light using one clap, we can also control the same light using two claps, and we can also control light by using 10 or ever-larger number of claps. How can this be possible, I will explain it to you in programming. So, what I want to say is that it depends on you, how many claps do you want to use to turn ON or turn OFF the light switch.

Controlling a light or any other electrical load with one clap or two claps isn’t really hard, but, the challenging part is, how to make it efficient? Well, for this purpose I have written two codes, the first one is a simple code without the use of a timer and then in the other code I have added a timer. I will practically test it and you will see the difference by yourself.



If you design a single clap or two claps light switch without using a timer, it will turn out to be too inefficient. And I am saying this based on my personal experience. Because I performed some experiments. I designed a light switch without using a timer, which could turn ON / OFF owing to any random sound. Therefore, I was completely unsatisfied. Then, I used a timer, and my one clap light switch and two claps light switch became effectual to a great extent.

Arduino Clap switch

Through this Arduino clap switch, you are able to control any AC / DC load. As a beginner, you can start with a small LED, or you can use any small DC motor, or you can control 110 / 220 VAC light just like me.

Guys, if you want to use 110 / 220 Vac, pay due attention to the safety factor, because such a high voltage can even lead to fatal incidents. Protective gloves are necessary to be worn while using 110 / 220Vac, otherwise while conducting such experiments, somebody must accompany you as a precaution. Let’s now move on to start our practical demonstration.


Practical Demonstration:

First, I am going to start by controlling this light using a single clap without using a timer. As you can see I have powered up the Arduino and I have also connected 220Vac. Remember, never touch the relay contacts when the 220Vac is connected.

Arduino Clap switch

You can see that we can turn the light ON / OFF with the help of a single clap. However, I am not going to recommend a single clap light switch, because it is liable to turn ON / OFF through any random sound. Though the programming of a single clap light switch is pretty easy, however, it does not prove to be as efficient at all. Now let me demonstrate a single clap light switch with a timer.



Now you can see (watch the video given at the end of this article) how easily we can convert an inefficient type of clap switch into an efficient clap switch through the application of a timer. You can even use a single clap light switch in your room, and it is supposed to work perfectly well… Its programming has been undertaken in such a fashion, that Arduino monitors clap duration with the help of a timer, and besides this, it also counts claps. So, in case there are more than two claps, the light will not turn ON / OFF. Now, let me demonstrate a two claps light switch.

Arduino Clap switch

You can see that it is the same circuit, however, I have carried out some modifications in its programming. I have also used a timer this time round, which counts claps. And, besides this, it also monitors the duration between any two claps. When the first clap is detected and after this, the second clap is also detected after a certain duration, then the light will turn ON / OFF.

Arduino Clap switch

If you take just one clap and keep a relatively large interval in the second clap, then the light will not turn ON / OFF. So, you can see (watch the video tutorial given at the end) how we can successfully design an efficient clap switch by means of using Arduino and a KY-037 or Xcluma sound sensor.


This two-clap light switch seems quite practical to me because it is not affected and it doesn’t turn ON / OFF by any random sound. I am sure by now you might have got an idea of how does this system work. So, without any further delay let’s get started!!!

 


Altium Designer:

altium designer sponsor

Altium Designer is the world’s most trusted PCB design system. Altium Designer enables engineers to effortlessly connect with every facet of the electronics design process. Over 35 years of innovation and development focused on a truly unified design environment makes it the most widely used PCB design solution. With Altium Designer you can create PCB designs with an intuitive and powerful interface that connects you to every aspect of the electronics design process. Route it your way through any angle, tune for the delay, Push, Slide, and Walkaround faster than ever. Interact and collaborate with mechanical designers like never before in a photo-realistic, 3D design environment. If you want to get started with the Altium designer, you can click on the get started.


Amazon Links:

Arduino Uno:

Mega 2560:

Arduino Nano

Sound Sensor

Relay Module

220V AC bulb

12v Adaptor:

16×2 lcd

16×2 i2c lcd

Potentiometer

330-ohm resistors pack:

female DC power jack socket:

470uf capacitors:

5×7 cm Vero board:

female headers:

connection wires:

Super Starter kit for Beginners:

Jumper Wires:

Bread Board:

PCB plate:

Variable Supply:

Digital Multimeter:

Vero Board / stripboard:

Soldering iron kit:

Solder wire:

Wire Stripper:

wirecutter:

PCB small portable drill machine:

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!


Xcluma Sound Sensor:

 

Arduino Clap switch

KY-037 Sound Sensor:

Arduino Clap switch

Specifications:

Power supply voltage: +5V
Power-On LED light: LED1
Electret Condenser Microphone (ECM) sensor
AO = analog output provides a real-time output voltage signal of the microphone
DO = Digital output, output goes high when the intensity of the sound reaches threshold
Comparator Circuit: LM393
Comparator Output LED: LED2, on when sound reaches threshold
Built-in potentiometer can be used to adjust the DO threshold level
Mounting screw hole size: 3mm
Circuit Board Dimensions: 35mm x 15mm x 14mm (L x W x H, excluding connector and microphone)



Operation:

Pin + to +5VDC
Pin – to Ground
Pin AO to Microcontroller Analog Input (for analog program)
Pin DO to Microcontroller Digital Input (for digital program)
LED1 will illuminate when power is applied
Turn potentiometer counter-clockwise until LED2 turns off. This is the sound threshold. Then adjust to the appropriate threshold for your application.


Arduino Clap Switch Circuit Diagram:

Arduino Clap switch

 

In the above circuit diagram, I have an Arduino, a sound detector sensor, a relay module, and a 110/220Vac Bulb. I connected the digital output (OUT) of the KY037 with the digital pin D2 of the Arduino Nano. The sensor itself has an LED that lights up when sound is detected. The ground and VCC pins of the sound sensor are connected with the ground and 5v pins of the Arduino.

Similarly, I connected the relay module IN pin with the Arduino Nano D13 pin. For powering up the relay module I used the external 12Vdc power supply, the positive wire of the supply is connected with the relay module’s VCC, and the GND wire is connected with GND. Make sure the ground of the 12V power supply is also connected with the GND of the Arduino.


A neutral wire from the 220Vac supply is connected directly with the Bulb. While the Live wire from the 220Vac supply is connected with the Normally Open contact of the Relay module, whereas, the common contact of the relay module is connected with the other terminal of the bulb. So, by turning ON and turning OFF the relay module, the bulb can be turned ON and turned OFF.

Since we are using a relay, so we can use any load, it can be an AC load or DC load, make sure the load current rating does not exceed the relay contacts current carrying capacity. By the way, the type of the relay I am using is of the type SPDT “Single pole and double throw”. Now, let’s take a look at the programming.


Arduino Clap Switch Programming:

Arduino one Clap Switch programming:

I simply started off by defining the pins to which the sound sensor and relay module are connected. I also defined a variable for storing the relay status.

Inside the setup() function, I activated the Serial communication for debugging purposes. I set the Sensor as INPUT and relay as OUTPUT using the pinMode() functions.

Now, the actual code is inside the loop() function which runs repeatedly. So, first I read the relay pin status if it’s ON or OFF and store it in the variable relay_status. Next, I check if any sound is detected then toggle the relay pin. I am telling you one more time, that this code is very inefficient, but as a beginner, you can start with this code. Let’s take a look at the code of one Clap light switch using the timer.



Arduino one Clap Switch Programming using Timer:

I modified my previous code and I also defined some other variables. The code inside the setup() function remains unchanged.

First, we store the sensor status. For this we use the digitalRead() function. The type of sound sensor I am using gives 0 when sound is detected and gives 1 when no sound is detected.


This, first if condition checks if the sound is detected, 0 means sound, So, if the sound is detected then the Arduino checks if clap is also 0, then the Arduino starts counting the milliseconds using the millis() function, these milliseconds are stored in variables clap_start and clap_range and at the same time, the clap is also incremented.

If clap is already greater than 0 and millis() – clap_range >= 50 then store then current millis() function value in clap_range and at the same time we also increment the clap variable.

Then these other if conditions check the time duration and the number of claps. So, if in the same time duration only 1 clap is detected then turn on the relay otherwise turn off the relay and store 0 in the clap variable. Now, let’s take a look at the code of two claps light switch.


Arduino Two Claps Switch Programming:

This code is 99% similar to the one clap light switch code. The only difference is, as this time I am controlling the light using two claps so that’s why this time I am using if clap == 2 and that’s it. Now, you can easily modify this code to control a light using more than 2 claps.


Watch Video Tutorial:

Coming soon…

Recommended For You

About the Author: Fawad

My name is Shahzada Fawad and I am a Programmer. Currently, I am running my own YouTube channel "Expertstech", and managing this Website. My Hobbies are * Watching Movies * Music * Photography * Travelling * gaming and so on...

Leave a Reply

%d bloggers like this: