Talking Electronics PIC Theory

Buy a kit


PIC Pinouts

A complete dialing alarm the size of a pack of cigarettes.
- its features will amaze you . . .
Page 1.

This is the lowest cost dialing alarm on the market and shows what can be done with an 8-pin microcontroller. The complete circuit is shown below. You cannot see all the features of this project by looking at the circuit - most of them are contained in the program. So, read on and see what we have included. . .

Click on the red dots to see the circuit working
Click on the 5
red dots to see each section operating

Dial Alarm-1 has a single input (although a number of sensors can be placed in parallel on the same input line). The circuit requires a trigger pulse to turn on a BC 557 transistor. This delivers power to the microcontroller. The micro starts to execute the program and outputs a high on GP2 to keep the "turn-on" circuit active. It also turns on the LED in the opto-coupler and this causes the line to be "picked up" via a high-gain Darlington transistor. The micro then dials two phone numbers and executes a series of events to alert the called party of an intrusion. The circuit also has a sensitive microphone with a high-gain amplifier. This is connected to the phone line when the alarm is triggered.
When the first number is dialled, a Hee Haw signal is sent down the line to alert the listener of an intrusion in the "target" area. Amplified audio of the room is then passed down the line. This signal is clear enough to detect conversations and/or movement in the target area and the listener can determine the situation. A second number is then called and the process is repeated. The two numbers are then called again and the alarm closes down. Simple but brilliant. The flow Diagram for the alarm is shown below:

Dial Alarm-1 Flow Diagram

Use Dial Alarm-1 as a "Back-Up" Alarm
This alarm has been developed in response to a number of recent large robberies reported in the news. Robberies are a constantly increasing crime, but very few are reported, unless they have a "twist." Recently, the robbers navigated the conventional alarm system and broke into the night safe in the Manager's office. The haul was quite significant and it's surprising such a large amount of cash was kept on the premises. The weakest link in most alarm systems are the PIR detectors, used to detect movement. It's a known fact that they are very easy to foil. It's so easy we are forbidden to print details of how to do it. But many thieves must be aware of the trick and that's why a back-up system is essential.
The cheapest back-up system is the use of the phone line. I know what you are going to say. Cutting the telephone line is an easy matter and offers little security. But finding the line in a premises is
not very easy and if there are two or more incoming lines, it's difficult to know which is connected to the dialler. Nothing is infallible, but for a lot less than $50 you can build this project and have a back-up to protect your property. 
The other advantage of our design is the "set and forget feature." The alarm is designed to ring your mobile and if you keep your phone beside you 24 hours a day, you can have this peace of mind, whether you are in your office, factory, holiday house or quietly dining at your favourite restaurant. 
You can protect any area where a telephone line can be installed. This includes houses-under- construction and outlying sheds. 
Talking Electronics has been producing security devices for more than 15 years and this project is a culmination of those years of experience.
The high-sensitivity amplifier is our development and comes from our highly successful Infinity Bug. This device connects to the phone line anywhere in the world and when the number is rung, the infinity
bug answers the call and lets you listen in to the activities in the room.  It's just like being there. We have used the same circuit in this project. When it is activated, you can easily work out if it has been triggered by staff, a family member or an intruder.  At least it prevents 90% of false alarms and offers enormous peace of mind. 
The secret lies in the placement of the triggering device.  We have provided only one input (trigger input). And there's a reason for this. The idea is to place the sensor near the target area or on an actual device, near the microphone.
For instance, it you are protecting a house, a thief always goes to the main bedroom and rummages through the drawers and cupboards. In this case a drawer that is never used should be wired with a magnetic switch (reed switch) or a movement detector such as a mercury switch.  These switches can be housed in a plastic case for easy screwing to a wall or door and are very reliable in operation. When the drawer is pulled out or the door opened, the switch is activated.  If you are protecting a wall safe, the switch is placed near the safe in a clipboard or picture so that when the board or picture is moved, the alarm is activated.  If a room is to be monitored, the switch is placed on the door so that when it is opened, the alarm is activated.  If other valuables are being protected (such as a VCR, scanner etc) a suggestion is to place a clipboard against the item.  The idea is the clipboard has to be moved to get at the "valuables." The clipboard contains a magnet and the switch is nearby. The clipboard keeps the switch open (or closed) and when it is moved, the alarm is activated.
The ideal arrangement is to avoid touching the clipboard, drawer, door or other "prop" during normal activities and this keeps the alarm activated at all times. 
Another suitable trigger device is a pressure mat.  This is something that can be avoided by "those in the know" and you can monitor an area during your absence.  The alarm can be used for other things too. You can determine when your business premises are opened up in the morning by placing a pressure mat or reed switch on a door. The same can apply to a particular room in your establishment. 
The purpose of this article is not only to produce the worlds smallest dialling alarm but also show you how the program runs so you can modify any of the routines to suit your own particular requirements.
The program can be re-written to dial only one number for two rings then hang up, or three rings, then again after 2 minutes or any combination to suit your requirements. Many mobile phones identify the caller on the display and you can keep track of the exact time of arrival and departure of different personnel.
The alarm can be programmed to monitor machinery and dial your mobile when a breakdown occurs. It can monitor water level or even your mail box. The possibilities are unlimited and it's just a matter of modifying the program to suit your own needs. 
But before you change any of the program you have to understand what the program does and be capable of changing the instructions without upsetting the operation of the alarm. 
Remember: A little knowledge is a dangerous thing.  Before doing any re-writing of the program you need to read our notes on programming and carry out one small modification at a time. 
This is really a very advanced project. The fact that is looks simple is the power of the microcontroller. It's taking the place of at least 10 chips in a normal alarm. 
Timing, tones and tunes have all been converted to instructions of a program. And the advantage of a program is the simplicity of alteration. A time-interval can be changed or a phone number altered with a few lines of code. Even new features can be added without the need for additional hardware. This project uses the '508A to its maximum and shows what can be done with an 8-pin microcontroller.  Before we go any further we must state that this project cannot be connected to the public telephone system. Only approved devices can be connected to the Public Phone System and any experimental device must be approved for experimentation and connected via a "telephone Line Separating Device." These are available from Altronic Imports for approx $100.
This is unfortunately the case and when we discuss connecting the project "to the line," we are referring to an experimental telephone system such as the one we have put together at Talking Electronics, to test and develop projects such as these. 
See the section "Testing The Project" on Page 2 for more details of the Test Circuit. It consists of 27v derived from 9v batteries, a 12v relay, a telephone and a socket, all in series. The 12v relay is included to limit the current. 

The circuit consists of 6 building blocks. 
1. The turn-on circuit. Click HERE to see the circuit working (or click the
red dot in the circuit above).
2. The tone detector. Click HERE to see the circuit working.         (   "        "      "    )
3. The DTMF wave-shaping circuit. Click HERE to see the circuit working. (   "    "    "  )
4. The high-gain audio amplifier. Click HERE to see the circuit working. (    "    "    "  )
5. The opto-coupler. Click HERE to see the circuit working.             (     "      "      "   )
6. The microcontroller.

The project is connected to a 6v supply at all times and to extend the battery life, the circuit turns off after use.  The current drops to less than 1uA and the only components connecting the battery to the project are the "turn-on" items. 
These consist of a BC 557 transistor, 2M2 turn-off resistor, 100k bleed resistor, and the top 100u electrolytic. The components to turn on the "turn-on" circuit are the sensing device such as a reed switch or mercury switch, the lower 100u electrolytic and 100k bleed resistor. The components to keep the turn-on circuit ON, are the microcontroller, diode and 100k separating resistor. 
It sounds quite complicated but here's how it works. The trigger device must be AC coupled to the project so the alarm only carries out one alarm operation and resets.  If the trigger device was directly coupled to the turn-on circuit, the project would never turn off, even though we could design the
program to carry out only one dialing operation. 
The sensing device must only give a TRIGGER PULSE to the circuit so it can reset after its operation, ready for another trigger pulse.
The only way to turn a reed switch activation into a pulse is to AC couple it. To pass the signal through a capacitor. This is what we mean by AC coupling - it means PULSE COUPLING or NOT DIRECT COUPLING. 
The way the turn-on circuit works is this: The top electrolytic is charged very quickly by connecting its negative lead to the negative rail of the project. 
This effectively charges the capacitor and supplies a voltage to the base of the BC557 to turn it on. 
Energy from the electrolytic passes into the base of the transistor and allows current to flow between collector and emitter leads. 
This flow of current activates the rest of the project. The microcontroller starts up and and the Watch-Dog Timer resets the program to the beginning after about one second (if the program did not start correctly) and takes over the job of turning on the BC 557, by taking GP2 low via the diode and 100k resistor. This action keeps the top 100u charged. 
Going back to the action of the tilt switch; instead of taking the top 100u directly to the negative rail as discussed above, it is taken to the negative rail via an uncharged 100u and this is similar to a "piece of wire" when it is in a discharged condition. It gets charged (to approx 3v) and the project turns on. 
If the reed switch remains closed and the micro goes through its set of operations and closes down,  the top 100u discharges while the lower charges to 6v. This will take a long time but eventually the transistor will turn off, even though the reed switch remains closed.
When the reed switch opens, the circuit cannot be re-activated until the lower 100u is discharged (or partially discharged) and this will take a long time through the 100k across it (and the upper 100u).  
What an enormously complex operation for such a simple circuit!
At the end of an alarm-cycle the micro is placed in a holing loop at Main8. To get the micro to re-start at address 000, the chip must see a definite LOW. This will naturally occur when the project is sitting for a long period of time, waiting for a trigger pulse. If you are experimenting, make sure the rail voltage has been completely removed before re-starting the project. 

The simplest building block in the project is the Tone Detector.  It is designed to detect any tone of about 500Hz on the phone line such as a whistle or DTMF. When this tone is detected, the alarm will turn off.  In this case the hardware does the detection. 
The circuit amplifies the signal on the phone line and this turns on a transistor. On the output of the transistor is a 4u7 electrolytic. It is charged via a 100k resistor. The stage sits with the collector at rail voltage, due to the biasing components keeping the transistor off. When a signal is delivered, the transistor turns on and the collector goes low. This causes the electrolytic to get discharged via the diode. At the same time, the electrolytic is getting charged via the 100k and if the frequency of the signal is rapid enough the electrolytic will be fully discharged and this will be detected by the micro as a LOW. 
Designing a project is a combination of good circuit and good program design. This section is a typical example. Originally, the signal was fed into the micro and a program detected the high's and low's. This was very unreliable. By adding the diode and electrolytic, the circuit does all the detection and the program only has to detect a high or low. Much simpler to implement and guaranteed to work.  

Dialing a phone number is carried out by sending a tone down the line. So that whistling can not carry out a dialing operation, the telephone company decided to make the tone impossible to produce "by accident."
Each dialing tone consists of two frequencies, sent at exactly the same time. These frequencies must be in the shape of a sinewave as the detecting device "locks onto" each of the frequencies at the same
time and produces a very-fast result.  The only problem is a micro can only produce a square wave. 
To convert a square wave into a sinewave, we need a wave shaping circuit. In essence this consists of charging and discharging a capacitor with a square wave and "picking off" the waveform. 
The charging of a capacitor is exponential but if we take the beginning of the curve and compare it to a sinewave, the two match up fairly closely.  
That's what we have done. We have charged a capacitor very quickly via a resistor so that it is nearly fully charged and then we begin to discharge it. The result is a fairly "peaky" sine wave. The waveform
is picked off the capacitor via a high value resistor and passed into a high impedance emitter-follower circuit. The two tones are produced separately by the micro and combined after wave-shaping. This reduces interference between one waveform with the other.
The component values have been especially chosen to produce a high amplitude signal, as the emitter follower transistor does not increase the amplitude, only the current-driving capability into the phone
The choke has been placed in the emitter of the driver transistor to have the maximum effect on the signal. When it was placed in the collector, it had no noticeable improvement.
The effect of a coil (choke) is to "smooth out" the shape of a waveform. It does this by taking some of the energy from a rising signal and delivering it during a fall in amplitude. This makes the "peaky" waveform "rounded." 
The coil actually produces a negative feedback on the circuit. You already know that a rise or fall in amplitude on the base of a transistor will create a fall or rise in the collector voltage.  Well, the same thing happens if you keep the base fixed and raise or lower the voltage on the emitter. The voltage on the collector rises or falls by a larger amount. This is due to the gain of the transistor. 
The improvement made by the choke increased the dialing accuracy from 80% to 100%. 
The improvement in the waveshape could not be detected on a CRO so it's not always possible to get test equipment to help you with a design. Sometimes it's your knowledge of componentry that gets you through.
Getting the DTMF generator to work was one of the most difficult parts of this project as the tone detectors at the exchange are very "exacting" and critical. To improve the chances of instant recognition, we have included a crystal in the circuit. 
Although we have generated the tones in the micro, there are tone-generating chips and these have a 16 tone capability, with only 12 tones used on the telephone keypad.  The additional 4 tones are shown on the diagram below as A, B, C and D. The two symbol keys are called "star" and "hash."
The extra tones can be generated by the program but are not needed in our situation. In the early days of DTMF, the 4 extra tones were used by the telephone companies to route the calls and create call-charges. The basis of defeating these charges was through "blue boxes" held to the mouth-piece, while creating the extra tones. Things have been tightened up since then. 

The high gain amplifier is the two-transistor amplifier at the bottom of the circuit. It is used to pick up sounds in the target area during an alarm activation. It is directly coupled to the phone line via a bridge. The bridge delivers the correct polarity to the circuit, irrespective of the polarity of the phone line and the change in impedance of any of the components connected to the phone line will result in a signal being sent down the line. The output stage of the high-gain amplifier is one of these components and it is biased ON via a 220k resistor. This turns it ON only very slightly, so that the audio signal will drive it correctly. The "load" for the transistor is all the other components connected in series with the transistor and this includes the "holding-in" relay and any isolating transformer at the exchange. The components across the transistor do not form part of the "wanted" load and they actually reduce the output. However they must be included as part of the DTMF section.  
So, we have a two-transistor high-gain amplifier. A 20mV signal from the microphone will produce a 1,000mV signal on the collector of the first transistor and this will be passed to the output transistor.
The amplitude of the waveform across the output transistor is about 2 -3v. 
The unusual layout of the circuit may be confusing. The pre-amplifier section is powered from the 5v supply while the output transistor is driven from the phone line.  Although the voltage on one side of the 100n on the base of the output transistor is different to the other side, this does not affect the operation of the circuit. It is the AC signal through the 100n that is amplified by the buffer (output) transistor and providing the negative rail of the pre-amplifier and the emitter of the buffer transistor are fixed and rigid with reference to one another, no motor-boating (instability) will occur. 
The audio amplifier is gated "off" when the DTMF tone is sent down the line. The supply for the pre-amplifier is obtained from an output of the micro and this line goes high before the tone is transmitted. This charges the 47u and the voltage across the BC 557 is very low. Without the ability to amplify the audio in the target zone, the signal on the phone line will not be upset when the DTMF is transmitted. 

The opto-coupler is the device that does the job of a normal phone. In other words it "picks up the phone line." The micro outputs a LOW on pin 5 (GP2) as soon as the program is activated by the mercury switch and this keeps the "turn-on" circuit activated. This line also goes to the opto-coupler and a LED in the opto-coupler is also turned ON. The illumination of the LED turns on a phototransistor inside the opto-coupler and the resistance between collector and emitter leads of the photo-transistor is reduced and this pulls the base of a Darlington transistor towards the positive rail. 
The Opto-coupler can be connected directly to the phone circuit but the transistor must be turned on much harder. This requires the LED in the opto-coupler to be driven much harder and puts a very heavy demand on the battery. 
At the conclusion of each "telephone call" pin 5 goes HIGH and this is the same as "hanging up the phone." The electrolytics in the "turn-on" circuit will keep the micro active during the short period of time between phone calls. 

The heart of the project is the microcontroller. It is an 8-pin chip with 5 input/output lines and one output-only line.  The output lines change from low-to-high-to-low very quickly and each line can deliver a maximum of 25mA. 
The program inside the micro determines what happens on each of the lines and the parts around the micro are merely interfacing components. In other words they adapt or modify or amplify a signal to suit the micro or phone line.  
The micro never stops "running" and it executes instructions at the rate of one million per second       (1 MIPS). 
You need to understand PIC language to program the micro and Talking Electronics has produced 
PIC Programming
pages on the web to help you develop a program.  

Before designing any project for operation on the phone line, you have to understand how the 50v line operates. It's not like a normal 50v power supply. You cannot simply design something for 50v and connect it to the phone line. 
The phone line is actually a 50v battery (actually slightly higher than 50v - about 52v. However some of the newer phone systems deliver a voltage as low as 35 - 40v) with a 1k relay in series with one line. When you short the two phone lines together, the relay pulls in to indicate the handset has been lifted.  Under these circumstances the current flowing through the line will be 50/1,000 = 50mA.  The relay will drop out at 15mA and so you can add devices to the phone line until the current falls to about 15mA without the line dropping out. It is best to keep the current high to prevent the line dropping out. 

Most phones drop about 8 - 12v across them when they are working and this voltage can be used by the phone for the amplifying circuits, tone generators etc. Our design has a separate supply, however it could be designed to use the phone voltage, if you wish. The 10v across the BC 337 audio output transistor gives the transistor plenty of voltage for a good output waveform.  The audio is sensitive enough to hear a clock ticking in the target area. 

More than one trigger device can be fitted to the alarm provided they are connected in parallel as shown in the diagram below. 


Go to: Page 2