Heat Monitoring System - NUST Term Project

Temperature Monitoring and Control System - 8051 / 8052

The Coding and programming is updated. You can find it out at http://elprojects.blogspot.com/2010/02/c-and-assembly-code-for-8051-based.html.

Certificate of OwnershipThis microcontroller based project, report and everything related to it, including the hardware and the softcopy belongs to :


Our microcontroller based project is based on making a heating system that turns the heater on or off, by sensing the temperature of the environment. The required temperature of the environment can be set by the user. This heating system is based on feedback control.
Feedback describes the situation when output from an event or phenomenon in the past will influence the same event/phenomenon in the present or future. When an event is part of a chain of cause and affects that forms a circuit or loop, then the event is said to "feed back" into itself.

Similarly our heating system turns on the heater or turns it off, based on the past information that in this case is the temperature measured. And consequently as the temperature is changed due to the heater, the system will compare it with the threshold set by the user, and influence the output, i.e. the heater. Hence making it a feedback loop.

Problem Definition (Developing a Practical Approach)
There are a lot of chemical and manufacturing processes in which a substance or a reaction have to be kept in a controlled environment. This controlled environment involves maintaining pressure, humidity, and temperature. So the problem that we have opted for is controlling the temperature environment.

Temperature or in better words heat content, is immensely important in chemical processes, such as: extraction, refining, cracking, polymerization etc etc. These reactions are temperature specific, and altering the temperature of the reaction may vary the reaction, and consequently the end product. So maintaining and monitoring the temperature in such applications should be a process that is accurate and quick.
The temperature would be altered by a heater, and monitored by a sensor, and controlled by the microcontroller. The user would input the threshold temperature, and our system will maintain that, throughout the process.

Technical Discussion

  • This project can be accomplished in various ways. Some of them are listed below:
    Manual switching of the heater using a thermometer as a reference
  • Electronic switching using op-amp as a comparator according to the temperature sensed by sensor.
  • Electronic switching using a MICROCONTROLLER according to the temperature sensed by sensor (microcontroller based projects are most of the time reliable)
Our Choice

It was apparent that the first option is by far the most impalpable one. Because it requires continuous dedication of a person and it would be quite inaccurate.
The second choice is good enough, but it doesn’t give our system the versatility we are wishing to give it. The comparator can be adjusted to compare one value at a time. And this can be a tedious job.

The third choice is the best one; as it provides dynamic readings, continuous monitoring, and versatility for our threshold temperature.

What actually we want to do with the microcontroller is that, we will input the threshold temperature using a keypad, and the MICROCONTROLLER will compare it with the temperature measure with the sensor. If the threshold temperature is less, the heater would turn on, otherwise it would remain off.

Block Diagram of Heat Monitoring and Control SystemClick on the diagram to magnify it to the actual size. This microcontroller based project can be taken as an home assignment for newbies.

Discussion of various modules

The environment is the place that requires the temperature to be set and monitored. The heater and the sensor is used in this area.
The sensor used in our system is a TEMPERATURE SENSOR, or moreover a Celsius TEMPERATURE SENSOR. It produces voltage linearly as per the temperature of the environment.
The heater is used to change the temperature of the environment.
The interface is the medium through which our controller recognizes the electrical signals from the sensor.
The display would show the current temperature, and the threshold temperature.
The microcontroller is the heart of our system. It gets data from the sensor through the interface, controls the heater, and also controls the display.

Theory of Operation of Microcontroller based Heat Monitoring System
The modules discussed earlier amalgamate into a system that monitors the temperature continuously. The sensor, senses the surrounding temperature, and produces a certain voltage as per the temperature sensed. The sensor used here, changes the voltage across it linearly with the temperature change.

This voltage Vo is fed into the ADC. The ADC converts this analog voltage into digital form, or being more specific, in binary form; the reason being that the data from the sensor can be recognized and processed by the MICROCONTROLLER.
Sensor used here, changes the voltage across it linearly with the temperature change. The TEMPERATURE SENSOR used in the project is the LM35 : This sensor provides a change of 10mV/~ analog.
output: Vo=10x 10-3T or, Vo = 0.01 T
Where, Vo is the sensor output voltage in Volts, and T is the temperature in oC

The ADC is a device that translates analog input into a digital form. An ADC has n-bit resolution; where n can be 8,10,12,16 or even 24 bits. A higher resolution ADC provides a smaller the step size, where the step size is the smallest change that can be discerned by the ADC. For our purpose, the number of bits required in our ADC is 8. The output of the ADC is determined by the formula: Vin/(step size).

An 8 bit ADC has 256 steps, hence the step size for 5V input is: 5/256= 19.53mV. But for our ease we are using 1.28V at Vref/2 pin of the the ADC. This makes the maximum input equal to 2.56 thus making the step size as: 2.56/256=10mV
According to the step size we have calculated, at 1 oC change in temperature, the sensor would output 10mV, consequently adding one to the binary digit at the output. So at 0 oC I have 0V, which gives 00000000B output, therefore if the temperature is 25 oC the output of the ADC would be: 00011001B = 0019H=25D.

