Electronics
Electronics
SUBMITTED TO
Dr. VISHAL SRIVASTAVA
i
AKNOWLEDGEMENT
i
ABSTRACT
ii
LIST OF CONTENTS
NAME OF THE PAGE
TITLE NO.
Acknowledgment i
Abstract ii
Introduction 1
Components used 4
Methodology 4
Schematic Diagram 9
Result and discussion 12
Future use 13
References 14
iii
INTRODUCTION
1
In other words they “filter-out” unwanted signals and an ideal filter will
separate and pass sinusoidal input signals based upon their frequency. In low
frequency applications (up to 100kHz), passive filters are generally constructed
using simple RC (Resistor-Capacitor) networks, while higher frequency filters
(above 100kHz) are usually made from RLC(Resistor-Inductor-Capacitor)
components. The low pass filter thus only allows low frequency signals from
0Hz to its cut-off frequency, ƒc point to pass while blocking those any higher.
2
Arduino boards and software distribution by anyone. Arduino boards are
available commercially in preassembled form or as do-it-yourself (DIY) kits.
These electronic elements will be used to construct the clap based switch
involving of a preamplifier microphone which acts as an input to the Arduino
and a relay based switch which is connected to its output to turn ON/OFF the
DC fan.
3
COMPONENTS USED
1 x Arduino UNO
1 x Electret Microphone
2 x 2N3904 NPN BJT Transistor
1 x SPDT 12V Coil Relay
1 x 100R 1/4W Resistor
1 x 330R 1/4W Resistor
2 x 1K 1/4W Resistor
2 x 10K 1/4W Resistor
1 x 100K 1/4W Resistor
2 x 100nF Capacitor
1 x 1N4007 Diode
1 x 5mm Green LED
1 x 5mm Yellow LED
1 x SPST Tact Switch
Jumper Wires
Perf-board
METHODOLOGY
void setup()
{
Serial.begin(9600);
}
4
void loop()
{
int sensorValue = analogRead(A0);
// print out the value you read:
Serial.println(sensorValue);
}
On the serial plotter of the Arduino IDE , we can get the graph. Here you can
see what the audio signal looks like during the clap test:
You can see that the DC offset of the audio signal is about 175-180 units. The
peaks generated by the claps can go up to 185-190 units. The main purpose of
the Arduino code is detect these peaks and activate the relay when a double clap
is sensed.
5
Fig. 6: The preamplifier circuit built on breadboard for testing
Actually, sensing any double clap is not enough for the desired clap operation.
The interval between the two claps is also important. A timeout procedure is
applied in the code and a clap is discarded if it is not followed by another clap
in 1000ms.
A tact switch is used to adjust the threshold level of the clap action that will
be detected. There are three different threshold levels and the yellow LED
brightness changes depending on the selected level. The LED gets brighter
when the sensitivity gets higher.
When the software detects the double clap, it toggles the P1.1 output which
drives a green LED and a relay through a relay driver. The green LED
indicates the output status. The relay driver circuit based on the Q2 transistor
is required since the output pin current rating of the Arduino is limited to
6mA and not capable to drive the relay coil. A 1N4007 diode is placed
between the coil terminals to prevent the back EMF.
6
The Software
The software of the application is built in Arduino IDE and it is provided
below. The Arduino sketch includes comments to clarify each step.
CODE:
void setup()
{
//Serial.begin(9600);
void loop()
{
/*int sensorValue = analogRead(A0);
// print out the value you read:
Serial.println(sensorValue);*/
7
// Detect the first clap sound
if (analogRead(A0) > sensitivity) {
delay(100);
timestamp = millis();
do {
// Detect the second clap sound
if (analogRead(A0) > sensitivity) {
digitalWrite(P1_1, !digitalRead(P1_1));
delay(100);
break; // Second clap is detected, break the while loop
}
//Discard the first clap if the second clap is not received in 500ms
while(millis() < (timestamp + 1000));
if (sensitivity == 185) {
sensitivity = 182;
analogWrite(P1_2, 150);
}
8
else if (sensitivity == 182) {
sensitivity = 180;
analogWrite(P1_2, 250);
}
else if (sensitivity == 180) {
sensitivity = 185;
analogWrite(P1_2, 50);
}
delay(500);} }
Schematic diagram
9
Project Images
10
Figs 9,10:- Relay based DC Fan switch circuit
11
RESULT AND DISCUSSION
Whenever 2 successive clap sounds are made with a gap less than
1000 ms, we can observe from the Serial Plotter that the average
spikes that go during the clapping sounds is around 180-185. This
value may go up and down depending on the selection of microphone
and the background. Now the Arduino code is adjusted such that if
two successive spikes of value more than 182 is received by the
arduino at a time difference of 1000 mS, then the nature of the switch
is inverted, i.e. it is switched “ON” if it was originally “OFF” and
vice-versa. Now through the relay based switch, the circuit
comprising of BJT as a switch through the coil of the 12 V relay gets
closed when the Arduino returns “ON” and this in turn shifts the
moveable contact to short the Normally Open(NO) coil instead of the
Normally Closed(NC) coil which is connected to the supply of the DC
Fan making it on. The same gets inverted when the Arduino returns
“OFF”. The Relay is used here to avoid direct contact of 12 V load
with Arduino pins to protect the device.
This project has thus helped to know about the working of electret
microphone and how to use it to operate a 12 V DC fan using dual
clapping sound via a microcontroller device like Arduino.
12
FUTURE USE AND SCOPE
The range of the circuit can be extended over a large distance using a
required set of radio frequency transmitter and reciever to wirelessly
control electrical devices like fan,lights etc.
13
REFERENCES
14