|

Clap switch using Arduino 

Clap ON & clap OFF circuits at the hobbyist projects cover every possible area of automation, when we start building the circuit with the common components, most of the time they don’t have the accuracy, because of this reason clap switch circuit only limited into mini-projects or hobbyist projects category.

 

Clap switch using Arduino 220v
Clap switch using Arduino 220v

In this article, we introduce the clap switch using Arduino, at this point you had a question that, why I want to build this circuit with Arduino? Because we know Arduino is a prototyping board, we can easily build almost every circuit with Arduino.

Simple Clap Switch Circuit Using 555

Just like a miniature various, we can build a clap switch with Arduino, also different possibilities of circuit changes will be made at the clap switch circuit with a few changes in coding and external boards. 

 

Here we include three simple possible clap switch circuits using Arduino boards, explanations of circuit working and codes will be included in this article.

 

Clap ON & clap OFF LED using Arduino 

Clap switch using Arduino
Clap switch using Arduino

 

This Clap switch circuit having a single LED at the output, first, we want to know all are the components we needed to build this simple clap switch for led light.

Clap Switch For Lights On Off Circuit

Clap switch Components required 

1.   Arduino UNO board

2.   Sound sensor Arduino

3.   1kohm resistor

4.   LED

 

These are the components we need to build this circuit, before going to the circuit and working, we explain small information about the Arduino UNO boards and sound sensor Arduino.

Arduino UNO board 

arduino uno
arduino uno

 

 

 

 

 

 

 

 

 

 

 

 

 

The Arduino UNO is an open-source microcontroller board, building a project with such boards will give the beginner a perfect tutorial to make a product.

Clap Switch Circuit Diagram Using Transistor Bc547

The Arduino boards are known as the prototyping boards, for that function, the boards need multiple functional ports and code booting arrangements, utilizing such functions to customize the microcontroller board for any applications.

 

Power supply section: In the Arduino board, 5v, 3.3v, and GND are the power supply pins.

Digital input/ output pins: 14 digital o/p pins 

LED pin: pin13 is our LED pin

UART: PIN0

I2C: A4 pin and A5 pin

Special pin function 

Each of the pins below represents special function ports, they will be work for different operations, such as to generate oscillator pulse.

 

Serial ports: Tx (1) & Rx (0)

 

 External interrupts pins: In the board 2 and 3 are the pins represent external interrupts ports 

 

PWM pins: Pins such as 3, 5, 6,9,10, and 19 represents the PWM ports

 

SPI ports: 10, 11, 12, and 13 pins are SPI pins  

 

TWI (2 wire interface): SDA or A4, A5

 

Arduino sound sensor 

 

arduino sound sensor
arduino sound sensor

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Arduino sound sensor is a device used to detect sound then generate an equivalent electrical pulse and reflected on the Arduino boards.

 

It is a complementary device used with Arduino for sound-sensitive applications, it is a condenser mic but fully customizable and accurate.

 

The Arduino sound sensor board includes three pins +VCC, ground, and output pins.

 

  • The board having an output LED and a power LED.
  • Condenser mic 
  • Voltage comparator
  • Sensitivity adjustable potentiometer 

 

Clap switch using Arduino Circuit explanation and working

The circuit shown is a basic clap switch using Arduino, very few components used, Arduino UNO boards connected to 5v power supply and GND, then digital pin11 connected to LED with 220ohm driver resistor.

 

Then the Arduino sound sensor has three leads, two leads represent +VCC and GND, and the output terminal will be connected to analog pin0.

 

This is our circuit connections for Arduino based clap switch.

Clap switch using Arduino Codes 

 

After the connection is made, we have to write a little bit of code, in the Arduino platform, we know Arduino is an open-source platform, emulate the code in the Arduino ide is a simple process.

 

int sound_sensor = A0;

int relay = 13;

 

int clap = 0;

long detection_range_start = 0;

long detection_range = 0;

boolean status_lights = false;

 

void setup() {

  pinMode(sound_sensor, INPUT);

  pinMode(relay, OUTPUT);

}

 

