freezer alarm

5
Copyright © 2008, Wimborne Publishing Ltd (Sequoia House, 398a Ringwood Road, Ferndown, Dorset BH22 9AU, UK) and TechBites Interactive Inc., (PO Box 857, Madison, Alabama 35758, USA) All rights reserved. The materials and works contained within EPE Online — which are made available by Wimborne Publishing Ltd and TechBites Interactive Inc — are copyrighted. TechBites Interactive Inc and Wimborne Publishing Ltd have used their best efforts in preparing these materials and works. However, TechBites Interactive Inc and Wimborne Publishing Ltd make no warranties of any kind, expressed or implied, with regard to the documentation or data contained herein, and specifically disclaim, without limitation, any implied warranties of merchantability and fitness for a particular purpose. Because of possible variances in the quality and condition of materials and workmanship used by readers, EPE Online, its publishers and agents disclaim any responsibility for the safe and proper functioning of readerconstructed projects based on or from information published in these materials and works. In no event shall TechBites Interactive Inc or Wimborne Publishing Ltd be responsible or liable for any loss of profit or any other commercial damages, including but not limited to special, incidental, consequential, or any other damages in connection with or arising out of furnishing, performance, or use of these materials and works. READERS’ TECHNICAL ENQUIRIES We are unable to offer any advice on the use, purchase, repair or modification of commercial equipment or the incorporation or modification of designs published in the magazine. We regret that we cannot provide data or answer queries on articles or projects that are more than five years’ old. We are not able to answer technical queries on the phone. PROJECTS AND CIRCUITS All reasonable precautions are taken to ensure that the advice and data given to readers is reliable. We cannot, however, guarantee it and we cannot accept legal responsibility for it. A number of projects and circuits published in EPE employ voltages that can be lethal. You should not build, test, modify or renovate any item of mainspowered equipment unless you fully understand the safety aspects involved and you use an RCD adaptor. COMPONENT SUPPLIES We do not supply electronic components or kits for building the projects featured; these can be supplied by advertisers in our publication Practical Everyday Electronics. Our web site is located at www.epemag.com We advise readers to check that all parts are still available before commencing any project. To order you copy for only $18.95 for 12 issues go to www.epemag.com www.epemag.com

Upload: rik206

Post on 02-Feb-2016

215 views

Category:

Documents


0 download

DESCRIPTION

Freezer Alarm, electronic proyectfrom EPE Online

TRANSCRIPT

Page 1: Freezer Alarm

Copyright © 2008, Wimborne Publishing Ltd (Sequoia House, 398a Ringwood Road, Ferndown, Dorset BH22 9AU, UK)

and TechBites Interactive Inc., (PO Box 857, Madison, Alabama 35758, USA)

All rights reserved.

The materials and works contained within EPE Online — which are made available by 

Wimborne Publishing Ltd and TechBites Interactive Inc — are copyrighted.  TechBites Interactive Inc and Wimborne Publishing Ltd have used their best efforts in preparing these materials and works. However, TechBites Interactive Inc and Wimborne Publishing Ltd make no warranties of any kind, expressed or implied, with regard to the documentation or data contained herein, and specifically disclaim, without limitation, any implied warranties of merchantability and fitness for a particular purpose.  Because of possible variances in the quality and condition of materials and workmanship used by readers, EPE Online, its publishers and agents disclaim any responsibility for the safe and proper functioning of reader‐constructed projects based on or from information published in these materials and works.  In no event shall TechBites Interactive Inc or Wimborne Publishing Ltd be responsible or liable for any loss of profit or any other commercial damages, including but not limited to special, incidental, consequential, or any other damages in connection with or arising out of furnishing, performance, or use of these materials and works.  READERS’ TECHNICAL ENQUIRIES 

We are unable to offer any advice on the use, purchase, repair or modification of commercial equipment or the incorporation or modification of designs published in the magazine. We regret that we cannot provide data or answer queries on articles or projects that are more than five years’ old. We are not able to answer technical queries on the phone. 

PROJECTS AND CIRCUITS 

