I haven't had the inspiration to come up with anything new for this website for some time, however I was recently in the Lake District on an open top boat in the cold March rain and two questions popped into my head. The first, which is of lesser relevance to this article, was "why am I on this feggin' boat in the rain?" while the second, which was far more interesting, went along the lines of "if the heater fails in my aquarium, my tropical fish are going to be fit only for serving with chips. How can I protect the little blighters against this?"

I've had a heater failure before and I'm sure I'll have another one again one day. While the loss of a school of cheap and easily replaced Neon Tetra will have the effect of me uttering a (probably) testicular related swearword at a moderate volume, the loss of some of the larger and more expensive fish now occupying my tank such as the Tin Foil and Torpedo Barbs will doubtless invoke the use of a swearword (likely) relating to a ladies front-bottom, shouted at an amplitude capable of penetrating the wall between us and the little old Indian lady who lives next door.

Now we certainly wouldn't want *that* to happen would we?

So I set about thinking of how I could cobble some electronics together to monitor the temperature of my aquarium which could alert me should it drop too low through heater failure or rise too high from a thermostat fault. This is the final result...


P4230081

The final installation, after some days of design, prototyping and construction.

P4230001

 

Having not built a thermometer before, I set about looking to see if there was an easy way to measure temperature in the range of 21-27C which most tropical fish like lounging around in. I expected I would have to use a thermistor as the in-tank sensor as the resistance of a thermistor changes with temperature. Instead, a bit of Googling turned up the LM35 precision temperature sensor IC. Driven from a 5V source, this little 3-pin TO-92 cased wonder outputs 10mA for every degree Celsius. Those witch-burners who prefer the old-fart imperial system will be pleased to hear Fahrenheit versions are also available although personally I don’t care if you do get thirteen groats to every wassock and six wassocks to a pratt so I’m metric all the way.... but I digress. So anyway, with my aquarium being a lovely 25 degrees Celsius, the LM35 will output 250mV. By fitting the LM35 into 2.5 metres of silicon air-hose and bunging up the end with aquarium sealant, I’d have a temperature probe I could place into the tank. What I then wanted was a way to measure and display this Voltage, a method of detecting whether it was too high or too low and some kind of visual/aural indication to get the attention of the sober and responsible fish-keeper should the reading reach and breach defined limits.


The final circuit design is below. Originally it was simpler but it seems to have grown organically at both the prototyping and build stages after slapping me across the face with some technical hitches.


thermo

This multicolour mess can be broken down into it’s modular parts which are green (detection, measuring and numerical display), red (power control and distribution), yellow (abnormal reading detection), cyan (latch and alarm display) and pink (audible alarm).

Parts list:

Resistors Capacitors Transistors Integrated Circuits

100k R1, R4, R5, R14

100pF C1 TR1 NPN (BC107/8) 7805 Voltage Regulator 
1K R2, R6 0.1uF C2 TR2 PNP (BC212/3) CD4078 8-input OR/NOR gate
470k R3  0.47uF C3 TR3 NPN (BC107/8) ICL7107 A/D Converter
5.6k R7, R8, R9, R12, R13, R16
 
0.22uF C4   7660 DC-DC Converter
330R R10, R15 10uF C5, C6 Miscellaneous 555 Timer
22k R11 10nF C7 SW1 Push to break switch  
300k R17 100uF C8, C9 BZ1 Piezo self-driving sounder Diodes
10k R18   LD1 & LD2 LEDs D1-D7 Small signal (1N4148) or similar
VR1 1K POT   Common anode 7-segment LED display  



So we have a sensor that outputs a Voltage that is in direct correlation to the temperature. Need a low cost way to measure and display a Voltage? I give you the ICL7107. This wonder chip does everything for you, A-D conversion, decoding, timing, display driver. All you have to do is provide the required external components and feed in the output Voltage from the sensor and this baby will display it numerically on four 7-segment displays. That’s a digit each for ones, tens and hundreds with the fourth (leftmost) display capable of showing a ‘1’ to represent a thousand or a minus sign for a negative Voltage.

