Silicon ChipFridge/Freezer Alarm - April 2016 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: Arduino, Raspberry Pi or Maximite – which will gain the ascendancy?
  4. Feature: Gravitational Waves: Einstein Was Right . . . Again by Ross Tester
  5. Project: Touch-Screen Boat Computer With GPS by Geoff Graham
  6. Project: Microwave Leakage Detector by Nicholas Vinen
  7. Subscriptions
  8. Project: Fridge/Freezer Alarm by John Clarke
  9. Product Showcase
  10. Serviceman's Log: Odyssey Stratos amplifier voltage conversion by Nicholas Vinen
  11. Review: Keysight U1282A & U1242C Multimeters by Nicholas Vinen
  12. Project: Arduino Multifunction 24-Bit Measuring Shield by Jim Rowe
  13. Feature: Digital TV & MPEG-4: The Current State Of Play by Alan Hughes
  14. PartShop
  15. Vintage Radio: The Westinghouse H-618 6-transistor radio by Ian Batty
  16. Market Centre
  17. Notes & Errata: Universal Speaker protector Mk3 / High Visibility 6-Digit LED GPS Clock
  18. Advertising Index

This is only a preview of the April 2016 issue of Silicon Chip.

You can view 43 of the 96 pages in the full issue, including the advertisments.

For full access, purchase the issue for $10.00 or subscribe for access to the latest issues.

Items relevant to "Touch-Screen Boat Computer With GPS":
  • Micromite LCD BackPack PCB [2.8-inch version) [07102122] (AUD $5.00)
  • PIC32MX170F256B-50I/SP programmed for the Micromite-based Touch-screen Boat Computer [BoatComputerFullV7.hex] (Programmed Microcontroller, AUD $15.00)
  • MCP1700 3.3V LDO (TO-92) (Component, AUD $2.00)
  • VK2828U7G5LF TTL GPS/GLONASS/GALILEO module with antenna and cable (Component, AUD $25.00)
  • CP2102-based USB/TTL serial converter with 5-pin header and 30cm jumper cable (Component, AUD $5.00)
  • Matte/Gloss Black UB3 Lid for 2.8-inch Micromite LCD BackPack (PCB, AUD $5.00)
  • Clear UB3 Lid for 2.8-inch Micromite LCD BackPack (PCB, AUD $5.00)
  • Gloss Black UB3 Lid for 2.8-inch Micromite LCD BackPack (PCB, AUD $4.00)
  • Modified software for the Micromite Boat Computer (Free)
  • Firmware (HEX) file and BASIC source code for the Micromite-based Touch-screen Boat Computer with GPS [V7] (Software, Free)
  • Micromite LCD BackPack PCB patterns (PDF download) [07102121/2] (Free)
  • Micromite LCD BackPack/Ultrasonic sensor lid cutting diagrams (download) (Panel Artwork, Free)
Items relevant to "Microwave Leakage Detector":
  • Microwave Leakage Detector PCB [04103161] (AUD $5.00)
  • Microwave Leakage Detector SMD parts (Component, AUD $12.50)
  • Microwave Leakage Detector PCB pattern (PDF download) [04103161] (Free)
Items relevant to "Fridge/Freezer Alarm":
  • Fridge/Freezer Alarm PCB [03104161] (AUD $5.00)
  • PIC12F675-I/P programmed for the Fridge/Freezer Alarm [0310216A.HEX] (Programmed Microcontroller, AUD $10.00)
  • Firmware (HEX) file and source code for the Fridge/Freezer Alarm (Software, Free)
  • Fridge/Freezer Alarm PCB pattern (PDF download) [03104161] (Free)
  • Fridge/Freezer Alarm panel artwork (PDF download) (Free)
Items relevant to "Arduino Multifunction 24-Bit Measuring Shield":
  • Arduino Multifunction Meter (MFM) PCBs [04116011/2] (AUD $15.00)
  • SMD resistors, capacitors and diodes for Arduino Multifunction Meter (MFM) (Component, AUD $25.00)
  • Arduino sketch, Windows installer & source code for the Arduino Multifunction Meter (MFM) (Software, Free)
  • Arduino Multifunction Meter (MFM) PCB patterns (PDF download) [04116011/2] (Free)
  • Arduino Multifunction Meter (MFM) cutting details and panel label artwork (PDF download) (Panel Artwork, Free)