All reasonable precautions are taken to ensure that the advice and data given to readers is reliable. We cannot, however, guarantee it and we cannot accept legal responsibility for it. A number of projects and circuits published in EPE employ voltages that can be lethal. You should not build, test, modify or renovate any item of mains‐powered equipment unless you fully understand the safety aspects involved and you use an RCD adaptor. 

COMPONENT SUPPLIES 

We do not supply electronic components or kits for building the projects featured; these can be supplied by advertisers in our publication Practical Everyday Electronics. Our web site is located at www.epemag.com 

We advise readers to check that all parts are still available before commencing any project. 

 

To order you copy for only $18.95 for 12 issues go to www.epemag.com 

www.epem

ag.co

m

Page 2: Freezer Alarm

�������������������������� ������������

SOME modern freezers contain alarmswhich sound if you leave the dooropen and allow the internal space to

warm up. However, they do not work if thefreezer suffers a power failure, which is abit of a drawback.

Making a temperature-sensitive circuitwhich can sound an alarm is not too diffi-cult (a typical example was the Ice Alert inFeb ’01) but what is required here is a low-cost circuit which can run on batteries fora very long time.

This design uses a circuit based on aPIC, using a feature about which little hasbeen written, namely the ability to send itto sleep! The circuit is extremely simple,and the software uses several techniqueswhich could be useful in other projects.

��������The design uses the “baby” of the PIC

family, the PIC12C508. This is an extra-ordinarily versatile device, and in its OTP(one-time-programmable) version is veryinexpensive. It is housed in an 8-pin d.i.l.package (see Fig.1), and has the same setof 33 RISC instructions as its bigbrothers.

Two pins are used for power (between2·5V and 5·5V), the remainder can be con-figured as five I/O (input-output) pins andone input-only pin.

An in-built oscillator runs at 4MHz – i.e.an instruction every 1�s. It has 25 bytes of

data RAM available, program memory is512 bytes. There are two internal timers,one of which is a “Watchdog”, and it candrive output devices with currents up to50mA.

This little PIC is extraordinarily versa-tile, and for many applications providesadequate microcontroller power. Ofcourse, the more powerful versions such asthe PIC16F84 can be programmed tooperate in just the same way with fewchanges to the software, but why use asledge-hammer to crack a nut?

�������� �������If you are the sort of person who enjoys

the challenge of constructing complex cir-cuits, you will be disappointed! The com-plete circuit contains only five compo-nents, as shown in Fig.2. The clever stuff,of course, is provided by the PIC.

The temperature sensor used is a low-cost disc thermistor, R1, which can beattached via a length of 2-core cable. Asmall preset variable resistor, VR1 isused to set the operating point, the tem-perature threshold at which the alarmsounds.

Capacitor C1 is used to make the inputcircuit time-dependant, as described in thenext section. For the alarm, a piezosounder (WD1) is used because it canmake a relatively large amount of noisewhilst using a very small amount of elec-trical power. The whole circuit will conve-niently run off a 6V battery.

���������� Thermistors are basically temperature

sensitive resistors – normal n.t.c. (negativetemperature coefficient) ones have a highresistance when cold, and a low resistancewhen hot, and the change of resistance is avery large effect.

�������

�����

������������������������������������������������ ������ ���������������������!�������"���#

����������������

316 Everyday Practical Electronics, May 2002

Fig.1 (above). Thepin diagram for thePIC12C508 micro-controller.

Fig.2 (right). Circuitdiagram for theFreezer Alarm.

The prototype Freezer Alarmwas built on a printed circuitboard, however, the design isso simple that a small pieceof stripboard is used in thisarticle.

www.epem

ag.co

m

Page 3: Freezer Alarm

An easy way to test a thermistor is toplace it in a freezer (which is normally atabout –18°C) and connect it to a multime-ter via leads of suitable length. After a fewminutes the thermistor will reach the tem-perature of the freezer, and with the meteron its resistance range you will be able tomeasure the approximate value of resis-tance at this temperature.

The thermistor used here has a resis-tance of around 1k� at room temperature(see Table 1). Other types of n.t.c. thermis-tor could equally well be used with minoralterations to the circuit which areexplained later.

