Projects‎ > ‎µC Projects‎ > ‎

On/Off Controller - Interfacing Touch LCD LC7981 with ATMega


Fig: Overview

An on-off controller is the simplest form of a temperature control device. The output from the device is either on or off, with no middle state.

An on-off controller will switch the output only when the temperature crosses the set-point. For heating control, the output is on when the temperature is below the set-point, and off above set-point. 

Since the temperature crosses the set-point to change the output state, the process temperature will be cycling continually, going from below set-point to above, and back below. In cases where this cycling occurs rapidly an on-off differential, or “hysteresis,” is added to the controller operations. This differential requires that the temperature exceed set-point by a certain amount before the output will turn off or on again. On-off differential prevents the output from “chattering” or making fast, continual switches if the cycling above and below the set-point occurs very rapidly.

On-off control is usually used where a precise control is not necessary, in systems which cannot handle having the energy turned on and off frequently, where the mass of the system is so great that temperatures change extremely slowly, or for a temperature alarm. 


Program requirements:

- Program an on/off controller with your AVR Evaboard
- On the start of the program let the user enter the on/off values and the time of checking using the serial port or an external connected keypad
- The on/off values must be entered in degrees Celsius (0 = 0V-99 = 5V) and the time of checking in ms(1-1000)
- Make it possible to correct typing mistakes
- Display the on/off state and the recent measured value on your LCD display
- Use the 10-bit AD result to calculate with, do not cut it to an 8-bit value
- Use inline documentation and the good style programming rules
- Do not use float/double or other fractured number variables


- Connect an 1st order RC network of your choice to your controller output pin and check, if your controller is working
- Draw/record a diagram with a program of your choice for a measurement where your system temperature goes up and is cycling between on and off state, then is disturbed and after this goes back to the normal cycling states


- Make a small users manual for using your on/off controller
- Document your basic program operation by using one or more Nassi - Shneiderman or flow chart diagram(s)
- Document also, what ports/pins you are using in your program
- Include your measurements, the diagram and the used RC network description. Explain the parts of the measured diagram
- Include the source code in your documentation in a readable monospace font

Principle of this on/off controller

5V are connected to the capacitor (on status).
This capacitor loads up until it reached the maximum value, which you can decide (for example 4V).
If the capacitor reached this value, the 5V will turn off (0V = off status).
The capacitor will discharge until it reached the minimum value, which you can also decide (for example 2V).

User Manual


If you start the program, the start screen is shown. It looks like in the picture below. To touch on the display you need a pointed object (for example a pencil). 

To go on you must click anywhere on the screen. After you did this a menu will turn up, where you can choose the way you want to type in your values for the on/off values and the time of checking. 

You can decide between two variations. You can type in the values via a “Num Pad Input Mode” or via a “Slider Input Mode”.

“Slider Input Mode”.

Min/Max value: 0-99°C in steps of 2°C
Refresh Time: 0-50ms in steps of 1ms
“Num Pad Input Mode”

Min/Max value: 0-99°C in steps of 1°C
Refresh Time: 0-1000ms in steps of 1ms
If you decide to type in the values via the “Num Pad Input Mode” the numeric keypad arise. There you can type in step by step your values for the minimum and maximum temperature and the checking time. If you click on “Ok” the transmission begins. If you click on the arrow you can correct your previous entry. An error comes up if the minimum temperature is higher than the maximum value or if the checking time is higher than 50ms. 

Use the “Ok” button to go on to the next value to enter or the “<-“button to return to the previous value. Mistyping can be corrected. If all digits are field, the cursor returns to the first position to reenter the value.

If you decide to use the “Slider Input Mode” you can also choose the values for the on/off state and the checking time. You must slide over the LCD-display to change these values. The values are shown above the timber. If you click on “Ok” the transmission begins.

After your settings the transmission starts. If the controller heats up a flame is shown on the display. It means that the capacitor loads up (actual temperature is increasing) until it reached your maximum voltage (maximal temperature).

If the controller cools down a snowflake is shown on the display. It means that the capacitor discharge (actual temperature is decreasing) until it reached your minimum voltage (minimal temperature). 

Picture Converter

To draw a picture on the screen or to customize the cover screen you can use our Picture to Pixel converter tool.

First you need a picture with maximum size of 160x80 pixels and of the picture file format bmp. The pixels, which should be drawn on the screen, have to be colored black.
Start the program and open the picture with the “Open” button.

Choose a function name (c naming rules) and an offset/variable name (c naming rules) for the picture position on the screen.

