You Are Here: Home » AVR ATmega Projects » Intelligent temperature monitoring and control system using AVR microcontroller

Intelligent temperature monitoring and control system using AVR microcontroller

Controlling temperature has been a prime objective in various applications including refrigerators, air conditioners, air coolers, heaters, industrial temperature conditioning and so on. Temperature controllers vary in their complexities and algorithms. Some of these use simple control techniques like simple on-off control while others use complex Proportional Integral Derivative (PID) or fuzzy logic algorithms. In this project I’m going to discuss about a simple control algorithm and utilize it intelligently unlike analogue controllers. Here are the features of our controller:

  1. Audio-visual setup for setting temperature limits.
  2. Fault detection and evasive action.
  3. Temperature monitoring and display.
  4. Audio-visual warning.
  5. System status.
  6. Settable time frame.
  7. Data retention with internal EEPROM memory.
 ATMega32 TempController

For this design I used an ATMega32L AVR microcontroller with an internal clock frequency of 8MHz, a 4×20 LCD for presenting data visually, a 4-button input interface, a tiny piezo sounder for audible indications and some LEDs for showing faults and simulating real-life devices like heater and coolers. I used MikroC for AVR compiler from Mikroelektronika to develop the firmware for this controller.


The hardware consists of a four-button interface, four LEDs, a piezo tweeter or sounder, a 4×20 LCD, a LM35 temperature sensor, an AVR ATMega32L microcontroller and some other passive parts. Two LEDs connected to PORTD0 and PORTD1 pins simulate on and off operation of relay switches that are actually present in actual applications to control a heater and an air conditioner. The hardware is powered by a 5V source preferably with a 5V regulator like 7805. If relays are used then a 12/24V source will also be needed to power the relays. The AVR micro’s AVREF and AVCC pins should be both connected to the 5V source. The distance between the LM35 sensor and the AVRs ADC pin must not be greater than 10-12cm for proper temperature reading. Though I did this project in a prototyping board made with a strip board, a PCB version is more preferred. Two additional LEDs connected to PD2 and PD3 indicates the failure or malfunctioning status of the air conditioner and the heater.

Microcontroller Ckt11


The entire firmware relies on logical decisions at every step. I wrote the code in a way that the complete code is divided into understandable small functional blocks or functions. Each of these functions is doing specific tasks.

Starting from the top of the code, I declared some definitions of port pins, LCD pins and EEPROM locations. Next I declared global variables and function prototypes.

I’m now going to explain the tasks each functions do. The first function that’s called in the main() function is the setup_mcu() function. It configures the I/O ports for general tasks, LCD and audio output pin. It also sets flags “c” and “h” zero. These flags are set whenever the system faces an alarm. “h” means heater fault flag and “c” means cooler fault flag.  Next to thesetup_mcu() function is the scan_keys() function which simple reads the buttons and a generate specific tone for the key pressed and return a specific value for that particular key. Thus key press, key debouncing delays and tone generation accompanied with key press is made universal throughout the entire code. The  adc_avg() function takes 64 samples of channel 0 of the AVR’s built-in ADC and makes the average of these samples to reduce noise and ensure accuracy. This function returns an unsigned long value since 10-bit ADC resolution is used. Following the adc_avg() function is the temperature display function temp_display(). All it does is simply show the current value of the temperature on the LCD display. The settings()function is the most important part of the program. When entered this function has two menus. The first one according to the program is the reset fault service request and the second allows the user to setup the high and low temperature values along with the number of passes that will be allowed for the temperature to reach the nominal value. Whenever these values are exceeded an alarm goes high and a particular temperature control device (heater or cooler) is set. Thus setting the right values ensure proper system operation and avoid false alarms. Theinc_dec function is used for the menu operations whenever when we need to change a value. It is called to setup temperature values and pass values. The display_common function is used for common display purposes as needed in the inc_dec function. Next the compare_temp() routine compares temperature and shows a message in the LCD if the temperature is within limit or beyond limit. Another important part of the program is the function called controller_state. It is here the controller sets on or off the temperature control devices and also generates alarm in the event of any error. Associated with this routine is the check_fault routine when the conditions for fault are checked. The read_memory routine reads the stored data for temperature limits and others in the AVR internal EEPROM. Finally the last three functions of the code are fault_messages() which shows the fault type, light the specific LED the specific fault and generate a warning tone for all faults; settings_demanded() calls for settings menu andall_tasks() is the collection of all the tasks done in the main function.

For more Detail: Intelligent temperature monitoring and control system using AVR microcontroller

Leave a Comment

You must be logged in to post a comment.

Read previous post:
Scala Showcases New QuickStart Service with HP SignagePlayers at Digital Signage Expo 2011

Exton, PA (PRWEB) February 10, 2011 Scala, the world's leading software provider for end-to-end digital signage solutions, will showcase its...

Scroll to top