Welcome to the TempRat Page


General Information

The TempRat is going to be a little device to switch things off if the ambient temperature rises above a definable level.
A certain time before switching off, a message is sent down the serial link to the host computer telling it how long until the power will be switched off.
The TempRat will then switch things back on once it thinks the temperature has gone back to normal.
The TempRat displays the ambient temperature on a 2 digit display, and also sends the temperature down the serial link once a minute for a c omputer to log or monitor.
All critical temperatures and time delays are settable, and stored in EEPROM in case the power fails.
The TempRat has an operating temperature range of 0 degrees to 70 degrees.


The MicroController

[Microcontroller Circuit]
The MicroController used in the circuit is an ATMEL 89C2051. This micro has:

  • 2Kb of reprogrammable Flash Memory
  • 128 x 8bit RAM
  • 15 I/O lines
  • Two 16 bit timer/counters
  • 6 interrupt sources
  • Programmabe serial UART, and an
  • On chip analog comparator
I am running the Micro with a 4MHz crystal, which allows baud rates of about 2400 and less to be generated.
Have a look at the code, if you want.


Temperature Sensing

The temperature sensing in the TempRat is done using an LM334Z. This is little device that outputs the current temperature in volts, with 10mV per degree Kelvin. This means that at 0 degrees centigrade, the device will be showing about 2.73 volt s.
This voltage is then compared to the reference voltage (2.5 volts from an LM335-2.5) and amplified through a differential amplifier with a differential gain of about 220/47 = 4.69.
This gives, from an input voltage swing of between 2.73V and 3.43V, a (thoeretical) output voltage swing of from 1.07V to 4.35V, working out to a 46.9mV per degree (which is a lot easier to measure, than 10mV/deg).
These things can be seen in the schematic sections below...
[Temperature Sensing Circuit]
[Voltage Reference Circuit]

[Comparator Circuit] In order to save on components, instead of putting in an ADC, the analogue comparator in the microcontroller is used to determine the voltage. This is done by charging up a known (fairly accurate) capacitor an d determinign how long it takes while discharging to get to the same voltage as the sensor.
The time is measured accureately by using one of the timers in the processor.
Of course this equation for the time is an exponential one and the function would probably use up all the code space available (only got 2k!), so I have not put the equation in the code, but used a lookup table instead.


Dual 7 Segment Display

The current temperature is measured every second, and displayed on a dual 7 segment display, via two 7 segment decoder/driver chips. Each segment has a 1K current limiting resistor to keep each segment at a constant brightness, and to keep the power cons umption down. [Display Circuit]


Serial Communications

The serial UART on the microcontroller is used to generate the correct bit stream at 2400 baud, 8 data bits, and 1 stop bit. A MAX232 chip has been used to generate the R S232 voltages from the bit stream.
No handshaking has been implemented due to the lack of free I/O on the micro.
[Serial Comms Circuit]


C Program Code

The program for the Micro was written in C, using Hi-Tech C for the 8051. You can have a look at the main code I wrote for this device by clicking on main.c (15.2Kb).



The following people/companies have helped me (knowingly or unknowingly) design and test this beast:

Virtual Logic, PTY. LTY
The place where I used to work. My boss and others there helped in the design, supplied me with a few chips, and also thaks for the use of the equipment on weekends.
Maxim Integrated Products
For supplying free samples and data sheets of the MAX232 chip.
National Semiconductors
For supplying free samples and data sheets of some other chips.

by Tim Johnson.