Articles in this series:
  • Arduino Multifunction 24-Bit Measuring Shield (April 2016)
  • Arduino Multifunction 24-Bit Measuring Shield (April 2016)
  • Arduino-Based Multifunction Measuring Meter, Pt.2 (May 2016)
  • Arduino-Based Multifunction Measuring Meter, Pt.2 (May 2016)

Purchase a printed copy of this issue for $10.00.

Who left that %$^^&* door open again! FRIDGE/FREEZER ALARM We’ve all done it: opened the fridge or freezer door and then not closed it properly. That can cost you: the food could spoil or at the least, the refrigerator could run continuously and you’ll waste a lot of electricity. B uild this Fridge Door Alarm and it will warn you whenever the door is open or ajar. Not only that, the cost to build it is far less than if you lose a fridge full of food due to spoilage. Even the self-closing doors on modern fridges are not completely foolproof; there might be an obstruction inside the door, because an item inside the compartment has moved or fallen over or because the compartment is too full. It helps, of course, if the fridge is slightly tilted back to help the doors close by themselves. Whatever fridge you have, our Fridge Door Alarm can be most useful. It warns when the door of the refrigerator or freezer is left open for longer than the preset time. It is great for indicating when someone is standing 40  Silicon Chip with the door open for too long and a real asset in warning when the door looks shut but is still partially ajar. The fridge alarm has an LDR (light dependent resistor) which responds to ambient light. So it will respond to the fridge light which will be on even if the door is barely ajar. And the circuit is sensitive enough so that it will all work in a freezer compartment which will normally not have an internal light (Note: recent model fridges often have white LED illumination in the freezer compartment). As long as there is some ambient light that the Fridge Alarm can detect, it will operate. The alarm will sound if the light By John Clarke is present for longer than the preset period and will continue to sound until the door is closed. In practice, the preset period is set so that in normal use the alarm will not sound. It will then sound when the door is left wide open for too long or if left slightly ajar. Note that the alarm cannot be used with display refrigerators or freezers that have glass doors – that is, unless the Fridge Alarm light sensor can be positioned so that it is covered over by the glass door frame when the door is closed. Does the light really go off? Do you or members of your family have doubts whether the fridge light really goes off when the door is closed? Does the little man in the fridge really do his job? Or is he sitting in there siliconchip.com.au FEATURES • Powered by a Lithium butto n cell • LED brightne ss indicates ce ll condition • Low current drai • Two alarm so n (~2.5µA) und options • Adjustable al arm onset peri od (~2-180s) PIC microcontroller, an LDR, piezo sounder and not much else. The 3V lithium button cell is switched via jumper link JP1. Taking up less room than a switch on the PCB, the link can be removed (and placed on one of the jumper pins – so you don’t lose it!) to disable the alarm when not in use. The circuit draws only 2.5µA when lying dormant in the fridge in darkness and rising to about 0.5mA when the alarm is sounding. Most of the time, the PIC12F675 microcontroller (IC1) is asleep and it wakes every 2.3 seconds to monitor the LDR and to power up its internal oscillator which runs at 4MHz. Normally, IC1’s GP1 output is set high (3V) and so there is no current through the 3.3MΩ resistor and the LDR. When IC1 is awake, it sets output GP1 low (0V) and the LDR forms a voltage divider in conjunction with the 3.3MΩ resistor across the 3V supply. The voltage across LDR1 is monitored at input GP3, pin 4. In darkness, the LDR resistance is shivering, trying to keep warm under the light? This Fridge Door Alarm will finally dispel any doubts on this score. If you open the door and can hear the alarm sounding immediately, it means that the light has remained on while the door was closed. Sceptics may then say it’s the fridge alarm itself that does not cease making alarm sounds and so is immediately heard when the door is opened. Well, stick the alarm in your pocket; the alarm will stop sounding! The Fridge Door Alarm is designed to be housed in a small transparent box or more simply, a sealed plastic bag, and powered with a 3V Lithium button cell. The Alarm is placed in the freezer or refrigerator near the door opening, so it can “see” the light from the internal lamp and from outside the compartment. Circuit details As can seen in the diagram of Fig.1, there is not much to the circuit; a siliconchip.com.au POWER INDICATION POWER K A LED1 100nF  3.3M K JP1 A 3V LITHIUM CELL D1 1N4004 1 Vdd 4 1k GP3/MC AN0 DELAY 7 VR1 10k LDR1  6 IC1 GP1 PIC12F675 GP2 5 100 –I/P 3 ALARM TYPE GP5 GP4 2 PIEZO Vss JP2 8 LED1 1N4004 SC 2016 FRIDGE DOOR ALARM A K K A Fig.1: there’s not much to the circuit – a PIC microcontroller, an LDR (the component which actually tells the little man in the fridge that the light is still on . . .) a piezo to make noise – and very little else. You can change the alarm sound with JP2. April 2016  41 very high (above 10MΩ) so the voltage at input GP3 is more than 2V due to the voltage divider action of the LDR and the 3.3MΩ resistor. This voltage level tells IC1 that the Fridge Alarm is in the dark (poor little fellow). If the fridge door is opened, light will cause the LDR to drop in resistance, down to around 10kΩ, which produces a low level at the GP3 input and IC1 “sees” the light. (Oh, joy!) Diode D1 is included as a safety measure to prevent damage to IC1 if the cell holder is installed the wrong way round. If the polarity is wrong, diode D1 will shunt the reverse current. If the cell holder is installed correctly, then because of the way the CR2032 cell is made, there is no way that it can be inserted back to front. (At least that is true for the particular cell holder we used). GP1’s output is only held low for just long enough to monitor the resistance of the LDR. GP1 then returns high to save power. When GP1 is low, LED1 lights to indicate that power is applied to the circuit. The LED brightness also provides an indication of the cell voltage. VR1 is also connected to the GP1 output again to save power. This allows one side of this trimpot to be taken low. The other end of the trimpot is connected to the 3V supply. The AN0 input monitors the voltage setting for VR1’s wiper whenever GP1 is low. VR1’s wiper can be set to show a voltage anywhere between 0V and the 3V supply. The voltage setting determines the delay which is adjustable from 2 to 180 seconds (three minutes). Notes on the software Note that the GP3 input in many projects is often configured as the MCLR input (master clear), which allows the microcontroller to have an external power-on reset. However, for our circuit we need this as a general purpose input for monitoring the LDR. When MCLR is set up as an input, the MCLR operation is switched to an internal connection within the microcontroller so the master clear power-on-reset function is not lost. One disadvantage of using this as a general purpose input is that it is not a Schmitt trigger input. The lack of a Schmitt trigger input at GP3 can mean that, at a particular ambient light level, the input to GP3 could be read as either a high or low input level by IC1’s software. At this threshold, the Fridge Alarm could produce strange alarm sounds as IC1’s software switches the alarm on and off, undecided as to the ambient light level. We solved this by making sure that once the Fridge Alarm is switched on (in the light), it is not switched off until the ambient light reaches a significantly lower level. This difference in level is called hysteresis. Scope1: This oscilloscope screen shows the drive signals to the piezo transducer, measured at pins 2 & 5 of the PIC microcontroller. The drive frequency is 4kHz. In effect, the total voltage across the transducer is the difference between the two out-of-phase signals, resulting in twice the voltage from pin 2 or pin 5. 42  Silicon Chip Hysteresis is implemented by pulsing the GP1 output momentarily high when checking for a high ambient light level. High ambient light means that the LDR’s resistance is low, so the GP3 input is a low voltage. The momentary high pulse level effectively raises the average GP3 voltage slightly since this pulse is filtered with the internal capacitance at the GP3 input of 50pF or less. The raised voltage means that the LDR is required to have a lower resistance (ie, have more light shining on it) to bring the GP3 voltage low enough for a low input reading by IC1. The second disadvantage of using the MCLR pin as a general purpose input is that there can be a problem when programming the microcontroller. This problem occurs when the internal oscillator is also used to run the microcontroller (which we do). We solved this problem in the software and the solution is discussed later under the "programming" subheading. Output drivers Outputs GP2 and GP5 on IC1 are used to drive the piezo transducer in bridge mode, ie, with the two outputs working in a complementary manner. So when GP2 is high, GP5 is low and when GP2 is taken low, output GP5; is taken high. This provides a full 3V peak square wave drive to the transducer. A 100Ω resistor limits peak currents into the capacitance of the Scope2: Taken at a much slower sweep speed than Scope1, this shows the same simple chirp alarm signal, which consists of 20ms bursts of 4kHz at regular intervals. Note that the drive signal from each microcontroller output is essentially “square” but the trailing edges do have significant ringing. siliconchip.com.au PIEZO TRANSDUCER FRIDGE ALARM Rev.A BUTTON CELL HOLDER 16120130 03102161 4004 D1 1 10k 100 IC1 PIEZO A PIC12F675 LED1 3.3M 100nF PIEZO JP1 VR1 + Power 1k C 2016 CR2032 LDR1 Alarm BOTTOM OF PCB JP2 TOP OF PCB Scope3: Taken at the same sweep speed as in Scope2, this is the more complex “cricket” alarm sound which we found to be more arresting (insistent, irritating, annoying – your choice). You can choose either alarm sound by having link JP2 in or out of circuit. piezoelectric transducer at the switching of the outputs. (See oscilloscope trace and caption). Normally, the GP4 input is set as a low output without pull-up to save on power drawn from the cell. However, whenever IC1 checks the input level, GP4 is set as an input, with an internal pull-up current source enabled. With no jumper link at JP2, the input is pulled high via this internal pull-up. When a jumper link is installed, the input is held low. This determines the alarm sound produced. Note that the GP4 input state is checked just before the alarm sounds. The alarm can be either a short (50ms) 4kHz beep that repeats once per second (JP2 open) or a chirping cricket sound (JP2 installed). See Scope1-Scope3 for more details. Construction The the Fridge Alarm is constructed on a PCB coded 03102161, measuring 30 x 65mm. It is presented as a bare PCB which can be sealed inside a clear plastic bag but we have made provision for mounting it inside a small plastic case. Fig.2 shows the PCB overlay. Begin construction by installing the three resistors, using a multimeter to check the value of each before inserting it into the PCB. Diode D1 can now be installed, taking care to orient correctly. Fit the IC socket next, orientating its pin 1 notch siliconchip.com.au Above right: Fig.2, the component overlays for the bottom and top sides of the PCB, with matching photos at right. Only the piezo, LED and LDR are mounted on the bottom side of the PCB; it is intended that this side aim out the fridge/freezer door. As explained later in the text, the PCB was enclosed in a zip-loc bag with a desiccant to help prevent condensation. as shown in Fig.2, followed by the lone 100nF capacitor (either way around) and the trimpot. Then solder in the 2-way pin headers for JP1 and JP2, followed by the cell holder. Make sure the plus terminal is oriented toward diode D1 on the PCB. The piezo transducer is mounted on the underside of the PCB, supported on TO-220 insulating bushes used as spacers and secured with short M2 screws and nuts. The wires can be soldered to the underside of the PCB (the positions are marked “PIEZO”) or brought around to the top of the PCB. We used PC stakes for the piezo transducer wiring, on the top side, as this allows provision for heatshrink tubing over the wires and PC stakes to help prevent the wires from breaking off. While the piezo transducer will probably come with red and black wires, the connections required are not polarised and it doesn’t matter which wire is used for each "PIEZO" position. LED1 is also mounted on the bottom side of the PCB. Make sure the longer lead of the LED (the anode) is inserted in the "A" position on the PCB. Then fit the LDR, about 10mm above the PCB surface, also on the underside. Its polarity is unimportant. If you intend to program the PIC yourself, download 0310216A.HEX from the SILICON CHIP website and flash the PIC chip with it. See the section April 2016  43 Parts list – Fridge/Freezer Alarm 1 double-sided PCB coded 03102161, 30 x 65mm 1 small zip-loc plastic bag 1 packet dry silica gel desiccant 1 20mm button cell holder (Jaycar PH-9238, Altronics S 5056) 1 CR2032 Lithium cell (3V) 1 30mm diameter piezo transducer (Jaycar AB-2440, Altronics S 6140) 1 10kΩ light dependent resistor (Altronics Z 1621; Jaycar RD3480) (LDR1) 1 DIL8 IC socket 2 M2 x 8mm screws with nuts 2 TO-220 insulating bushes 2 2-way pin headers (2.54mm pin spacing) (JP1,JP2) 2 jumper shunts 2 PC stakes 1 25mm length of 2mm diameter heatshrink tubing Semiconductors 1 PIC12F675-l/P programmed with 0310216A.hex (IC1) 1 1N4004 diode (D1) 1 3mm green high brightness LED (LED1) Capacitor 1 100nF 63V or 100V MKT polyester Resistors (0.25W, 1%) 1 3.3MΩ 1 1kΩ 1 100Ω 1 10kΩ miniature horizontal trimpot (VR1) Extra parts for mounting in box 1 UB5 Jiffy box 4 M3 x 12mm tapped spacers 4 M3 x 6mm machine screws 4 M3 x 6-9mm countersunk screws on programming for details. IC1 can now be plugged into its socket, with pin 1 towards the notched end, near the centre of the board. You can now install the CR2032 cell in its holder and place the jumper link onto the 2-way header (JPI). If all is well, the LED will momentarily flash after about three seconds to indicate that power has been connected. A brief flash of the LED also occurs when a high light level is detected. Then the Fridge Alarm will sound the 44  Silicon Chip alarm after the delay set by VR1. The alarm should stop when the LDR is in darkness. The delay can be adjusted from between two and 180 seconds, with two seconds when VR1’s wiper is set fully anticlockwise and 180s when set fully clockwise. Mid setting provides about a 90s delay. Note that the 2-second delay will be affected by the sampling period of the LDR that occurs every 2.3s. So the alarm may start anywhere between two and 4.3 seconds after light is detected by the LDR. As the delay is adjusted to higher periods, the variation in delay due to the sampling period becomes less significant. Note that you can keep tabs on the lithium cell condition by observing the LED. If it flashes brightly as the fridge door is opened, then the cell is OK. As the cell discharges, the LED will become quite dim. Programming If you are programming the microcontroller yourself, you may be presented with a warning by the programmer stating that programming is not supported when both the MCLR is set as a general purpose input and with the internal oscillator set. However, you will be able to program the microcontroller successfully, ignoring the warning. That’s because any problems associated with this configuration are already solved by a software solution. Read on if you want more details. As mentioned, we set MCLR as a general purpose input and utilise the internal oscillator within IC1. This can present problems for a programmer during the process of verifying the software code after programming. The problem lies in the fact that as soon as the microcontroller is programmed, it will begin executing its program. A typical program initially sets up the microcontroller with the general purpose (GP) lines set as inputs or outputs (I/O). This conflicts with the programmer needing to use the clock and data programming I/O lines for program verification. This problem does not happen if the MCLR pin is set as the external MCLR input because the programmer then has control over the microcontroller, stopping it from executing the programmed code. Note also that in order to run the code, the microcontroller needs to operate from the internal oscillator instead of an external crystal, RC oscillator or clock signal. The programming problem is solved in the software provided by including a three second delay at the start of the program. This delay is before the I/O lines are set as inputs or outputs. The I/O lines therefore remain as high impedance inputs while the programmer verifies the internally programmed code using the clock and data programming lines. A warning from the programmer will still be issued but the microcontroller can be programmed successfully and correctly verified by the programmer. Note that the PIC12F675 also needs special programming due to the fact that it has an oscillator calibration value (OSCAL) that is held within the PIC’s memory. This calibration value is individually programmed into each PIC by the manufacturer and provides a value that allows the PIC to run at an accurate 4MHz rate. This value must be read before erasure and programming so that it can be included with the rest of the code during programming. If this procedure is not done, then the oscillator could be off frequency and that will have an effect on the Fridge Alarm sound. Most PIC programmers will automatically cater for this OSCAL value, but it is worthwhile checking if your programmer correctly handles this. Finally, be aware that the PIC12F675 requires a 5V supply for programming, even though it happily runs at 3V in the circuit. In use Condensation will always be a problem in a fridge or freezer. To help overcome this, once we confirmed it was working correctly, we sealed the unit inside a “zip-loc” type plastic bag and at the same time, included a bag of desiccant (silica gel) which will help absorb moisture. You should be able to find some silica gel – we’re always throwing it away as it comes packed with a lot of equipment, photo gear, etc, where moisture can be a problem. Because of the ultra-low current drain, battery life should be not much less than cell’s shelf-life. SC siliconchip.com.au