In my case, I’m going to set the 7107 to read 2V FSD so that when I connect my LM35 sensor at 25C, the display will read 0250mV. Well, actually it will just read ‘25’ as I won’t be fitting the leftmost (thousands) digit or the rightmost (ones) digit, I’ll just be using the hundreds and tens outputs to represent tens and units of temperature. In this way, the 7107 will be displaying a reading in miliVolts but it will actually look like a temperature readout. Resistor R3 sets the scale for the 7107 and the datasheet shows 47K will set it to 200mV FSD while 470k will set 2V FSD. Of course, the 7107 can read much higher Voltages at different Full Scale Deflections but that's outside the scope of this project.

When it comes to detecting if the reading is too high or too low, there are a couple of ways I considered. One that I didn’t put much thought into because I didn’t have ready access to the parts was to use comparators to check the reading against high and low reference Voltages. Instead I opted to trigger off the numbers actually being displayed by the readout as this seemed more interesting. I also thought it might require fewer components but the complexity of the circuit diagram grew when I hit a couple of hurdles while prototyping. More on that later for those who don’t get bored and chicken out.

The range of 21-27C happens to be quite useful for keeping tropical fish happy as it is bookended by the high teens and the high twenties. To cut a long story short, if the second digit is an 8,9 or 0 then the fish are either fryin’ or freezin’ as the water will be 28, 29, 30 at the high end or 18, 19, 20 when low. If we look at how a seven segment LED display forms the numbers, we can see there are a combination of segments illuminated together only when an 8, 9 or 0 are rendered, segments A, B, C, D  and F. Segments C & D illuminate together in other numbers but A, B and F only illuminate together for an 8, 9 or 0 so we know if these three segments are on together then our fishy friends have a problem.


7segnumlayout

7segpinout

 
Pinout of a standard 7-segment common anode dual display showing which pin connects to which LED cathode



My original plan was simply to run the A, B and F outputs for the second digit from the 7107 IC into an AND gate however this is where I ran into problems. The 7107 requires a common anode display, so the LED segments are already connected to 5V and their individual cathodes are connected to the output pins of the 7107 IC. To have a segment switched off, the 7107 outputs 5V so there is no potential difference to light it, while switching on a segment requires the 7107 pin to drop low allowing current to flow from the anode through the LED where it is sunk by the chip. In effect then, the 7107 works opposite to how you’d expect as it switches outputs on to turn segments off and vice versa. My plan for an AND gate was out the window as segments A, B and F being on would mean 0, 0 and 0 going into my AND gate which would give me 0 out. In fact, there is no number display where segments A, B and F would all be at ‘1’ (off) so an AND gate would never see it’s outuput triggered.

What I needed was a three input NOR gate as the output of such would only be high on an input of 0, 0, 0.

Cue the CD4078 eight input OR/NOR IC. With redundant inputs tied together effectively making it a three input gate, my ‘alarm’ condition of 0, 0, 0 on the inputs from segments A, B and F being illuminated would now result in the NOR output switching on, giving me a trigger condition and a means of activating other circuitry to alert the responsible (and by now, part drunk) fishkeeper.

If we look at the truth table for the CD4078 OR/NOR gate when using three inputs we can see the NOR output will be high only when the three inputs are all low:

Input Input Input      
A B F OR output  NOR output
0 0 0 0 1
0 0 1 1 0
0 1 0 1 0
0 1 1 1 0
1 0 0 1 0
1 0 1 1 0
1 1 0 1 0
1 1 1 1 0


