Build Your Own Alarm System with an LM386 Amplifier and an NPN Transistor - LEKULE

Breaking

21 Aug 2015

Build Your Own Alarm System with an LM386 Amplifier and an NPN Transistor

Build an analog booby-trap alarm system with an LM386 amplifier and an NPN transistor. This alarm system is activated by a trip sensor that sets off a screeching noise, alerting everyone and scaring off thieves.
Recommended Level

Beginner


Introduction

Let me paint a picture: a long-lost great uncle has just bequeathed to you a solid gold banana worth thousands of dollars. It's a hasty arrangement with no time to secure a proper safe, so it has to be hidden in plain sight on the kitchen counter with the other fruit. As you turn the lights off in your kitchen and go to bed, a crafty burglar slithers in through the shadows. Sneakily, the thief approaches the fortune banana and just as he swipes it, a screeching alarm hidden in the fruit basket goes off! The crook is caught and the banana is safe, thanks to a little bit of homemade analog circuitry.



Part NumberManufacturerDescriptionQuantityPrice (USD)
LM386N-1/NOPBTexas InstrumentsAudio Amplifiers LOW VLTG AUDIO PWR AMP1$0.98
SB4011NOMNKK SwitchesPushbutton Switches SPST OFF-(ON) STRT1$3.58
CLS0231MA-1-L152CUI Inc.Speakers & Transducers Speakers1$4.63
CF1/4CT52R333JKOA SpeerCarbon Film Resistors - Through Hole 33K ohm 5%1$0.15
CF1/4CT52R103JKOA SpeerCarbon Film Resistors - Through Hole 10K ohm 5%1$0.15
CF1/4CT52R102JKOA SpeerCarbon Film Resistors - Through Hole 1K ohm 5%2$0.30
2N3904BUFairchild SemiconductorBipolar Transistors - BJT NPN Transistor General Purpose1$0.19
84-4Keystone Electronics9V Battery Snaps & Contacts 9V BATTERY STRAP1$0.85
C320C104K5R5TAKemetMultilayer Ceramic Capacitors MLCC - Leaded 50volts 0.1uF 10% X7R1$0.32
EEU-FC1H680PanasonicAluminum Electrolytic Capacitors - Leaded 68uF 50V1$0.49
6LF22XWA/B12PanasonicConsumer Battery & Photo Battery INDUSTRIAL ALK 9V BOX OF 12/PRICED EA1$2.37

The Schematic:



The Breadboard:




The bread and butter of this project is the oscillator above. The LM386 datasheet demonstrates a similar oscillator in their "Typical Applications" section on page 6. They call their design a 1KHz square wave oscillator with R4 designated as 30k instead of the 33k resistor here. Not a huge difference but, as we'll see below, it does have a slight effect on the resulting frequency. This configuration is a class of circuit called a multivibrator -- it's pretty common to see them made of digital logic chips and 555 timers as well as op-amps. The resistors R1 and R2 connected to the non-inverting terminal of the LM386 form a positive feedback loop. This configuration allows for the device to have only two stable states: one in positive saturation and the other in negative saturation. This dual stability leads to what's known as a bistable multivibrator. When an RC circuit made of R4 and C2 are added to the negative feedback loop, this forces the bistable multivibrator to oscillate between states and turns the circuit into an astable multivibrator. The capacitor on the output pin, C1, is in place to isolate the speaker from DC to prevent damage.
The frequency of the oscillator can be determined by the following equation:
f = 1 / ( 2 * tau * ln( [1 + beta] / [1 - beta] ) )
where tau = R4 * C2 and beta = R1 / (R1 + R2)
I'm a really big fan of using Python's "Fancy Calculator" functionality so I made a super basic script to check my work and play with the variables:

Code

                    #!/usr/bin/env python3

from math import log as ln

R1 = 1000
R2 = 10000
R4 = 33000
C2 = 0.1e-6

tau = C2 * R4
beta = R1 / (R1 + R2)

f = 1 / (2 * tau * ln((1 + beta) / (1 - beta)))
print(f)
                  

 

So, from the equation, our circuit should yeild a frequency of 831 Hz. I managed to get my Digilent Analog Design board up and running in Linux so I took a got a shot of the waveform output going to the speaker:
815 Hz -- the perfect frequency for startling and obnoxious noises...
815 Hz is pretty close to the theoretical value and just so happens to be the perfect frequency for startling thieves and annoying everyone else. Substituting the datasheet's 30K resistor for R4, you can see that the equation yields a frequency of about 914 Hz which is close enough for TI to call it a 1KHz square wave oscillator. For reference, I found these equations in my copy of Sedra and Smith's Microelectronic Circuits (6E) in Chapters 17.4 and 17.5. Even though I've been out of shchool for a while, I consult that mostrous book (it's over 1400 pages!) all the time. Great resource if you can find yourself a copy.


The 2N3904 circuit above serves as a low-side switch for the oscillator circuit. When the switch is closed or the contacts are shorted, Vbe < 0.7V, which is the magic diode voltage for silicon. This keeps the transistor in cutoff mode, preventing the oscillator from turning on. However, when the switch is opened or contacts un-shorted, the transistor goes into saturation mode ("full on") since now the base-emitter juction is forward biased and the base-collector junction is reverse biased. In the case of the banana heist, pieces of copper tape were used to short the base pin to ground, but any sort of normally open momentary switch will do.

You can now sleep soundly, knowing your fruit is safe.

No comments: