WHAT'S NEW?
Loading...

Light control simulated by clapping using Atmega 168





Clap to switch the light on and off! This is a very simple atmega168 based project which uses a microphone as a sensor to sense the sound produced through clapping and toggles the output(here the CFL).


Equipment that you will require are:

1.    Atmega 168
2.    Relay 12v
3.    Microphone
4.    Capacitor 1uF
5.    Resistor 3kohm {*depends upon the microphone )
6.    Transistor 2n2222
7.    Resistor -2---330ohm
8.    Wires


Circuit Diagram:




Code:

C code compiled in winavr

Explanation:

Before going to the explanation of the codes, I would like to explain how and why the various resistance used in circuit are chosen.
First of all let us take a look at the microphone. If we connect a multimeter to its ends in resistive mode we will find that its resistance changes on depending on the sound that it receives. If we connect it to a constant resistance and a dc voltage source in series, then we would get a varying voltage at the junction of the resistance and mic. That voltage is fed to the ADC and thus our MCU is able to sense the change in the sound produced (like clapping, whistling, screaming etc.). The value of the resistance should be comparable to the resistance of the microphone.
Now coming to the output. The output pin has 5v output. This voltage is not sufficient for driving a relay of 12v rating. One option is to use a 5v relay but that would increase the power consumption (in mA). Best option is to use a transistor and connect the base terminal to the output pin. This would reduce the power consumption to uA. Also an amplified voltage can be given to the relay for its proper operation. So we have used the transistor. Now important point is why do we require a relay? Appliance we are going to operate works on 220v ac. How do you expect to drive it with just 5v that too dc. Here comes the role of relay. It allows you to switch an ac dc high voltage through small dc voltage.
Finally coming to the logic and the coding.  The analog value of the sensor is calibrated linearly on a 10bit scale. A threshold value is marked depending upon the change in the voltage across the sensor on clapping. Value above the threshold value is set to 1 and below is 0. It is compared with the previous value (difference) which is initially set to 0. Following it, is an if condition tester which tests for the difference greater than 0 and toggles the output pin. This ensures that the value doesn’t toggle when the value returns from high value to low value. Finally the present value of adc is assigned to the previous value and the loop goes on.
* Capacitor in the diagram is in series with the sound sensor as described in its datasheet to reduce the noise.


Video:




2 comments: Leave Your Comments

  1. Good Work!!!
    One suggestion it would be better if you give some video explanation of the circuit and its working

    ReplyDelete
  2. Sure! will try to experiment this next time. Thanks!!

    ReplyDelete

Suggestions and Comments are welcome!