Clap Switch Circuit

Clap Switch Circuit

Introduction

This experiment demonstrates how to control a device, like an LED, using a clap sound detected by a microphone sensor.

Clap Switch Circuit

Components Needed

Circuit Setup

  1. Connect the microphone sensor to the 5V pin and GND on the Arduino.
  2. Connect the output pin of the microphone sensor to a digital input pin (e.g., D2) on the Arduino.
  3. Connect the anode of the LED to pin 13 and the cathode to GND through a 220-ohm resistor.

Ensure the microphone sensor is placed where it can detect the sound of a clap.

Clap Switch Circuit Setup

Code for Clap Switch Circuit

Upload the following code to your Arduino to toggle the LED when a clap is detected:


const int micPin = 2;   // Pin connected to the microphone sensor
const int ledPin = 13;  // Pin connected to the LED
int micValue = 0;

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(micPin, INPUT);
}

void loop() {
  micValue = digitalRead(micPin);
  if (micValue == HIGH) {
    digitalWrite(ledPin, HIGH);  // Turn LED on
  } else {
    digitalWrite(ledPin, LOW);   // Turn LED off
  }
}
            

Explanation

The microphone sensor detects sound. When a loud sound, like a clap, is detected, the LED turns on. Otherwise, it stays off.

Troubleshooting