Temperature sensor with time and date display on graphical LCD using Atmega32

Summary of Temperature sensor with time and date display on graphical LCD using Atmega32


This article details a prototype project using an Atmega32 microcontroller to display temperature, time, and date on a graphical LCD. The system reads data from a DS18B20 sensor via software 1-wire implementation and tracks time using Timer1 interrupts with leap year logic. Features include MIN/MAX temperature logging in EEPROM, UART output, and navigation via a rotary encoder.

Parts used in the Temperature Display Project:

  • GLCD board
  • Atmega32 microcontroller
  • DS18B20 temperature sensor
  • LED
  • Rotary encoder
  • EEPROM

Some time ago I’ve build a prototyping board with graphical LCD. It have served for various small projects and prototypes. Had a spare temperature sensor DS18B20 and decided to put simple temperature display project. GLCD board is equipped with Atmega32 microcontroller running at 16MHz. DS18B20 sensor is connected to port D pin 6.
LED connected to PD3 is used for indicating EEPROM write activity. Device is navigated with rotary encoder. It is connected to MCU as follows (more about interfacing rotary encoder here):
Temperature sensor
As you can see hardware is simple considering that you already have GLCD board. Next step is to decide what functionality is needed. I came up with following:

  • Temperature display with 0.01ºC resolution;
  • Time display in HH:MM:SS format;
  • Date display in YYYY:MO:DD format;
  • Date is calculated with leap year algorithm;
  • Temperature is updated every 5s;
  • Temperature data with date/time is sent to UART terminal;
  • MIN and MAX temperature storage in EEPROM;
  • Menu selectable functions: time/date set, temperature log view, graph plot, reset min max, stats view;
  • LED blinks each time min or max is updated.

Reading DS18B20 sensor

Lets go through all parts of this. First of all temperature reading. As Atmega32 doesn’t have any hardware level 1-wire support everything has to be done in software. Luckily you can find ready libraries for this. As a reference I’ve used code example from here. Library is combination of several smaller that include 1-wire and DS18x20 code developed by Peter Dannegger and CRC code from Colin O’Flynn. All you need to initialize sensor, read its ROM code and then you can access sensor data with function that returns temperature value. Library supports multiple sensors connected to single wire so main code could be simplified since we need to read only one sensor. We are leaving as it is as long as it works. Temperature is stored as three 8-bit values: sign, integral part and decimal part. This way we avoid using floating point numbers that would take significant part of resources.

Time and date calculation

Time and date track is software based. This means that every second, minute, hour, day, month and year has to be calculated withing algorithm. To make one second ticks there is 16-bit timer1 used which generates overflow interrupts. On every interrupt time and date update function is called that increments value by one second as follows:
void TimeDate_Update(void)
{
if (++TD.ss==60)
{
TD.ss=0;
if(++TD.mm==60)
{
TD.mm=0;
if(++TD.hh==24)
{
TD.hh=0;
if(IsLeapYear(TD.year)&&(TD.mo==2))
{
if(++TD.dd>SDays[0])
{
TD.dd=1;
if(++TD.mo>12)
{
TD.mo=1;
TD.year++;
}
}
}
else if(++TD.dd>SDays[TD.mo])
{
TD.dd=1;
if(++TD.mo>12)
{
TD.mo=1;
TD.year++;
}
}
}
}
}
It also takes care of leap year calculation. It means if year is leap then February has 29 days otherwise it has 28. Leap year algorithm is common and can be found on internet:

For more detail: Temperature sensor with time and date display on graphical LCD using Atmega32

Quick Solutions to Questions related to Temperature Display Project:

  • What microcontroller is used in the GLCD board?
    The GLCD board is equipped with an Atmega32 microcontroller running at 16MHz.
  • How is the DS18B20 sensor connected to the microcontroller?
    The DS18B20 sensor is connected to port D pin 6.
  • Does the device support floating point numbers for temperature?
    No, temperature is stored as three 8-bit values to avoid using floating point numbers that would take significant resources.
  • How often is the temperature updated?
    The temperature is updated every 5 seconds.
  • Can the system calculate leap years?
    Yes, the date calculation includes a leap year algorithm to determine if February has 28 or 29 days.
  • What timer is used for generating second ticks?
    A 16-bit timer1 is used which generates overflow interrupts to create one-second ticks.
  • Where are the minimum and maximum temperatures stored?
    MIN and MAX temperature values are stored in EEPROM.
  • How does the LED indicate activity?
    The LED blinks each time the minimum or maximum temperature is updated.

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter
Scroll to Top