Only it wasn’t that bloody simple. The clever bods who designed the 7107 IC knew people would be hanging 7-segment LED displays off it, after all, that’s what it’s for. Now the problem with a common anode 7-segment LED display is that the current it consumes varies according to the number being displayed. Assuming 8mA per segment, displaying a ‘1’ will require 16mA while displaying an ‘8’ will suck up 56mA. Also, LED’s being LED’s, your average off-the-shelf 7 segment display will require a forward Voltage of about 2 - 2.5V depending on the colour and specification of the LED’s. If the common anode is connected to 5V and the 7107 drops it’s output pins to 0V to activate the segments, they’ll turn a funny colour and pop in a cloud of smelly smoke within seconds. The varying current requirements means a single series resistor can’t be used on the common anode to lower the Voltage as the display brightness would vary according to how many segments are illuminated at any one time, so in these circumstances a series resistor is usually required in-line with each output pin and each segment cathode to protect the display. In this application where two full displays are employed, that could potentially add fourteen resistors to the circuit. To keep circuit design to a minimum, the eggheads designing the 7107 did not build it to drop to 0V and instead the output lines drop to about 2.5V when segments need to be illuminated. This should be enough to run most displays and those requiring a lower Voltage simply need one to three series diodes on the anode to drop the Voltage further. This is great until you come to interface other logic gates with the outputs as I am doing and indeed, as far as my CD4078 NOR gate is concerned, the 7107 dropping from 5V to 2.5V is still a logic ‘1’ whether those LED segments illuminate or not. To pull down the inputs for the benefit of the NOR gate, an extra diode and resistor were required on each of the three inputs (D2-D4 and R7-R9).

So, a few extra components but the NOR gate was now doing it’s thang. When an 8, 9 or 0 is illuminated on the second digit, segments A, B and F will be on, the corresponding 7107 outputs will be dropped and the NOR gate is now able to detect the drop and switch on it’s output.

The next problem was what to do with that output. The simplest thing would be to hang a light or piezo sounder off it but that wouldn’t necessarily tell the whole story. What if heater failure was intermittent? The temperature could become abnormal for a time before the fault righted itself and conditions normalised. Imagine, for example, you went away for the weekend and the thermostat stuck. The tank rises to 50C killing the fish, then the thermostat pops back and the water cools to the correct temperature again. You’d return home and wonder why all the fish were floating on the top when everything looks normal. Worst case, you might medicate the tank for diseases that aren’t there and replace the stock without realising you have an intermittent fault that will strike again.

I decided to build a transistor latch which is triggered from the high NOR output and remains triggered even if the NOR gate drops low again. Indeed, this was needed with the circuit design up to this point because the NOR output is only triggered on a reading of 18, 19, 20 or 28, 29, 30 under normal conditions. Should the temperature pass these readings, the NOR output will drop as it cannot distinguish between a reading of 21-27 or 31-37 or anything else as it only looks at whether the second digit is an 8, 9 or 0 and is not connected to any segments of the first digit. A latch would mean the alarm is triggered as the temperature passes though the 8, 9, 0 threshold and remains triggered as it comes out of that threshold range even if conditions normalise.

The latch is simple enough. Transistor TR1 is activated by the high output of the NOR gate and feeds into Transistor TR2 to switch it on. A feedback loop from TR2 back into the base of TR1 keeps the transistors active even if the original signal from the NOR gate drops low again. Only by pushing SW1, a push to break switch on the feedback line, can the loop be broken and the latch deactivate (assuming the NOR gate isn’t still holding it high because of an abnormal reading).

The latch output is then used to drive a red LED salvaged from an old optical mouse which provides visual indication of an alarm condition even if the temperature returns to within the accepted range. The latch output could also drive an audible alarm if a piezo sounder were hung from it. I wanted an audible alarm but I didn’t want anything too in-yer-face. A continuous piezoelectric chirp isn’t pleasant for me or the fish to listen to, so I put in something a little more subtle using a 555 timer. This IC is being used to pulse a piezo sounder giving a short ‘bleep’ about every 20 seconds. It’s regular enough not to be missed while discreet enough not to give the fish or the wife a headache if it starts sounding off when I’m not around. Diode D7 is used in the 555 circuit to distort the mark/space ratio of the square wave generated by the timer in order to ensure the sounder is off for a lot longer than it is on.

In fact, for those interested, we can calculate the timing for the 555 IC output as follows:

Mark time (piezo sounder on) is derived from 0.693 x R16 x C9
therefore... Tm = 0.693 x 5.6x103 x 100x10-6 = 0.388 seconds.

