Silicon ChipPIC-Based Water-Tank Level Meter; Pt.1 - November 2007 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: Now for the next 20 years
  4. Feature: Your Own Home Recording Studio by Michael Goebel
  5. Feature: The Electricity-Saving Box – Does It Work? by Mauro Grassi
  6. Project: PIC-Based Water-Tank Level Meter; Pt.1 by John Clarke
  7. Project: Playback Adaptor For CD-ROM Drives by Mauro Grassi
  8. Feature: Siemens’ Electronic Wedge Brake by Silicon Chip
  9. Project: Rolling Code Security System; Pt.2 by John Clarke
  10. Project: A UV Light Box For Making PC Boards by Robert Scott
  11. Vintage Radio: Pocket-sized valve portable radios by Rodney Champness
  12. Book Store
  13. Advertising Index
  14. Outer Back Cover

This is only a preview of the November 2007 issue of Silicon Chip.

You can view 30 of the 104 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 "PIC-Based Water-Tank Level Meter; Pt.1":
  • PIC16F88-I/P programmed for the Water Tank Level Meter telemetry base station (Programmed Microcontroller, AUD $15.00)
  • PIC16F88-I/P programmed for the Water Tank Level Meter main/transmitter unit (Programmed Microcontroller, AUD $15.00)
  • PIC16F88 firmware and source code for the Water Tank Level Meter receiver [water tank level receiver.HEX] (Software, Free)
  • PIC16F88 firmware and source code for the Water Tank Level Meter transmitter (Software, Free)
  • Water Tank Level Meter base station PCB patterns (PDF download) [04101081/2] (Free)
  • Water Tank Level Meter main PCB pattern (PDF download) [04111071] (Free)
  • Water Tank Level Meter base station front panel artwork (PDF download) (Free)
  • Water Tank Level Meter main sensor/transmitter unit front panel artwork (PDF download) (Free)
Articles in this series:
  • PIC-Based Water-Tank Level Meter; Pt.1 (November 2007)
  • PIC-Based Water-Tank Level Meter; Pt.1 (November 2007)
  • PIC-Based Water-Tank Level Meter; Pt.2 (December 2007)
  • PIC-Based Water-Tank Level Meter; Pt.2 (December 2007)
  • Water Tank Level Meter, Pt.3: The Base Station (January 2008)
  • Water Tank Level Meter, Pt.3: The Base Station (January 2008)
Items relevant to "Playback Adaptor For CD-ROM Drives":
  • ATmega8515 programmed for the CDROM Playback Adaptor (Programmed Microcontroller, AUD $15.00)
  • ATmega8515 firmware and source code for the CDROM Playback Adaptor (Software, Free)
  • CDROM Playback Adaptor PCB pattern (PDF download) [07112071] (Free)
Articles in this series:
  • Playback Adaptor For CD-ROM Drives (November 2007)
  • Playback Adaptor For CD-ROM Drives (November 2007)
  • Playback Adaptor For CD-ROM Drives; Pt.2 (December 2007)
  • Playback Adaptor For CD-ROM Drives; Pt.2 (December 2007)
Items relevant to "Rolling Code Security System; Pt.2":
  • Rolling Code Receiver PCB [01510071] (AUD $5.00)
  • PIC16F88-I/P programmed for the Rolling Code Keyless Entry System receiver unit [ircroll.HEX] (Programmed Microcontroller, AUD $15.00)
  • PIC16F628A-I/SO programmed for the Rolling Code Keyless Entry System transmitter unit [irxmroll.HEX] (Programmed Microcontroller, AUD $10.00)
  • PIC18F628A firmware and source code for the Infrared Rolling Code Transmitter [irxmroll.HEX] (Software, Free)
  • PIC18F88 firmware and source code for the Infrared Rolling Code Receiver [ircroll.HEX] (Software, Free)
  • Rolling Code Keyless Entry System PCB patterns (PDF download) [01510071/2] (Free)
  • Rolling Code Keyless Entry System receiver front panel artwork (PDF download) (Free)
Articles in this series:
  • Rolling Code Security System; Pt.1 (October 2007)
  • Rolling Code Security System; Pt.1 (October 2007)
  • Rolling Code Security System; Pt.2 (November 2007)
  • Rolling Code Security System; Pt.2 (November 2007)
Items relevant to "A UV Light Box For Making PC Boards":
  • PIC16F84(A)-04/P programmed for the UV Lightbox Timer (Programmed Microcontroller, AUD $10.00)
  • PIC18F84 firmware and source code for the UV Lightbox Timer (Software, Free)
  • UV Lightbox Timer PCB patterns (PDF download) [10111071/2] (Free)
  • UV Lightbox Controller front panel artwork (PDF download) (Free)

Purchase a printed copy of this issue for $10.00.