The MICROCONTROLLER we are using is AT89S52. The output on the ADC is fed into one of its 8-bit ports. The MICROCONTROLLER manipulates the data and it outputs the temperature to be displayed on one of its other ports. The output is shown on an LCD screen. It also turns on or turns off the heater.
If the temperature is less than the temperature we want, i.e. the threshold temperature, the MICROCONTROLLER would turn on the heater, if it is equal or greater it would turn it off. This process would be repetitive.

So in a nutshell, our hardware arrangement, would first read data from the sensor, then do data acquisition and translation, and then display the temperature on a screen. And while doing that the heater is turned or on off according to the surrounding temperature.

Controlling system
For our controlling system we chose a MICROCONTROLLER, more specifically AT89S52. We chose this powerful MICROCONTROLLER because it catered for our demands, providing us with an effective and an inexpensive solution. And besides this, its ability of in-system programming, made it much easier for us to program, erase and reprogram its flash memory when ever we wanted.

Description of AT89S52

The AT89S52 is a low-power, high-performance CMOS 8-bit MICROCONTROLLER with 8K bytes of in-system programmable Flash memory. The device is manufactured using
Atmel’s high-density nonvolatile memory technology and is compatible with the industry-standard 80C51 instruction set and pinout. The on-chip Flash allows the program memory to be reprogrammed in-system or by a conventional nonvolatile memory programmer.By combining a versatile 8-bit CPU with in-system programmable

  • Compatible with MCS-51® Products
  • 8K Bytes of In-System Programmable (ISP) Flash Memory
  • Endurance: 1000 Write/Erase Cycles
  • 4.0V to 5.5V Operating Range
  • Fully Static Operation: 0 Hz to 33 MHz
  • Three-level Program Memory Lock
  • 256 x 8-bit Internal RAM
  • 32 Programmable I/O Lines
  • Three 16-bit Timer/Counters
  • Eight Interrupt Sources
  • Full Duplex UART Serial Channel
  • Interrupt Recovery from Power-down Mode
  • Watchdog Timer
  • Dual Data Pointer
  • Power-off Flag

Data Acquisition and Description of 0804
We are acquiring digital data by using the ADC. The ADC that we are using is parallel, 8-bit ADC. Namely 0804. We dint use a higher resolution ADC, because we didn’t need one, we didn’t want a lower step size. The step size provided by this ADC was enough.

The ADC0804 is a CMOS 8-bit successive approximation A/D converters that use a differential potentiometric ladder similar to the 256R products. This converter is designed to allow operation with the NSC800 and INS8080A derivative control bus with TRI-STATEÉ output latches directly driving the data bus. These A/Ds appear like memory locations or I/O ports to the microprocessor and no interfacing logic is needed.Features can be summarized as under :-

  • Compatible with 8080 microprocessors derivatives-no interfacing logic needed - access time - 135 ns
  • Easy interface to all microprocessors, or operates "stand alone"
  • Differential analog voltage inputs
  • Logic inputs and outputs meet both MOS and TTL voltage level specifications
  • Works with 2.5V (LM336) voltage reference
  • On-chip clock generator
  • 0V to 5V analog input voltage range with single 5V supply
  • No zero adjust required
  • 0.3× standard width 20-pin DIP package
  • 20-pin molded chip carrier or small outline package
  • Operates ratio metrically or with 5 VDC, 2.5 VDC, or analog span adjusted voltage reference

Temperature Sensor (LM-35)
Lets study the working of sensor relying on microcontroller based system. For our sensor, we chose LM35. The reason primarily being, that it has a linear voltage / temperature curve. This made temperature measuring using the MICROCONTROLLER easier, as compared to other sensors. Other alternatives can be RTD (resistance temperature detector) or thermistor.

RTDs are used in medium range temperatures, ranging from -200~ to +600 ~ They offer high accuracy, typically :1:0.2~ RTDs can usually be used in most chemical and physical environments, but they are not as robust as the thermocouples. The operation of RTDs requires external power. RTD’s are fairly linear, but not enough as LM35.

Thermistors are used in low to medium temperature applications, ranging from
-50~ to +200~ They are not as robust as the thermocouples or the RTDs and they can not easily be used in chemical environments. Thermistors are low cost and their accuracy is around +0.2~.Thermistors are non-linear.Semiconductor sensors such as LM35 are used in low temperature applications, ranging from -40~ to about +125~ Their thermal coupling with the environment is not very good and the accuracy is around +I~ Semiconductors are low cost. They are extremely linear.So the suitable choice is LM35.
Description of LM35
The LM35 series are precision integrated-circuit TEMPERATURE SENSORs, whose output voltage is linearly proportional to the Celsius (Centigrade) temperature.
Features area as under :-

  • Calibrated directly in ° Celsius (Centigrade)
  • Linear + 10.0 mV/°C scale factor
  • 0.5°C accuracy guarantee able (at +25°C)
  • Rated for full −55° to +150°C range
  • Suitable for remote applications
  • Low cost due to wafer-level trimming
  • Operates from 4 to 30 volts
  • Less than 60 μA current drain
  • Low self-heating, 0.08°C in still air
  • Nonlinearity only ±1⁄4°C typical
  • Low impedance output, 0.1 W for 1 mA load