The microcontroller circuit needs to“measure” this resistance in order to eval-uate whether the thermistor is too warm –we do not need to know its actual value,just whether it is higher or lower than apreset value. This can conveniently bedone by comparing the resistance of thethermistor to that of a preset resistor, VR1.

The PIC12C508 is basically a digitaldevice, so we need a cunning plan to makeit capable of measuring resistance. Themethod is to use the PIC as a timer whichcan count how long it takes a small capac-itor C1 to charge up to a certain voltage.

If we consider a very simple circuit(Fig.3) consisting of just a capacitor C anda resistor R, we can see that if the switch isclosed, the voltage V across the capacitoris zero and it is uncharged. As soon as theswitch is opened, the capacitor charges viathe resistor, and the voltage rises along anexponential curve (Fig.4).

In our circuit, we time how long it takesto go from zero to the logic threshold ofthe PIC (the point at which a logic 0changes to a logic 1), which is about 3·0V,say.

The mathematics of this chargingprocess produces a very simple relation-ship, namely that the time taken to reach acertain voltage is directly proportional tothe value of R, so the time we have count-ed out until the voltage rises to 3·0V is anaccurate representation of the value of theresistor. So all we need to do is to timehow long it takes for the capacitor tocharge via the thermistor, then time howlong it takes to charge via the preset resis-tor. If the first time is shorter than the sec-ond, the thermistor is too warm and weought to sound the alarm!

In order to give a reasonable number ofsteps to do the counting and improve therange of accuracy of the measurement, tworegisters are used together to form a 16-bitvalue.

The technique used for measuring resis-tance is shown in Fig.6, and involves thefollowing:

1. First the capacitor needs to be com-pletely discharged. To do this, pin 5 is setas an output, and then set at logic 0 (zerovolts). This effectively shorts the capacitor.A delay of approximately 5ms makes sureit is fully discharged.

2. Next the two registers used to store thecount time for the thermistor are set to zero.

3. Then pin 6 is set as an output, andreset to logic 0. Pin 5 is swapped to beingan input pin, and then pin 6 taken to logic1. At this moment the capacitor begins tocharge up.

4. The program now starts to loop, incre-menting the counter registers as it goes.Each time around the loop pin 5 is checkedfor having reached the voltage threshold atwhich it is considered to be at logic 1.

5. As soon as this happens, the routineends, and the counter registers then con-tain the final time count. This process isrepeated for the variable resistor VR1using a different set of counter registersand pin 7 instead of pin 6.

After both measurements have beenmade, the two answers are compared: all weneed to do is to subtract one number fromanother – we just want to know whichprocess took the longer. Depending upon theoutcome, we either go directly into the Sleepmode, or sound the alarm for a short timebefore again going to sleep.

��������Generally speaking, a piezo device is

not a buzzer – it has to be driven by anoscillating signal to make the alarm

Everyday Practical Electronics, May 2002 317

What makes it possible for the PIC to dothis is that not only can we force pins to gohigh or low, but we can also changewhether a pin is an output or an input asthe program is running. Using this fact wecan both switch between the two resistors,and discharge the capacitor between ourreadings. This is described in the sectionon programming.

����������The way the program operates is straight-

forward, as illustrated by the flow-chart inFig.5. First the PIC is initialised in that pinsare set up either as outputs or inputs. Wethen have to measure the charging times ofthe capacitor first for the preset resistorVR1, then for the thermistor R1.

����� �Resistor

R1 n.t.c. discthermistor, 10k (1k atroomtemperature)

PotentiometerVR1 10k min. enclosed carbon

preset, horiz

CapacitorC1 100n ceramic disc

SemiconductorIC1 PIC12C508

preprogrammedmicrocontroller (see text)

MiscellaneousWD1 piezo sounder, 3V to 24V

Stripboard, 10 strips x 17 holes; plasticcase, size and type to choice; batteryholder; AA-size batteries (4 off); batteryclip; 8-pin d.i.l. socket; connecting wire;solder, etc.

SeeSSHHOOPPTTAALLKKppaaggee

Approx. CostGuidance Only ££99

excluding case & batts.

Table 1. Thermistor temperature/resistance

Temperature Resistance

Room 22°C 900�Fridge 2°C 2k3Freezer –20°C 11k2

Fig.3. Simple circuit to demonstratecapacitor charging.

Fig.4. Capacitor charging curve.

Fig.5. Flow chart for the main program.

www.epem

ag.co

m

EPE Online
Note that you can purchase pre-programmed PIC microcontrollers for our PIC projects (see the “ShopTalk” page in the associated issue of the Magazine for more details). Alternatively, if you wish to program the PIC yourself, you can find the code files by bouncing over to the EPE Online Library (visit www.epemag.com, click in the “Library” link in the top navigation, then on the “Project Code Files” link).
Page 4: Freezer Alarm

sounds. There are two reasons for using a“swept frequency” alarm sound using thesoftware:

a. Changing sounds such as beepers,sirens, etc. stand out much better frombackground noises, and

b. the piezo device used here has a verysharp resonance – i.e. the sound output isvery much higher at a specific frequencythan at others. Different devices have dif-ferent resonances, and even those tested ofthe same type had frequencies which var-ied quite a bit. By sweeping the frequencythrough the resonance one can be sure ofmaking the most irritating noise! In thisdesign, the frequency sweeps from approx-imately 2kHz to 8kHz.

To make a PIC generate an oscillatingsignal is quite simple. Referring to thewaveform in Fig.7, you take the outputhigh, wait for a short time (tdel), take theoutput low, wait for a short time (tdel), andthen repeat the process.

The result is a square wave driving thepiezo sounder. If, for instance, we made tdel= 0·5ms, the period would be 2 × tdel =1·0ms, and the sound would have a fre-quency of 1kHz.

Sweeping the frequency may be accom-plished by gradually changing the value oftdel which can be done using the fact thatdelays in microcontroller systems are oftenmade by “time-waster” loops where acounter counts down to zero.

By changing the value loaded into a reg-ister in the first place, the time taken can bevaried. Fig.8 shows the program segmentresponsible. For each specific frequency,eight cycles are generated. The wholeprocess takes approximately 130ms.

��������Not many published projects seem to

use a PIC’s Watchdog Timer (WDT), butwhen it comes to conserving power usingthe Sleep mode, it is very useful.Information can be found in Microchip’sdata sheets and other publications.

When a PIC is given the Sleep com-mand, it shuts down nearly all its functionsand as a result consumes a very tinyamount of power – it only draws about4�A from the supply.

There are three ways in which it canwake up again:

a. by a logic change on a pre-defined pinb. when the WDT times-out, andc. by an external master ResetIt is the second of these options that is

used in this project. Inside the PIC12C508,the WDT function has its own internaloscillator and counter, and these continueto run even if the PIC is asleep. When theWDT times out, a system Reset is generat-ed, and the program restarts.

It should be noted that one bit of the con-figuration word of the PIC enables or dis-ables the WDT, and this bit must be setwhen the chip is programmed.

So, if we reset the WDT, it will then startcounting and when it times-out (18mslater), the program goes through a Resetand starts again. That is not a very longtime, but fortunately we can use the inter-nal pre-scaler which can be used in con-junction with the WDT. To do this, we usethe OPTION register to extend the time-outperiod to approximately 2·3 seconds.

318 Everyday Practical Electronics, May 2002

Fig.6. Measuring the resistance of thethermistor.

Fig.8. Flowchart for the piezo sweeper.The whole sequence takes approxi-mately 130ms.

Fig.7. Output waveform.

www.epem

ag.co

m

Page 5: Freezer Alarm

This may not seem very long, but whatmatters in conserving power is the ratio ofthe time taken to run the measurementscompared and the time remaining asleep.If, for instance, it takes 50ms to take themeasurements, the circuit is asleep for 98per cent of the time with a resultingextension of battery life.

The OPTION register has eight bitswhich must be set up in order to control theWDT and prescaler. The functions areshown in Table 2. For this application, theOPTION register must be set to contain thebinary byte 11001111. The short mainprogram section is shown in Fig.9.

