Components Used

  • Arduino Board
  • Relay Module
  • Sound Sensor
  • LED Strip 5M
  • LED Adapter
  • 9V Battery
  • F to F Jumper
  • M to M Jumper
  • Breadboard
  • Battery Cable

Description

In this tutorial we will learn how to control the Arduino Sound Sensor. So we will control our LED’s and Lamps with a clap. We will use a sound sensor and a relay module for this.

Specification

Maximum load:  AC 250V/10A, DC 30V/10A

Trigger current: 5mA

Working voltage: 5V

Module interface

 

VCC: positive power supply

GND: negative power supply

IN: can be high or low level control relay

Relay Output

NO: normally open relay interface

COM: Common Interface Relays

NC: normally closed relay interface

About sound sensor

This module allows you to detect when sound has exceeded a set point you select. Sound is detected via a microphone.

The sound level set point is adjusted via an on board potentiometer. When the sound level exceeds the set point, an LED on the module is illuminated and the output is sent low.

Min required – 30 min

Lines of Code

int sound_sensor = 4;
int relay = 5;

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;
  }
}