Space time (piezo sounder off) is derived from 0.693 x R17 x C9
therefore... Ts = 0.693 x 300x103 x 100x10-6 = 20.79 seconds.

In this application, the 555 timer has it's reset pin pulled down by R18 so it sits idle until the latch output pulls it high allowing it to start generating an output for the piezo sounder.

 
Despite having finished prototyping and having already built the final circuit at this point, I found I wasn’t quite satisfied with the NOR gate method of detection because it relied on the initial conditions being correct, i.e. it needed to be used in a tank that was already at 21-27C and it couldn’t detect if the temperature was already well outside of this range. For example, if the water was at 35C at the point where this circuit is first employed, there would be no alarm condition. It would read 35 on the display but the NOR gate would not be triggered because ‘5’ is a valid number for the second display. In fact, the alarm *would* be triggered if the temperature dropped back to a still high but somewhat healthier 30C because ‘0’ is not valid for the second display. It would be the same for any other temperature where the second digit was not an 8, 9 or 0 so 11C would not trigger the alarm should this circuit be used on a new tank being set up but once you switch the heater on and the temperature rises to a healthier 18-20C, the alarm would sound. Similarly, there would be no alarm condition if the threshold temperature was skipped which could happen during a water change if the tank was already at 27C, had a significant amount of water removed and quickly replaced by much hotter water causing an immediate jump in the reading to 31C or higher without it passing through the threshold range. This is unlikely however as this circuit takes three readings per second and besides, anyone performing such a cack-handed water change would have probably already killed their fish and no gadget of mine can stop them being an idiot.

These are known limitations and can be accepted as such, but there is a fairly easy fix. If we look again at how a seven segment display renders it’s numbers, we can see that there is one segment which, handily, is only ever off if a ‘2’ is displayed - segment ‘C’. For all other numbers, this light will be on. As we want to work with temperatures in the 21-27C range, we know that the first display should always be reading a ‘2’ as anything else puts our water temperature right out of range.

 
 
7segnumlayout

I’m using transistor TR3 as a NOT gate hooked into the first digit's segment 'C' line. So long as the 7107 is holding this line high and keeping segment 'C' switched off, TR3 is active so current flows via R6 through it to ground. As soon as the 7107 drops the Voltage to illuminate segment 'C', we know the display is no longer showing a ‘2’ so the temperature can't be in the Twenties range and we'll want to see an alarm condition. The Voltage drop on the line will shut off TR3 so the current flowing through R6 now has to pass through diode D5 to the latch input and thus the latch is triggered. With this modification, the only temperature conditions that won’t trigger the latched alarm condition now is the 21-27C range we’re interested in.

Probably should’ve used comparators huh?

 
 
 
IMAG0237
Under construction. The largest component is the self driving piezo sounder. I used a translucent blue project case from Farnell to house the circuit however space was tight and so the board is densely populated. The 7-segment display is on a separate board located in what is actually a PP3 battery compartment which is why it's connections are being made to the 7107 via a ribbon cable. The 7107 is mounted upside-down to keep pins 1-20 close to the top edge of the board as few external components are required on this side. Although some diodes connect to pins 11, 12 and 13, these have been mounted within the socket under the IC to save space. At this stage of construction, the circuit was working however the transistor NOT gate was yet to be fitted and this was later located on the left side of the board next to the 8-pin IC. Sensor input wires and the incoming power line both feed into holes drilled into the bottom of the case which is also where the push-to-break reset switch is mounted.