Note that during a Sleep period, theI/O ports maintain the same conditionsthat they had immediately beforehand.Therefore, to minimise the currentdrawn, all the pins are made inputs (highimpedance) before the Sleep command.

������������Construction is very simple. The sug-

gested stripboard component layout andtrack cut details are shown in Fig.10.

The thermistor can be soldered to a shortlength of wire such as thin audio coax. Animprovement would be to waterproof thethermistor connections by dunking it inpolyurethane varnish. The wire can be fedinto the freezer via the door seal.

It is important to resist the temptation toadd a light emitting diode as a battery indi-cator – the l.e.d. would take about a thou-sand times more power than the rest of thecircuit!

The PIC should be plugged into theboard via an 8-pin d.i.l. socket. The circuitand batteries can be housed in a plastic boxto sit outside the freezer, a small hole beingprovided to glue the piezo sounder behind.You should not need to replace batteriesvery often.

Software and pre-programmed PICsare available as stated in this month’sShoptalk.

�����The circuit will

work quite happily atroom temperature.Once the batteries areconnected (it seems towork well on 6Valthough this is higherthan the maximumrecommended).

Gently rotate pre-set VR1 until thethreshold is foundbetween the alarmbleating or not. Set itso that the alarm isjust off. Then holdthe thermistor inyour fingers to warmit up, and the alarm

should sound; let go to allow thethermistor to cool again to room temper-ature, and the alarm should stop.

Once you are convinced all is well, putthe thermistor in the freezer, and afterallowing time for the temperature to sta-bilise, increase the resistance on the presetso that the alarm threshold is set where youwould like it.

In fact, the best way to find out if thebatteries are OK is to let the thermistorwarm up a bit when you open the freezer –if it is working and the alarm sounds, thebatteries are fine!

���� ��������As mentioned earlier, the techniques

explained allow simple modifications tochange how the circuit operates:

a. To make the alarm work if somethingis too cold rather than too warm (for exam-ple as a greenhouse frost alarm), simplyswap over the connections to pins 6 and 7.Alternatively, make the appropriate swapsin the software.

b. The method can be adapted for anyresistance changes – for example, thealarm could be made light-sensitive byusing an l.d.r. (light dependent resistor)instead of a thermistor. Whatever thermis-tor or other device is used, VR1 needs tohave a resistance which can be set to thesame that the device has at its operatingthreshold.

c. An important design considerationconcerns the value of the capacitor C1.Once the resistance of the appropriate sen-sor is known, the variable preset resistorneeds to have the same value. However, thecounter which waits for the capacitor tocharge to its threshold must not overflow.This will happen after 320ms with thisdesign’s value for C1. Therefore, ensurethat C(�F) × R(k�) <320ms.

d. The circuit is remarkably accurate andstable. Because of the timing method ofcomparing the two resistors, any changesin the supply voltage (within the parame-ters above), or changes in the capacitancevalue caused by temperature or ageing,have virtually no effect.

������������The author expresses his thanks to

Mrs Jan Edwards for her help in thisproject. �

319

Table 2. Option Register BitsBit 7 GPWU Enable (0) or disable (1) wave-up on pin changeBit 6 GPPU Enable (0) or disable (1) weak pull-up resistorsBit 5 T0CS Timer 0 clock sourceBit 4 T0SE Timer 0 edge selectBit 3 PSA Prescaler assignment: Assigned to WDT (1), or to Timer 0 (0)Bits 2-0 Prescaler rate – division ratio (111 for WDT ratio of 1:128)

Fig.10. Stripboard layout for theFreezer Alarm.Fig.9. Main program

; Main program startstart

clrwdtclrf gpio ;initialise I/Omovlw b’00000111’tris gpiomovlw b’11001111’option ;wdt and prescaler

setup

call delay ;settle downcall measureRcall measureTcall comparexorlw 0FFH ;check if resT <

resRbtfsc z ;If so, set off alarm!call alarmmovlw b’11111111tris gpio ;all pins high

impedance

clrwdtsleep ;until reawakened

by wdt;with a reset kiss

goto start ;should never reachhere!

www.epem

ag.co

m