Displaying Real-Time Temperature on LCD

For displaying our temperature we used an LCD. The reason for that is that, we wanted to output our data parallel instead of serially. And the LCD that we chose displays the output that is LCD. The LCD that we are using is LCD-016M002B. which is

  • 5 x 8 dots with cursor
  • Built-in controller (KS 0066 or Equivalent)
  • 5V power supply (Also available for + 3V)
  • 1/16 duty cycle
  • B/L to be driven by pin 1, pin 2 or pin 15, pin 16 or A.K (LED)
  • N.V. optional for + 3V power supply

Shematic (Interfacing of 8052 with ADC and LCD)The shematic is shown below. Click on the picture to magnify it. Recommended to open in new tab.

Software theory (Designing and Coding in Assembly)
To accomplish the task we had to cater for a lot of things in our software. Like:

  • Getting data from ADC
  • Preparing the data (temperature) for LCD.
  • displaying data on the LCD
  • taking input from keypad
  • Turning the heater on or off.

Programming ADC 0804 in assembly
First was to acquire data from the sensor. As we had used an ADC to do that the first thing in our program was to write a routine, that enables the ADC to read and write data, and then monitor the INTR pin of the ADC and bring an analog input into the register A. this task had to be accomplished by sending a high to low transition pulse on the WR pin through one of the port pins of the MICROCONTROLLER. This converts the analog input into 8bit digital form. After this is done the INTR pin goes low. Our program keeps monitoring the INTR, and as it goes low, it knows that the data is latched and available on the ADC output pins. Once the conversion in ADC is done, the data is available in the output latch of the ADC. After that the RD signal on the ADC is given a low to high pulse enabling the ADC to output the data. That data is sent to the accumulator from the port where the output from ADC is connected.We are using a timer interrupt in our program, which when generated, takes the value from the ADC and stores it in A, and then displays it.
Preparing data (temperature) for LCD
The data from ADC had to be send to the LCD as temperature. But the problem was that the LCD shows Binary Coded Decimals BCD numbers and the ADC gives a hex (binary) output. So what we did was that we converted the hex output to BCD. For that we divided the hex by 10D once or twice (for numbers >100). This made the hex to break into two or three (for numbers >100) portions, and these portions are situated in three different registers. Now these portions are accessible to the LCD, to display as a collective number.

For eg: if the temperature is 52, the ADC outputs 34H, we divide it by 10D, we get 5 in accumulator and 2 in B. these numbers are available for the LCD. First 5 in A is sent, and then 2 in B is sent to A, to send it to the LCD. Ergo, displaying a 52 on the screen.
Displaying data on the LCD
LCD contains two registers, data and command. Data register is used to send any type of data to the LCD. And command register is used to send addresses that initialize the LCD.

Enabling the two lines of your lcd, by sending 38H to the command register. Then after a delay we send 0EH to the command register, to display the data and cursor. After that we used 01H to clear the LCD, and then we move the address 80H to start writing the data, at that location.

The table shows all the codes that correspond to the commands that we use to work on the LCD. These commands are sent to the lcd through our program along with the data, making our data appear o the screen.
Setting the temperature using push buttons
We have used two push buttons in our project that set the temperature of the sensor, one of them increases the temperature and one of them decrease it. These push buttons are checked continuously and as one of them is pressed, the MICROCONTROLLER, increase the maximum value and displays it on the screen.
Turning the heater on or off
The threshold value set by the keypad is saved in a register. Each value entered from the ADC is then compared with this threshold value. Then using the CJNE instruction, the CY flag bit is checked, so if the threshold is greater then the input from ADC, pin at which the heater is connected is set, hence turning the heater on. If the threshold is less, the heater is turned off, by sending a 0 at that pin.

Program flow chart along with source code and hex file can be found at http://homeofgadgets.blogspot.com/2010/02/c-and-assembly-code-for-8051-based.html

Result and conclusions

After setting up the system, we realized that as the temperature of the environment is changed, the numbers on the LCD (i.e our temperature) change accordingly.
We have successfully implemented a digital thermometer, but it also changes the temperature around it by turning on or turning off the heater by comparing it with the value entered by the keypad.. Hence we can say that we have successfully implemented a heating system that regulates and maintains the temperature around it.

Suggestion for future expansions

The system we have made is based on a very small scale. There are a lot of changes that can be added to it, to make a better and a versatile temperature regulating system.

  • Addition of a cooling system, with the heater to decrease temperature, if required.
  • Serially interfacing with the computer screen and keyboard.
  • Increasing the temperature range.
  • Using sensors like RTD, thermistor, thermocouple.
  • Making it adaptable to harsher environments.

For more details Click here

Posted by Muhammad Ahmed on 09:34. Filed under , , . You can follow any responses to this entry through the RSS 2.0. Feel free to leave a response


Recently Commented

Recently Added