I’m powering my circuit from a recycled mains adaptor that used to charge up a toy (one of mine, not the kid's). This brick puts out a regulated 15V at up to 300mA. My circuit requires a third of this (both Voltage and current), so to bring the Voltage down to a clean 5V I’m using a 7805 regulator IC. Mine is capable of running at up to 1A with a heatsink however it can supply the required 100mA without one.

Power control is a little more complicated than may be expected as a -5v supply is also required on pin 26 of the 7107 IC. There are circumstances where the -5v line isn’t needed, however if you want the chip to generate it’s own timing and not require an external reference as I do then it is necessary. If an external reference was used, the -5V line could be left out according to the datasheet as I’m not reading a negative Voltage and the readings being taken are below 1.5V.

To derive -5V from a 5V source, I’m using a 7660 DC-DC converter. This IC requires just two 10uF capacitors to generate -5V for the 7107 which it uses in conjunction with the RC components of R1 and C1 to run an internal oscillator at 48kHz allowing it to take three readings per second.

According to the 7805 regulator datasheet, a capacitor is required on the regulator ouptut if the power lines are located some distance from from the 7805 IC in order to reduce noise. In this case, my temperature probe consists of the LM35 sensor located about 2.5m away from the main circuit board down a silicon air hose that is dropped inside the tank. When I first built the probe, I left out the capacitor and all seemed well until the fluorescent lights illuminating the tank switched on. Suddenly my readings shot up to between 30 and 45 which was clearly nonsense and the result of noise from the high Voltage ballast used by the lighting. To squash this noise and get accurate readings, I had to splice open my silicon hose and fit a 100uF capacitor (C8) at the end of the probe between the power lines of the LM35 sensor. I then covered it all over with aquarium silicon. After 48 hours of drying, the probe went back into the tank and all was well.


P4230088The probe end showing the LM35 sensor IC (arrowed red) and the 100uF capacitor (arrowed green). At about 5mm, the silicon tube was tricky to work with and a lot of Vaseline had to be used to thread the three wires down it. Once the wires were through the other end, the LM35 was soldered into place and the capacitor was run off the two power connections. The IC and capacitor were then greased up and pushed back up the tube before the end was sealed with aquarium sealant.
 

The original circuit was prototyped on a breadboard as shown in the picture below. As you can see, there is a third (red) display being used in the prototype and this shows tenths of a degree (i.e. it’s connected to the ‘ones’ output of the 7107 on pins 2-8), so in this case the reading being displayed is 22.2C (or 0222mV). I’d have liked to have kept this third digit in the final circuit but I didn’t have room in my case to incorporate it and I didn’t have another common anode green display amongst all my componentry cack. Had I included it, the decimal point to the right of the second digit would have been wired through a 330 Ohm resistor to ground to keep it illuminated. If I can source a small enough common anode green display, I may look at retrofitting it at a later date.


IMAG0191

To calibrate the circuit, one just needs to place a Voltmeter onto the output of the LM35 and adjust potentiometer VR1 until the reading from the 7107 display matches the Voltmeter. The value of R2 sets the sensitivity of VR1 and, interestingly, the 7107 datasheet shows a 24k resistor however I found I had to drop it to 1k to get any sensible adjustment out of VR1. Calibration is easier with the third display connected to the 7107 as a Voltmeter reading of, say, 252mV would just look like ‘25’ when using two digits off the 7107, but you don’t know for sure if it’s really showing 25.0 or 25.9 or anything in-between. My tip in that case is to get the LM35 to a borderline temperature so it reads something like 249/250mV and then adjust VR1 so it’s flicking between 24/25.

Sharp minded readers who haven’t been bored to tears at this point may have spotted a design flaw with this circuit. In the event of a power cut, the heater in the aquarium will stop working - and so will my super warning system as I’m running it from the mains and not a battery. If the power outage is prolonged then the water will cool but there will be no temperature display or alarm to warn the (now very drunk) fishkeeper.

I don’t see this as a problem however because if there is a power cut and I’m at home, I’m gonna know about it as I have plenty of electrical gadgetry that I will quickly spot isn’t working. I am therefore aware of the implications that a prolonged outage will have on my water dwelling pals and I can monitor the mercury thermometer. There has certainly been an instance of a power failure in the night before which I haven’t noticed for several hours because I was asleep and dreaming of naked... uh.. wife...  but even then the temperature hadn’t dropped to danger levels by the morning and I was able to keep an eye on things until Eon Energy put the plug back in at their end.

If I’m not at home to notice the power failure then an alarm is useless anyway and is just going to annoy the fish and the little old lady next door.

Thinking whilst writing in my super multitasking way, I suppose it wouldn’t be too hard to integrate a battery backup into the circuit should it be required. The easiest way I can think of, off the top of my head, would be to use a relay with the coil on the incoming 15V line so it is energised by the output of the mains transformer. The 7805 regulator input pin could hang off the relay COMmon while the 15V transformer output would connect to the Normally Open contact and a PP3 (9V) battery would connect to the Normally Closed contact. While the relay is energised, the N.O. contact is closed so the transformer DC output connects through this and through COM to the input of the 7805 regulator and powers the circuit. Should the input power fail, the relay coil will de-energise and the circuit path will switch to the N.C. contact connecting the battery through this and through COM to the regulator. I guess a second relay or a secondary set of contacts would also be required to cut the power line to the anode of the seven segment display when on battery in order to prevent it being drained by the LED segments in much the same way as a clock radio battery backup works. This is something I’ve just come up with though so there may be something I’ve missed and relays are probably not a particularly power efficient way of cracking the problem.


 
P4230085
Final construction with case top removed. Those with sharp eyes may spot a couple of differences to the earlier picture as the components forming the transistor NOT gate are now visible to the left of the board and the 7805 regulator is sporting a rather natty heatsink. Although the regulator does get quite warm, it is operating within design limits so the heatsink isn't really necessary but as I happened to have one and it was small enough to fit, I figured it wouldn't hurt to use it.

P4230086
The whole shebang. Notice the choke installed on the probe tube just to help with keeping noise off the sensor line.
 
 

Okay so this circuit is far more complicated than I originally planned and there are some easy ways to simplify it. As I mentioned before, comparators would probably be a more efficient way of detecting the high and low thresholds without the need for the NOR and NOT gates. If a readout of the temperature wasn’t too important and you just wanted something that would alert you to an underheat/overheat problem, the 7107 and 7-segment display could be cut out with the LM35 sensor driving comparators directly. The latch can also be dumped if you only want a realtime readout or alarm and the alarm can be in the form of an ordinary self-driving piezo-electric buzzer sounding continuously if you wanted to leave out the 555 timer. In short, something like this can be as easy or complicated as you like and my circuit is only built this way because I wanted it to work like this and had certain parts available.

The CD4078 IC is a OR/NOR IC and it’s only the NOR function I’m interested in for this circuit. That said, I don’t like leaving an IC output doing nothing so LED LD2 hangs off it via resistor R10. It’s pretty pointless to be honest but the original idea was that it would act as a ‘situation normal’ indicator as it would be on while the NOR gate wasn’t triggered (i.e. when operating at 21-27C) although reading the figure on the 7-segment display should be a good enough indication of whether or not everything is normal. It doesn’t quite work like that however as this LED is only on when the temperature is outside of the ‘8, 9, 0’ threshold range making it pretty useless as an indicator of all being well as it will illuminate at 11-17C, 31-37C and other unsuitable temperatures. I decided to leave it included on my final circuit build and I’ve used a green self-flashing LED. The visual appearance is that of a ‘heartbeat’ which should show under normal conditions but stop when the threshold range is entered. It’s not of any value however and can be left out to simplify the build.
 

P4240006Placing the probe in cold water triggered this low temperature alarm. A '6' on the second digit means the NOR gate is inactive so it is the transistor NOT gate holding this alarm state on.   P4240007
This reading is within the threshold range. The transistor NOT gate is happy as the first digit is showing '2' however the '0' on the second digit means the NOR gate now holds the alarm active.
     
P4240008
Back to a healthy temperature so both the NOR and NOT gates will be in their non-alarm state (off for NOR, on for NOT), however the red light and audible alarm remain in effect because of the latch. Only pressing the reset switch will clear the alarm condition.
 

P4240009
Here the reset switch has been pressed breaking the latch feedback loop. With nothing to re-trigger the latch, the alarm condition is cleared. Had the display remained outside of the 21-27C range, the reset switch would be ineffective.


I'd be happy to hear from any real electronics smart-arses out there who think I've done this in a really daft way and have a better solution. Feel free to drop me a line to: service at r3uk dot com.