You can use the variable as defines (for example #define pos_x 13) or as parameters to call the function.

Click on “Generate” to create your function. You can copy the code into your main.c or use the “Save” button to save the function into an individual c file and call it from your main.c. 

Simulation & Measurements

R-C Network 1st Order

R1 = 10000?
C1 = 1000µF
S1 Reset button for rapid discharge of C1
Measurement point A for µC analog input 
+5V digital output of µC
GND of µC

The R-C network is simulating a thermal system. We can simulate for example room temperature control or a water heater for a bathroom. R1 limits the current which is used to charge C1. The time constant tau represents the time needed to reach 63.2% of the supplied voltage across C1.

The charging and discharging process is observed by a microcontroller (analog measurement of the voltage across C1). If the measured value (actual temperature) is smaller or equal to the minimum voltage level (minimum temperature) the microcontroller supplies the system with 5V and the capacitor starts charging (temperature is increasing). If the measured value (actual temperature) is bigger or equal to the maximal voltage level (maximal temperature) the microcontroller is setting the supply pin to 0V and the capacitor starts discharging (temperature is decreasing).

LABView Measurements

The charging and discharging of C1 was captured with LABView. 

Setup for room temperature control:

R1 = 10000?, C1 = 1000µF
Minimal temperature: 18°C
Maximal temperature: 21°C
Refresh time: ~0ms

Rising time Tr:         3.00s - 1.25s = 1.75s
On time Ton: 5.06s - 4.68s = 0.38s
Off time Toff: 6.50s - 5.06s = 1.44s
Duty Cycle:         g = Ton / Ton + Toff = 0.38s / 0.38s + 1.44s = 0.21 = 21%

Distortion of the system

The same values and system were used to generate with LABView the distortion behavior of the system.

After the system was disturbed, the microcontroller adjusts the system back to the given parameters.

Ports & Pins


Port F (a/d converter, touch control)

Pin 7

Pin 6

Pin 5

Pin 4

Pin 3

Pin 2

Pin 1

Pin 0






A/D (x) +


Output (y)

A/D (y) +

Digital output (x)


(analogue input)


Port C (LCD data bus)

Pin 7

Pin 6

Pin 5

Pin 4

Pin 3

Pin 2

Pin 1

Pin 0










Port A (LCD control bus, touch control)

Pin 7

Pin 6

Pin 5

Pin 4

Pin 3

Pin 2

Pin 1

Pin 0










Port D (system supply)

Pin 7

Pin 6

Pin 5

Pin 4

Pin 3

Pin 2

Pin 1

Pin 0









GND à connected to GND of microcontroller
5V à connected to 5V output of microcontroller

Define Settings 

Show flame and flake for heating/cooling status
        #define FLAME_AND_FLAKE_ON

Show grad sign in front of Celsius
        #define GRAD_ON

Show cover screen

        #define COVER_ON

Show current temperature, refresh automatically

        #define SHOW_AD_VALUE

Live update of the graph

        #define LIVE_DIAGRAM_ON

Customize to Other Microcontroller Boards

Using the define statements on top of the main.c it’s easily possible to customize the used ports to other microcontroller boards using the same chip (like the EVA board).

Change the define statements to your specific controller setup.

Hardware Setup

The display data port is initially set to port C. Change it for example to port B: DDRB, PORTB, PINB.

        // Display Data Port

        #define LCD_DATA_DDR DDRC

        #define LCD_DATA_PORT PORTC

        #define LCD_DATA_PIN PINC

The display control port is initially set to port A. Change it for example to port B: DDRB, PORTB.

        // Display Control Port

        #define LCD_CTRL_DDR DDRA

        #define LCD_CTRL_PORT PORTA

Change the display control pins to your setup.

        // Display Control Pins

        #define LCD_CTRL_RS 7

        #define LCD_CTRL_RW 5

        #define LCD_CTRL_E 6

Change the digital output pin for the touch panel to your setup. For example ‘b’ (lower case letter with ’’)

Change the analogue port to your chosen setup.

        // Touch Control

        #define TOUCH_DIGIT_OUT_PORT 'a'

        #define TOUCH_DIGIT_OUT_PIN 0

        #define TOUCH_ANA_PORT 'f'

The r-c network is supplied with port d, pin 0. Change it to your setup.

        // System Control

        #define SYS_SUPPLY_PORT 'd'

        #define SYS_SUPPLY_PIN 0



The gadget spec URL could not be found


Alexander Wegner,
13 Jan 2012, 07:29