PIC-Based Water Tank Level Meter Pt.1: By JOHN CLARKE Optional radio telemetry feature lets you remotely monitor up to 10 tanks & automatically control pumps Looking for a water tank level meter that’s easy to install? One that’s accurate but doesn’t need a complicated in-tank sensor? This PIC-based unit uses a pressure sensor to monitor water level and it displays tank level at the press of a switch. It can also send its readings to a base station with an LCD readout via an RF link. R AINWATER TANKS are now all the go! Australia is one of the driest continents on Earth and faced with ongoing drought conditions, Australians are now rethinking the way water is managed. In most parts of the country, dams have been at their lowest levels since 28  Silicon Chip construction and many towns and cities now have some form of water restrictions. Saving water is vital and using rainwater tanks to store otherwise wasted rainwater is becoming commonplace. One traditional problem with water tanks is checking how much water is in them. That’s because they are opaque and they are made that way to protect the water from sunlight which would otherwise promote algae growth. Trying to look down through the water inlet into the dark interior doesn’t help much because this is invariably gauzed over to keep mosquitoes out. siliconchip.com.au And although some large concrete tanks have a manhole, this usually takes some effort to remove, so it’s not a convenient way to check the water level. Add-on devices Many ingenious devices have been developed over the years to show the water level in tanks. These include simple passive indicators that use clear tubing as a sight glass, mechanical floats and pulleys that move up and down with the water level, and the more complex electronic gauges. Each has its advantages and disadvantages. For example, sight “glass” systems, although simple, eventually become impossible to read because of algae growth and discolouration of the transparent material due to minerals in the water. And if the tube is directly exposed to the sun, it tends to become brittle. Similarly, mechanical float and pulley systems require regular maintenance otherwise they become jammed. In addition, none of these mechanical gauges easily provide for remote monitoring. Electronic gauges are more complex, require power and are usually more costly. However, they can provide features that passive and mechanical gauges cannot. These features include reliability, accuracy and the ability to provide remote monitoring of one or more tanks at a time. In addition, provision is often made to include pump control. This new Water Tank Level Meter includes all those features and more. Basic concept The SILICON CHIP Water Tank Level Meter is a versatile unit that can be built in a number of different configurations. It suits all types of rainwater tanks, is easy to install and because it doesn’t rely on mains power, can be installed just about anywhere. That last feature is particularly important because mains power is often not available adjacent to water tanks and this makes many electronic tank level meters impractical. By contrast, the SILICON CHIP Water Tank Level Meter is powered from a single AA alkaline or rechargeable cell, making it independent of the mains. So it doesn’t matter whether your tank is attached to the house, located next to a shed away from the house or siliconchip.com.au Fig.1: in its most basic form, the Water Tank Level Meter is a standalone unit that sits next to the tank. The water level is sensed using a pressure sensor connected by a plastic tube. Fig.2: the telemetry version transmits its reading to a remote Base Station which can display a range of data. A solar cell panel recharges an internal NiMH or Nicad battery. situated half way up a hill to provide water pressure storage – this unit will still work. In its most basic form, this water level meter can be built as a standalone unit that’s installed adjacent to a tank. The basic arrangement is shown in Fig.1. All you have to do is press a pushbutton switch and a multi-coloured LED will display the water level. Water levels are displayed as a colour sequence, ranging over 10 colours from white through to violet, to violet/indigo, indigo, indigo/blue, blue, green, yellow, orange and red. Red indicates the lower 10% range followed by orange for the 10-20% range and so on up to violet for an 80-90% level and white for the 90-100% level – see Fig.3. A single AA alkaline cell provides power for this basic version of the Water Tank Level Meter. The circuit draws no power until the pushbutton switch is pressed to activate the LED display. Actual cell life depends on usage but with one water level check per day, the cell should last for four years. If you want higher water level resolution and remote monitoring, the unit can be upgraded to a telemetry unit. In this case, the tank level is transmitted to a separate (plugpack-powered) base station – see Fig.2. Note, however, that November 2007  29 Main Features Basic Version • Powered by a single cell • Zero power consumption unless displaying the level • Water level displayed using a 10-colour LED indicator • Pushbutton initiates the display • Easy installation using a length of plastic tubing into tank • Weatherproof housing Telemetry Version • Alkaline, NiMH or Nicad cell powered • Solar cell charging for rechargeable cell • Pushbutton initiates the 10-colour level display • Minimal power drawn from cell • Radio transmission of tank level, temperature and cell voltage • Up to 10 tanks can be monitored at the base station by using 10 water level meters • Automatic pump control facility (requires Base Station and separate Pump Control unit) • 16 encoding selections (prevents interference from a neighbour’s Water Tank Level Meters) • • Four transmission update selections • Easy installation using a length of tubing into the tank for height measurement • Accurate measurement of regularly shaped tanks, including tanks with corrugated sides • Weatherproof IP65 housing (protected from ingress of dust and water) Update period differs slightly between each tank monitor to minimise data send clashes the tank level can still be checked using the LED display. Base station The base station shows levels in 1% increments from 0% through to above 100%. Why show levels above 100%? Well, most tanks are full when the water level reaches either the overflow outlet or the bottom of the inlet strainer when there is no overflow outlet. This is the 100% full level. However, during periods of heavy rain or when the tank is being filled using a pump, the tank can overfill. It is this condition that can be monitored via the base station readout – ie, up to 110% in level. Up to 10 tanks can be remotely monitored using the base station. To do this, each Water Tank Level Meter (one 30  Silicon Chip for each tank) uses an inbuilt radio transmitter to send the data to the base station. This transmitter operates on the licence-free LIPD 433MHz band. The distance over which the data can be sent depends on the terrain. Our tests indicate a range of more than 250m in open country but this is reduced if the signal has to pass through a wall or roof to reach the base station, especially if there is corrugated iron in the transmission path. The data is sent to the base station once every 16.8s, 33.5s, 67s or 268s (about 4½ minutes), depending on the set-up. This rate is selectable and depends on your installation. For small tanks, you may want to choose a fast rate so that the reading updates can keep pace with the water level as the tank rapidly fills. The downside of a fast rate is that the circuit draws more power from the cell. So while an alkaline cell could be used to power each Water Tank Level Meter, the best power option for the telemetry version is to use a rechargeable cell, along with a solar cell to recharge it. The slowest rate (ie, 268s) can be used to conserve power and is more suited for large tanks. It’s also an acceptable update period for most other installations, where you just want to know the water level and don’t have pump control. Pump control The base station not only shows water levels but can also independently control up to 10 electric water pumps. For example, the base station can be set up to switch off a given pump when the tank water drops below a preset level. This is useful when pumping out of a tank. Alternatively, a pump can be switch­ ed off if the water rises above a preset level; eg, when filling a tank. A pump can also be switched off if the temperature drops below a preset value, to prevent the pump from running when the water is frozen. In addition, the pump control includes brownout protection. We’ll have more to say about this and pump control in a later article. Water Tank Level Meter Now that we’ve covered the basic features, let’s go back and take a closer look at the Water Tank Level Meter. Basically, you require one of these meters for each tank. As shown in the photos, the unit mounts in a weatherproof box with a clear lid to allow the coloured LED to be seen (for water level indication). The front panel carries a waterproof switch, while the plastic tube that is required for tank level measurement enters the box via a waterproof cable gland. Unlike the basic version, the tele­ metry version uses a rechargeable cell and this is recharged by a separate solar cell panel during daylight hours. The leads from the solar panel enter through a waterproof cable gland on the bottom of the box. Measurement techniques Just about every water tank level meter on the market measures water height within the tank. They do not siliconchip.com.au Another method involves using an ultrasonic sensor to measure the distance from the top of the tank to the surface of the water. However, ultrasonic transducers require more power than we care to draw from an AA cell and the measurement is unreliable while the tank is filling. Why is it unreliable? Well, as the water enters the tank inlet, the droplets scatter the ultrasonic signal and the measurement is lost. We published an ultrasonic level meter in the April 1994 issue. Pressure sensor Fig.3: the water level in the basic version is displayed using a 10-colour sequence, ranging from red (0-10%) to white (90-100%). These colours are generated by a tri-colour LED. measure water volume because that is difficult to do and because it is usually unnecessary. If the tank is a regular shape with nominally straight sides and with the same shape and area at any horizontal cross section, then the water level gives a direct indication of water volume. By contrast, irregularly-shaped tanks such as those that have large indentations or are moulded to fit into an available space are not suited to accurate level measurement. Tanks that taper slightly (in the vertical direction) due to the use of thicker material towards the base do not alter the accuracy markedly. Similarly, corrugations have only a small effect on accuracy, although this gets worse at very low water levels and where the tank diameter is small compared to the corrugation depth. In general though, the small non-linearity of volume with height does not matter. There are several electronic techniques that are used to measure water level in a tank. One method is to use an in-tank sensor with a series of vertically-spaced metal contacts. As the water rises, current flows through each successive contact (because water is a good conductor) and the associated electronic circuit displays the level. The resolution of this type of meter depends on the number of vertical contacts. This type of water level meter was described in the April 2002 and July 2007 issues of SILICON CHIP (five levels and 10 levels respectively). siliconchip.com.au Unlike our previous designs, the Water Tank Level Meter described here uses a pressure sensor to measure water height. This is a very simple method that provides excellent accuracy and is easy to install – all you have to do is connect the free end of a hose to the pressure sensor and feed the other end of the hose into a tank. The technique relies on the fact that water pressure increases with increasing depth. For water, the pressure increases by 9.8kPa per metre and so there is approximately an extra atmosphere (1013hPa or 101.3kPa) of pressure for every 10.3m of depth. Refer now to Fig.4. As shown in Fig.4a, if the free end of the hose is left open, the hose will fill to the same level as the water in the tank. However, if we first connect the free end to a pressure sensor and then place the hose in the tank, the water will still rise inside the tube but not to the water tank level (see Fig.4b). That’s because it pressurises the air trapped inside the tube. In fact, the water level within the tube stabilises when the pressure inside the tube equals the water pressure at the bottom of the tube. Fig.4c shows what happens if the water level drops below the bottom of the tube. In this case, the reading will be zero, since both inlet ports on the sensor are at atmospheric pressure (ie, the unit is calibrated to measure zero pressure when there is no water in the tank, with the pressure then progressively rising as the water level rises). One problem with this scheme is that the tube will not stay down of its own accord but will float due to the air trapped inside it. Fortunately, that’s easy to overcome by tying it to a length of PVC pipe. Alternatively, it can be tied down using a weight. Another problem concerns the effect Fig.4a: if the free end of the tube (or hose) is left open, the tube fills to the same level as the tank. Fig.4b: if one end of the tube is connected to a pressure sensor, the water pressurises the air in the tube. Fig.4c: if the water level drops below the bottom of the tube, the reading will be zero since both sensor ports are at atmospheric pressure. November 2007  31 Fig.5: this cross-section diagram shows the internal structure of the MPX2010DP pressure sensor. The strain gauge varies its resistance according to the applied load. Note that there are two port openings (P1 & P2). Fig.6: the basic circuit for the step-up switching regulator. Transistor Q1 is repeatedly switched on and off by the control circuit. When it is on, the current builds up through L1 and when it switches off, the energy stored in L1 is transferred to the load. of temperature variations on the air pressure inside the tube. For example, if the sun heats the tube, the air inside it will expand and displace some of the water out of the tube. In practice, this pressure variation is compensated for by measuring the temperature and modifying the measurement accordingly. We can also minimise this pressure variation by making sure the length of tubing outside the tank is short compared to the overall length and by keeping the part that is exposed out of the sun. Another problem that must be taken care of is the effect of atmospheric pressure variations. As shown in Fig.4, the atmosphere presses down onto the water and so the water level readings could vary markedly as the atmospheric air pressure changes. The solution to this problem is simply to use a differential pressure sensor. This type of sensor is vented to the atmosphere, and so this variation 32  Silicon Chip is removed from the measurement. In order to explain how the sensor ignores the atmospheric air pressure, let’s take a look at its internal construction – see Fig.5. The sensor used here is the MPX­ 2010DP from Freescale Semiconductor. Note that “RTV die bond” stands for “Room Temperature Vulcanising” bonding. In other words, silicone glue is used to bond the strain gauge die to the epoxy casing and is cured at room temperature. Inside the sensor is a strain gauge that varies its resistance according to the applied load – ie, the air pressure exerted on the gauge. Note that there are two port openings to the strain gauge. One is on the top side and is designated port1 (P1), while the other is on the lower side and is designated Port 2 (P2). If the same pressure is applied to both P1 and P2 then the strain gauge does not flex. However, if one port has more pressure than the other, the strain gauge bends and its resistance changes. This particular sensor is called a differential type because it measures the difference in pressure between the two ports – ie, its output only changes when the pressure difference between the two ports changes. The MPX2010DP is designed for the pressure at port 1 to be greater than or equal to the pressure at port 2. In addition, port 1 has a silicone gel protective layer to prevent moisture affecting the strain gauge element. This makes the sensor ideal for water level measurement, as the silicone barrier keeps the sensor free of the water vapour that results from condensation in the measuring tube. By contrast, Port 2 is vented to the atmosphere, to balance the air pressure on both sides of the strain gauge element. This sensor is specified for a 0-10kPa pressure range, with a maximum differential pressure of 75kPa. Using it above the 10kPa level degrades the linearity due to internal self-heating of the sensor. However, this limit is specified when running the sensor from a 10V supply. Since we are using a 5V supply, the self-heating will be considerably lower and so we can easily exert more pressure than 10kPa without loss of linearity. When connected to measure water level, each metre of water adds 9.8kPa of pressure to the sensor. Most water tanks are equal to or less than about 2.2m in height because they are designed to fill from the rainwater guttering of a house. This means that, for a 2.2m tank, the maximum pressure applied to the sensor will be about 22kPa maximum. This is well below the 75kPa maximum allowable for the sensor. The strain gauge element is temperature compensated within the sensor by connecting it in a balanced bridge arrangement and by laser trimming the elements during manufacture. In practice, the sensor is compensated over a 0-85°C range but can be operated from -40°C to +125°C. Circuit details As stated previously, the unit is powered from a single cell – either a 1.5V rail from a standard alkaline cell or a 1.25V rail from an NiMH (or Nicad) rechargeable cell. This voltage siliconchip.com.au Fig.7: this is the circuit for the basic version of the Water Tank Level Meter. The differential outputs from the pressure sensor at pins 2 & 4 are buffered and amplified by op amps IC2a-IC2d and then fed to inputs AN2 & AN3 (pins 1 & 2) of a PIC18F88-I/P microcontroller (IC3). IC3 processes the data and drives a tri-colour LED at RA0, RA6 &RA7. needs to be stepped up to 5V to run the microcontroller (IC1) and its associated circuitry This voltage step-up is performed using a TL499A switching regulator (IC1), transistor Q1, inductor L1, a series diode (D1) and output filter capacitor C1. Fig.6 shows the details. The circuit works like this: initially transistor Q1 is switched on and the current through inductor L1 builds up until it reaches a preset value, as set by the resistor connected to pin 4 of IC1. At that point, the transistor switches off and the energy stored in L1 is delivered to the load and to output capacitor C1 via the series diode (DIODE1). This process then repeats, with the transistor switching on again siliconchip.com.au and recharging L1, then switching off again and transferring the charge in L1 to the load. A voltage divider consisting of resistors R1 & R2 reduces the output level, while Q1’s switching is controlled so as to maintain 1.26V at pin 2. Basically, the voltage divider values of 29.68kW and 10kW divide the output by 3.97 so the output will be at 5V when there is 1.26V at pin 2. Should the voltage rise slightly above 5V, transistor Q1 stops switching until the voltage falls slightly below the 5V level. Conversely, if the output voltage falls below 5V, the transistor switches on and off at a fast rate to increase the voltage. Note that the 1.26V at pin 2 (necessary to maintain regulation) is only a nominal value and could in fact be anywhere between 1.2-1.32V, depending on the particular IC. As a result, resistor R1 needs to be adjustable so that the output voltage can be set precisely to +5V. Refer now to Fig.7 for the circuit details of the Water Tank Level Meter (Basic Version). As shown, power from the 1.5V cell is applied to pin 3 of step-up converter IC1 via switch S1. Diode D1 provides reverse polarity protection if the cell is inserted incorrectly, while a 470mF low-ESR capacitor bypasses the supply. This capacitor provides the necessary transient current for the inductor when Q1 switches on. If the cell is connected the wrong November 2007  33 The Base Station goes with the Telemetry Version of the level meter and can display a range of data, including individual levels for up to 10 tanks & pump control setup. It will be described next month. way around, D1 conducts heavily and limits the reverse voltage at pin 3 and across the 470mF capacitor to less than 1V. In addition, many single cell holders are designed to prevent the cell from making contact with the positive contact if it is inserted incorrectly. Power is drawn from the 1.5V cell only when switch S1 is pressed. This means that the cell should last for several years before it requires changing, depending on the amount of use. The current consumption from the cell when the switch is pressed with one or two LEDs alight is typically around 32mA. IC1’s output voltage appears at pin 8 and is sampled via trimpot VR1 and a 10kW resistor. This sampled voltage is then applied to pin 2. In practice, VR1 is adjusted so that the output is exactly +5V. A 100nF ceramic capacitor and a low-ESR 220mF capacitor filter this supply rail which is then fed to pin 14 of microcontroller IC3. The +5V rail is also connected to the emitter of transistor Q1 (BC327). When power is applied to IC3, its internal software program starts running. Initially, transistor Q1 is switched off because IC3’s RA4 output (which drives the base via a 1kW resistor) is held at +5V. 34  Silicon Chip As a result, no power is applied to either the pressure sensor (Sensor1) or IC2. However, after a short period to allow the +5V rail to stabilise, RA4 goes low and Q1 switches on. Sensor1 and IC2 are then powered up and begin operating. Differential outputs As shown in Fig.7, Sensor1 has differential outputs at pins 2 & 4. If the same pressure is applied to both ports, the voltages at pins 2 & 4 are nominally the same, at half supply voltage or 2.5V. However, if the pressure at port 1 is higher that at port 2, the voltage at pin 2 rises and the voltage at pin 4 falls. This change in voltage is actually quite small, amounting to around 12.5mV for a 10kPa pressure difference when the sensor is powered from a 5V rail. The sensor’s differential output signals at pins 2 & 4 are fed to op amps IC2a & IC2b respectively. These are each set up as non-inverting amplifiers with 22kW feedback resistors and with a 1kW trimpot (VR2) connected between their inverting inputs. The 10nF capacitors across the 22kW resistors, filter the signal by rolling off the high-frequency response. The outputs from IC2a & IC2b ap- pear at pins 1 & 7 respectively and are summed in unity gain differential amplifier IC2c. Basically, IC2c acts as a voltage follower for the positive-going signals from IC2a and as an inverter for the negative-going signals from IC2b. As a result, the signal voltage excursions from IC2a & IC2b are effectively added together. The overall gain is 1 + (22kW x 2/VR2). Buffer stage IC2d is wired as a buffer stage and applies an offset voltage to the noninverting input of IC2c (pin 10) via a 1kW resistor. It obtains its reference voltage via a voltage divider from the +5V supply and this divider comprises trimpot VR3 and a 22kW resistor. In practice, VR3 is adjusted so that IC2c’s pin 14 output sits at 1V when the sensor has no pressure difference between the two inlet ports. By contrast, trimpot VR2 is adjusted to provide 3V at IC2c’s pin 8 output when the sensor is measuring a full tank. As a result, IC2c has a 2V range – ie, from 1-3V for a zero to full tank level measurement. If the tank being monitored is 1m high, the sensor output will provide a 12.5mV signal when the tank is full. In this case, the signal must be amplisiliconchip.com.au fied by 160 to produce the required 2V swing and that means that VR2 would be set to 277W. VR2’s practical range from 1kW down to about 100W easily provides for tanks ranging in height from 3m down to 360mm. However, in the unlikely event that a tank is less than 360mm high, a 200W trimpot should be used for VR2 instead of the 1kW value specified on the circuit. This will allow the trimpot to be set below 100W without being too near its adjustment limit. The reason we restrict IC2c’s output to between 1-3V is so that the LM324 op amp can operate correctly within its output range. Typically, an LM324 can easily provide an output from 1-3V when powered from a 5V rail but it cannot provide a 0-5V output. Microcontroller IC2c’s output at pin 8 is applied to the AN3 input (pin 2) of IC3, a PIC16F88-I/P microcontroller. Note, however, that the 5V supply is applied to the sensor and to IC2 for about 64ms before the voltage at AN3 is measured. In operation, IC3 converts this applied voltage to a 10-bit digital value and this is then calculated as a percentage, with a 1V reading converted to 0% and a 3V reading converted to 100%. The 100% to 110% range covers input voltages between 3V and 3.2V. The resulting percentage level is then used to determine what colour should be produced by the tri-colour (RGB) LED. This device basically includes separate red, green and blue LEDs and these are driven by the RA0, RA7 & RA6 outputs via 1kW resistors. When all the LEDs in the package are powered, the LED colours mix to show white. If only two or one LED is lit, a different colour results. For example, to produce violet, the red and blue LEDs are lit. Similarly, yellow is displayed when the red and green LEDs are lit. We can also obtain a range of inbetween colours by reducing the light output of one of the LEDs. This is achieved by switching the LED on and off using a fast equal duty cycle waveform, so that it doesn’t appear to flicker. For example to obtain orange, we switch the red LED on continuously while the green LED is rapidly switched on and off. In practice, when switch S1 is momentarily pressed, the LED colour display comes on for about 2s to show siliconchip.com.au Specifications Water Level Indication: White 90-100%, Violet 80-90%, violet/indigo 70-80%, indigo 60-70%, indigo/blue 50-60%, blue 40-50%, green 30-40%, yellow 20-30%, orange 10-20%, red 0-10% Current – Basic Unit: 32mA typical when displaying level; 0mA when off. Current – Telemetry Version: standby current drawn from 1.25V cell = 1mA; awake current during each start-up for 220ms = 24mA; average current = 314mA for 16.8s update; 157mA for 33.5s update; 79mA for 67s update; and 19mA for 268s update. Add an extra 8mA over 2s when one or two LEDs are lit Solar cell charge current in winter time and in full sunlight: typically 30mA Data transmission duration: 146ms Transmission repeat: approximately 16.8s for encode 0-3, 33.5s for encode set at 4-7, 67 seconds for encode set at 8-B and 268s for C-F. Transmit range: over 250m the water level and then switches off again. At the same time, IC3’s RA4 output goes high and switches off transistor Q1 to disconnect power to the pressure sensor and IC2. This conserves power should the switch be pressed longer than required. The 2.2kW resistor at pin 18 (AN1) of IC3 ties this input to pin 3 of IC1 so that it is not left floating (this input is used in the telemetry version to measure cell voltage). Temperature sensing The AN2 input (pin 1) monitors the temperature via an LM335Z temperature sensor (Sensor2). This produces a nominal output of 10mV/°C but with an offset of 2.73V at 0°C and is linear with temperature changes. The water level reading is then compensated for according to the measured temperature. Trimpot VR4 is used to calibrate the sensor for 2.73V at 0°C or 2.98V at 25°C by altering the voltage at the ADJ terminal. Clock signals for IC3 are provided by an internal oscillator that’s set to run at 8MHz. Among other things, it runs the internal program at a constant rate to perform the A/D conversion and to drive the RGB LED for the set period. Telemetry version The telemetry version of the Water Tank Level Meter is almost the same as the standard version but adds a few extra parts, including a 433MHz transmitter and two rotary BCD switches. In addition, the power supply arrangement is slightly different. As previously mentioned, this version is powered from a rechargeable NiMH (or NiCd) cell. This cell is in turn charged from a solar cell array via Schottky diode D2. This diode is required to stop the solar cell from discharging the NiMH cell when there is no sunlight. In case you are wondering, you could still use an alkaline cell to power the unit and do away with the solar cell charger. However, the cell would require changing every two months. Another alternative is to run the circuit from a mains plugpack. In this case, an NiMH (or Nicad) cell must be used and this is recharged from the plugpack. In addition, diode D2 must be replaced with a 1kW 0.25W resistor. Other supply changes to the circuit include moving S1 so that it now connects across transistor Q1. S1’s previous position is now replaced by link LK1, which means that power is now continuously applied to step-up converter IC1 which in turn permanently powers the microcontroller (IC3). Saving power To conserve power, IC3 is normally in a sleep mode; ie, its internal oscillator is stopped, its A/D converter is off and the program is halted. In this mode, IC3 typically draws just 11mA. During this period, a watchdog timer is left running (more about this timer soon) and the RA4 output is set high so that transistor Q1 is off. As a November 2007  35 ➊ ➋ ➏ ➌ 1. Tri-colour LED ➍ 2. 433MHz transmitter 3. Encode/update switch 4. Tank select switch ➎ 5. Pressure sensor 6. NiMH or NiCd cell Here’s a preview inside the Water Tank Level Meter. This unit has the extra parts required for the Telemetry Version (ie, the BCD switches & the 433MHz transmitter module). The pressure sensor is at bottom right although the author now recommends that it be mounted off the PC board (see Pt.2 next month). result, there is normally no supply to Sensor1, ICs2a-2d, the 433MHz transmitter and all those other components that derive their supply from the +5V switched rail. We have also minimised the current drain due to BCD switches BCD1 and BCD2. These switches can connect any of their ‘1’, ‘2’, ‘4’ or ‘8’ inputs to the common pin (C), depending on the switch setting. These inputs are usually tied to +5V via internal pull-up resistors (typically 20kW) at the RB0-RB2 inputs for BCD1 and the RB3-RB6 inputs for BCD2. The RA5 input for BCD1 is pulled to +5V using an external 100kW resistor. The 1kW resistor between BCD1 and RA5 is necessary because this input is susceptible to currents that flow into or out of the pin when voltages go above or below the supply (these currents can reset IC3). Normally, if IC3 is to determine which settings are selected for the BCD switches, their common (C) connections must be at ground level so any closed switch will pull the normally high input to ground. However, this would cause extra current flow because 36  Silicon Chip the corresponding pull-up resistors would be connected across the 5V supply and thus drawing up to 250mA extra current for each closed switch. To prevent this current, we have connected the common pins to the RA4 output of IC3 instead. This out­ put is high at +5V when the micro­ controller is in sleep mode and so whether a switch is closed or not, the BCD switches will not add to power consumption. The RA4 output subsequently goes low when IC3 is awake to allow the switches to be read. This also means that the switchmode step-up circuit comprising IC1 and its associated components does not need to supply much current to IC3 when it is in sleep mode. As a result, IC1 charges L1 for just 28ms once every 6ms and this is just enough to maintain the 5V supply. By contrast, when the supply is required to deliver current to the whole circuit, L1 is charged for 28ms every 150ms. Reawakening IC3 IC3 will “wake up” on any one of two events. The main event is when the watchdog timer times out and wakes IC3 from its sleep. In this case, the oscillator starts up and the internal program starts running. Basically, the watchdog timer will timeout every 16.8s, 33.5s, 67s or 268s, depending on the switch selection for BCD2. The period between “wake-ups” is basically the update period – each time IC3 wakes up, the water tank level is measured and the data transmitted to the base station. After sending this data, the microcontroller then returns to its sleep mode to conserve power. Note that a watchdog wake-up does not light the tri-colour RGB LED and this is again done to conserve power. In order to light the RGB LED for a tank level display, switch S1 (now in parallel with Q1) must be pressed. In addition, IC3 needs to be woken from its sleep independently from the watchdog timer through a different process. Note that, during the sleep mode, the AN1 (pin 18) and AN2 (pin1) inputs of IC3 are set to connect to a comparator within IC3. The AN1 input is at the cell voltage (1.2V), while the AN2 input is at 0V because transissiliconchip.com.au siliconchip.com.au November 2007  37 Fig.8: the Telemetry Version is similar to the Basic Version but adds in a couple of BCD switches and a 433MHz data transmitter module. The BCD switches allow tank selection and set the data update periods. ➊ ➋ This larger than life-size view shows the 433MHz transmitter module (1) and the tri-colour LED (2) mounted at one end of the PC board. The LED colour indicates the water level. tor Q1 is off. As a result, the output of the internal comparator is low because the pin 18 inverting input of the comparator is higher than the pin 1 non-inverting input. That leads us to the second way of waking up IC3 – by manually pressing switch S1 and forcing the comparator output to go high. It works as follows. When S1 is pressed, it bypasses Q1 and supplies power to the temperature sensor (Sensor2) via a 1.8kW resistor. With power applied, Sensor2 will now have at least 2.5V across it and the comparator’s pin 1 input (AN2) will now be greater than the 1.2V from the cell. As a result, the comparator output goes high and this wakes up IC3. And when that happens, the processor maintains power to the sensors and the 433MHz transmitter by bringing its RA4 output low to turn on Q1. Regardless as to how it wakes up (ie, either via the watchdog timer or by pressing S1), IC3 measures the temperature, cell voltage and tank level. It then transmits this data via a 433MHz transmitter module which is connected to pin 13 (RB7). At the same time, the tri-colour LED also lights for about 2s to show the tank level. Note that before measuring the temperature and cell voltages, IC3 changes its AN1 and AN2 ports to digital inputs. This allows IC3 to measure the cell voltage at pin 18 via a 2.2kW resistor and 100nF filter capacitor and to monitor the temperature at pin 1. As with the basic version, the temp­ erature is monitored using an LM335Z temperature sensor. This part of the circuit works as before. At the AN2 input, the temperature sensor voltage is converted to a 10-bit 38  Silicon Chip digital value. This is then converted to °C by the software and the digital data transmitted to the base station where it is displayed on the LCD panel. The temperature can be displayed from -99°C to 100°C. Note that the temperature reading can used to switch off a pump should the temperature drop below a preset point. This is done via the base station and a separate pump control circuit to be described. Cell voltage The cell voltage is measured at the AN1 input. This input converts the voltage to a 10-bit digital value which is again transmitted to the Base Station for display. The displayed voltage is a good indicator of battery charge. A cell voltage that is 1.15V or less has a small “x” located at the top left corner before the “1” in the display reading, to indicate a possible problem with the cell. Typically, a fully-charged NiMH cell will show more that 1.25V on the Base Station display. BCD switches Switch BCD1 is designated the “Tank” switch. This switch can be set to any number from 1-9 or to 0, the number selected representing the tank number. This means that if you have two Water Tank Level Meters (to monitor two tanks), you would set one as Tank 1 and the other as Tank 2. That way, the base station knows which tank is which. The base station has a display option that shows all the selected tanks and their levels as a bargraph on the one display. The order of the display is 1, 2, 3, etc up to 9 and then 0. The 0 tank is placed at the end because not too many people start counting tanks from 0! The encode switch (BCD2) has two functions, one of which is to prevent any neighbouring tank level meters from sending data to your base station. Thus, when a water tank level meter transmits its data to the base station, it also sends the encode selection. The Base Station must also have the same encode selection programmed in to accept the data. This means that if a neighbour’s tank levels are displayed on your base station (unlikely), then it is time to change the encode selection. Note, however, that if you have several water tank level meters, these must all have the same setting for BCD2 and this must be identical to the Base Station encode switch. The encode switch also alters the period between each data transmission of the tank level. If you have the encode switch set to 0, 1, 2 or 3, then the update period is 16.8s. Encode switch settings of 4-7 give a 33.5s update; settings between 8 and B give a 67s update; and settings from C to F 268s, or about 4.5 minutes. The selection you choose depends on the size of the tank to some extent and the number of tanks being monitored. The fewer the tanks, the faster the update periods can be. A slower update rate avoids data clashes. Minimising data clashes Data clashes occur when one tank transmits its data during the same time period as another. This will cause incorrect data reception at the Base Station and the data will be rejected. The more tanks that are monitored the greater the likelihood of clashes. So we need to minimise these clashes or the data at the Base Station will not be updated very often. Data clashes will be worse if each tank has exactly the same update period. For this reason, the tank selection switch BCD1 also alters the update rate slightly between selections. The change is not great and overall is of the order of ±12% but that’s enough to cause any data clashes between tanks to quickly drift apart. In addition, the encode selections at BCD2 also alter the watchdog timer oscillator by a small amount (this is additional to the widely-spaced update values of 16.7s, 33.5s, 67s & 268s). As noted, clashes cause incorrect data to be received at the Base Station, so we need to ensure that the Base Station does not accept this incorrect data. As a result, several safeguards are included to ensure the that only the correct data is processed and displayed. First, we send a start locking code that locks the base station receiver to the transmitter frequency. As a result, data from another water tank meter will be a different rate and so will not lock. Second, the water tank level data and temperature data are sent twice and the base station checks if the data is the same for both transmissions before it accepts it as valid. In addition, siliconchip.com.au Parts List Basic unit 1 PC board, code 04111071, 104 x 79mm 1 IP65 sealed polycarbonate enclosure with clear lid, 115 x 90 x 55mm (Jaycar HB-6246 or equivalent) 1 MPX2010DP Freescale Semiconductor 0-10kPa differential temperature compensated pressure sensor (Jaycar ZD1904 or equivalent) (Sensor1) 1 SPST waterproof momentary switch (Jaycar SP-0732 or equivalent) (S1) 1 18 x 8 x 6.5mm iron-powdered core (Jaycar LO-1242 or equivalent) (L1) 1 3-6.5mm diameter IP68 waterproof cable gland 1 AA cell – see text 1 AA cell holder (Jaycar PH-9203 or equivalent) 1 2-way pin header with 2.54mm spacing 1 18-pin DIL IC socket 1 4-way SIL socket (made from a cut down DIP8 socket) 2 M3 x 15mm screws 2 M3 nuts 2 No.4 x 6mm self-tapping screws 10 PC stakes 1 1.5m length of 0.5mm enamelled copper wire 1 150mm length of medium-duty hookup wire 1 270mm length of 0.8mm tinned copper wire 2 100mm cable ties 1 length of 3mm ID clear vinyl tube (length to suit water tank depth and installation) the encoding selections for the Water Tank Level Meter and the Base Station must match, the water tank level must not be more than 110% and the stop bit encoding must be correct. Data protocol The protocol for sending data is as follows: initially, the Water Tank Level Meter sends a 50ms transmission to set up the receiver to be ready to accept data. A 16ms locking signal is then sent, followed by a 4-bit encode signal and the 4-bit tank number. siliconchip.com.au 1 length of 25mm PVC tubing to support the tubing or a suitable weight 4 200mm cable ties Semiconductors 1 TL499A power supply controller (IC1) 1 LM324N quad op amp (IC2) 1 PIC16F88-I/P microcontroller programmed with “water tank level meter.hex” (IC3) 1 LM335Z temperature sensor (Sensor2) 1 BC327 PNP transistor (Q1) 1 1N4004 1A diode (D1) 1 common cathode RGB LED (Jaycar ZD-0012 or equivalent) (LED1) Capacitors 1 470mF 10V PC low-ESR electrolytic 1 220mF 10V PC low-ESR electrolytic 1 100mF 16V PC electrolytic 3 100nF MKT polyester 1 100nF ceramic 3 10nF MKT polyester Resistors (0.25W 1%) 1 100kW 1 1.8kW 3 22kW 7 1kW 2 10kW 1 330W 1 2.2kW Trimpots 1 50kW horizontal trimpot (code 503) (VR1) 1 1kW multi-turn top adjust trimpot (code 102) (VR2) 1 10kW multi-turn top adjust trim- Next, the 8-bit tank level is sent, followed by the temperature (eight bits with bit 7 as a sign bit), cell volts (8 bits) and then the 8-bit water level again and the temperature again. The 8-bit stop code which has a value of 170 is then sent. These stop bits indicate that the signal is a water tank signal. A different stop bit sequence is used for the water pump control transmission. Note that the locking sequence is included at the start of each transmission because the oscillator rate is slightly pot (code 103) (VR3) 1 10kW horizontal trimpot (code 103) (VR4) Extra Parts For Telemetry Version 1 BCD 0-9 DIL rotary switch (BCD1) (Jaycar SR-1222 or equivalent) 1 BCD 0-F DIL rotary switch (BCD2) (Jaycar SR-1220 or equivalent) 1 433MHz transmitter module (Jaycar ZW-3100) 1 6.5mm diameter IP68 waterproof cable gland 3 PC stakes 1 2.54mm jumper shunt 1 Solar garden light (Homemaker Lifestyle (Kmart) or equivalent – this includes the solar cell, an AA NiMH or NiCd cell & the 1N5819 Schottky diode (D2)) 1 100nF MKT polyester capacitor 1 100nF ceramic capacitor 1 1kW 0.25W 1% resistor 1 length of single core shielded microphone cable (length to suit installation) Extra parts if pressure sensor mounted inside tank 1 bulkhead box, 65 x 38 x 17mm 1 4-way header with 2.54mm pin spacing 2 M3 x 15mm Nylon screws 2 M3 x 6mm Nylon screws 2 M3 x 9mm tapped Nylon spacers 1 2-pair (4-wire) sheathed telephone cable (to suit installation) 5 100mm Nylon cable ties Neutral-cure silicone sealant different for each tank selection. In operation, the receiver must lock onto the transmission rate or the data will be read incorrectly. The data from the 433MHz transmitter is sent at a nominal 1k bits per second. The receiver in the Base Station detects the signal and delivers the same data at its output. That’s all for this month. Next month, we’ll show you how to build both versions (Basic & Telemetry) of the Water Tank Level Meter and deSC scribe the Base Station. November 2007  39