void loop() {

  int status_sensor = digitalRead(sound_sensor);

  if (status_sensor == 0)

  {

    if (clap == 0)

    {

      detection_range_start = detection_range = millis();

      clap++;

    }

    else if (clap > 0 && millis()-detection_range >= 50)

    {

      detection_range = millis();

      clap++;

    }

  }

  if (millis()-detection_range_start >= 400)

  {

    if (clap == 2 )

    {

      if (!status_lights)

        {

          status_lights = true;

          digitalWrite(relay, HIGH);

        }

        else if (status_lights)

        {

          status_lights = false;

          digitalWrite(relay, LOW);

        }

    }

    clap = 0;

  }

}

 

Clap switch Output  

When we make a clapping sound, it will pick by the Arduino sound sensor, they convert the sound energy to electrical energy and forward towards the analog pin of the Arduino UNO board.

And the LED connected at the pin glow, as a reaction to clap sound.

Clap switch using Arduino 220v

 

Clap switch using Arduino 220v
Clap switch using Arduino 220v

 

This clap switch circuit using Arduino is capable to control home appliances, due to the Arduino relay we can control 220v AC.

 

Components required  

 

1.   Arduino UNO board

2.   Arduino sound sensor

3.   Arduino relay

4.   220v AC bulb

 

Arduino relay

 

Arduino relay
Arduino relay

 

An Arduino relay is a module used with Arduino boards, it is just like the normal relay, but these Arduino relay module boards include protection circuits and capable to upgrade 1 way to higher ways.

 

For this circuit we use 5v 1 channel relays, normally Arduino relay used to control higher voltage (120v – 240v) devices like fans, lights, and other home appliances.

 

Inside the relay is a 120-220v switch consists of an electromagnet, when the relay receives a high signal, the electromagnet becomes charged and move the contacts of the switch open or close.

 

For that purpose relay works with two types of electrical contacts normally open NO and normally closed NC, which one you use will depend on the switch turn ON or turn OFF.

 

Clap switch using Arduino 220v Circuit explanation

This circuit here is not different from the first, the only difference is the Arduino relay module used in the circuit, and due to the usage of this component we can control 220v appliances.

 

Moving onto the connections, Arduino boards operated in 5v, so 5v +VCC and ground is connected to the board, then we have Arduino sound sensor having three pins +VCC, ground and signal pin, signal pin connected to digital pin7 of Arduino.

 

And we have an Arduino relay having two sides, first side has an input pin, +VCC, and ground, an input connected to digital pin8 of the Arduino board.

 

On another side of the relay module we have normally open, common, and normally closed, we connect the 220v AC bulb between normally open NO and Common COM. 

 

Clap switch using Arduino 220v Codes

 

After the connection we have to write the Arduino code and injected it into the microcontroller, we have the option to modify the circuit and code for further upgrades.

 

#define sensorPin 7

#define relayPin 8

 

// Variable to store the time when last event happened

unsigned long lastEvent = 0;

boolean relayState = false;    // Variable to store the state of relay

 

void setup() {

  pinMode(relayPin, OUTPUT);  // Set relay pin as an OUTPUT pin

  pinMode(sensorPin, INPUT);  // Set sensor pin as an INPUT

}

 

void loop() {

  // Read Sound sensor

  int sensorData = digitalRead(sensorPin);

 

  // If pin goes LOW, sound is detected

  if (sensorData == LOW) {

 

  if (millis() – lastEvent > 25) {

    relayState = !relayState;

    digitalWrite(relayPin, relayState ? HIGH : LOW);

  }

 

  lastEvent = millis();

  }

}

Clap switch using Arduino 220v Output

When we clap in front of the mic, it will generate an equivalent electrical signal and passes towards the Arduino board, we have the option to adjust the mic sensitivity.

And after the signal reaches the Arduino board, a digital signal is passed to the Arduino relay, and normally open NO relay switches to a normally closed state and the 220v AC bulb becomes ON. 

 

Product designing 

In the light of this Arduino board-based project, we have a better understanding of prototyping, which will lead to product designing.

 

When we consider the clap switch circuit, they need more accuracy in its operation as a product.

 

Before going into a product project, Arduino boards are the perfect option to make a prototype, mainly they are open source, and we can use the whole Arduino products for free.

 

And the availability of complementary devices such as sensors and modules is enormous and the programming side is simple than any other programmer platform.

 

You can easily modify the circuit with the Arduino component to build any possible circuit, and also understand the useful changes made at the circuit to build it as a product.

Similar Posts

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *