Automatic LED with Clap Switch DIY Kit
In this project, we are going to look at how to use a sound sensor/sound detector module to make a clap switch that activates an LED.
Requirements :
● Computer with an internet connection
● Download and install Arduino IDE
Components
Sound Sensor
5v Relay Module
LED lights
Arduino UNO
Arduino USB Cable
Jumper wires
9v Battery
Hardware
Getting
Started with
Arduino UNO
Arduino Uno
Although there are many types of boards from arduino . Here we are going to be using the Arduino UNO as it is the most commonly used one. The arudino UNO has :
- The operating voltage is 5V
- The recommended input
- voltage will range from 7v to 12V
- Digital input/output pins are 14
- Analog i/p pins are 6
- DC Current for each input/output pin is 40 mA
- Flash Memory is 32 KB
- SRAM is 2 KB
- EEPROM is 1 KB
- CLK Speed is 16MHz
Another wonderful feature of the arduino is the option of using a add-on boards to the arduino which comes as a module and they are known as “Shields”
Pin out diagram
Arduino UNO
Sound sensor
The sound sensor converts sound waves in air to electronic signals ,it works-out just like our ‘ear’.
The Sound sensor has 4 pins.
5V & GND
A0 (analog output)
D0 (Digital output)
(here we are going to use the analog output )
A0
What are the sound waves?
Sound waves are longitudinal waves that propagate through a medium (air, water, etc). The longitudinal waves create compressions and rarefactions in the air which then travels to our ear to hear.
Circuit Diagram
STEP 1: CONNECTING A THREE PIN DHT11
- Ky-037 VCC -> Arduino 3v3
- Ky-037 Signal -> Arduino Analog pin A0
- Ky-037 GND -> Arduino GND
STEP2: CONNECTING THE RELAY MODULE
- Relay VCC -> Arduino 5v
- Relay Signal -> Arduino Digital Pin 3
- Relay GND -> Arduino GND
wire up the Relay module‘s COM (common) and NO (normally open) to the LED and the 9V battery
The final circuit should look like this
Getting started with Arduino
Before starting any project, we need to interface Arduino with a computer. So we have to write and compile code for the Arduino to execute, as well as providing Arduino to function with the computer
Installing The Arduino Software Package On Windows
Download a version of Arduino software suitable for your version of Windows from Arduino website/superkitzs.com.After downloading, check the instructions below to install the Arduino Integrated Development Environment (IDE).
CONNECT YOUR ARDUINO UNO BOARD WITH AN A B USB CABLE; SOMETIMES THIS CABLE IS CALLED A USB PRINTER CABLE.
In order to program the board, the USB connection with the PC is necessary to program the board and not just to power it up. The Arduino Uno is capable of withdrawing power from either the USB or an external power supply. Connect the board to your computer using the USB cable. The green power LED (labeled PWR) should go on.
If you used the Installer, as soon as you connect your board the Windows – from XP up to 10 – will install drivers automatically
If the board is not properly recognized when the zip package is downloaded and expanded, please follow the procedure below.
- START menu> CONTROL PANEL MENU
- From the control panel, check for System and Security
- Select system
- Select Device Manager from the System window
- Select open port named “Arduino UNO (COMxx)”, under Ports (COM & LPT). If there is no COM & LPT section, check “Other Devices” for “Unknown Device”.
- Choose the “Update Driver Software” option by right-clicking on the “Arduino UNO (COmxx)” port
- Navigate to the “Browse my computer for Driver software” option.
- Choose the driver file named “arduino. inf”, located in the “Drivers” folder of the Arduino Software download (not the “FTDI USB Drivers” sub-directory). If you are using an old version of the IDE (1.0.3 or older), Choose the Uno driver file named “Arduino UNO.inf”, If an old version of the IDE (1.0.3 or older) is used
- Thus the windows driver installation is completed
Select your board type and port
Go to port>tools> serial device
here you select the serial device of the board. (ex. COM3/COM4/COMxx)
To find out which COM port your arduino board might be , you can always disconnect the arduino ,then open the port drop down tab. After seeing which COM port got disconnected , you can choose that after reconnecting the Arduino board
Press CNTRL + A and press DELETE on keyboard for clearing the Arduino IDE page
Upload the program
Now, click the “UPLOAD button“
and you will be able to see the RX and TX leds on the board flashing. If the upload is done successfully then the message “Done uploading ” will appear in the status bar.
Sketch Code
int time = 5000; //5 seconds now but you can change this number for how long the led needs to be ON
const int soundpin = A2; //the analog pin A0(sound sensor) to arudino A2
const int threshold = 525; // sets threshold for sound sensor (scale between 0-1024 for analog)
const int RELAY_PIN_1 = 3;
int state = 0; //relay pin is at digital pin 3
void setup() {
Serial.begin(9600);
pinMode(RELAY_PIN_1, OUTPUT); //initialize digital pin 3(relay) as output
pinMode(soundpin, INPUT);
digitalWrite(RELAY_PIN_1, HIGH);//initialise analog pin A2 as input
}
void loop() {
int soundsens = analogRead(soundpin);
Serial.println(soundsens);// read analog data from sensor
if (soundsens <= threshold && state==0)
{ digitalWrite(RELAY_PIN_1, LOW); //if Clapped , Then the LED is turned "ON"
Serial.print("CLAP DETECTED"); //show the temp in the serial montior (press shift+ctrl+m)
Serial.print("\n");//go to next line
delay(500);
state = 1;
}
soundsens = analogRead(soundpin);
if (soundsens <= threshold && state == 1) {
digitalWrite(RELAY_PIN_1, HIGH);
delay(500);//if the no CLAP , then the LED is turned off
state = 0;
}
}
Output
You should be able to see an output when ‘CLAPPED’