11.7 PROJECT 11.7 – Temperature and Pressure Display

This project is about the design of a microcontroller based device to measure the ambient temperature and the pressure and to display them on a 2 × 16 LCD. The temperature will be displayed on the first row and the pressure on the second row. The display is in floating point format as follows:

img

There are many analogue and digital temperature sensors available. The one used in this project is the LM35DZ integrated circuit analogue temperature sensor. This is a small 3-pin sensor, where one of the pins is connected to +V, the other one to GND, and the third one is the output pin. The output voltage is proportional to temperature and is given by

(11.1) equation

Thus, for example, at 10°C the output voltage is 100 mV, at 25°C the output voltage is 250 mV, and so on.

The ambient pressure sensor used in this project is the MPX4115A. This sensor generates an analogue voltage proportional to the ambient pressure. The device is available either in a 6-pin or an 8-pin package.

The pin configuration of a 6-pin sensor is:

Pin Description
1 Output voltage
2 Ground
3 +5 V supply
4–6 not used

and for an 8-pin sensor:

Pin Description
1 not used
2 +5 V supply
3 Ground
4 Output voltage
5–8 not used

Figure 11.25 shows pictures of this sensor with both types of pin configurations.

Figure 11.25 MPX4115A pressure sensors

img

The output voltage of the sensor is given by

(11.2) equation

or

(11.3) equation

where

kPa = atmospheric pressure (Kilo Pascals);
V = output voltage of the sensor (V).

The atmospheric pressure measurements are usually shown in millibars. At sea level and at a temperature of 15°C, the atmospheric pressure is 1013.3 millibars. In equation (11.3) the pressure is given in kPa. To convert kPa to millibars, we have to multiply equation (11.3) by 10 to give:

(11.4) equation

or

(11.5) equation

or

(11.6) equation

where the voltage is in millivolts.

Figure 11.26 shows the variation of the output voltage of the MPX4115A sensor as the pressure is varied. Our range of interest lies in the area where the ambient (atmospheric) pressure is between 800 and 1100 millibars.

Figure 11.26 Variation of sensor output voltage with pressure

img

11.7.1 Block Diagram

The block diagram of the project is shown in Figure 11.27. The top row of the LCD shows the temperature and the bottom row the pressure.

Figure 11.27 Block diagram of the project

img

11.7.2 Circuit Diagram

The circuit diagram of the project is shown in Figure 11.28. The LCD is connected to PORT B, as in the earlier projects. The temperature sensor is connected to analogue input RA0 (Channel 0) of the microcontroller. In a similar way, the pressure sensor is connected to the analogue input RA1 (Channel 1) of the microcontroller. Both RA0 and RA1 are configured as analogue input ports. The project is based on a PIC18F45K22 type microcontroller with an 8 MHz crystal clock, although most other PIC microcontrollers supporting at least two A/D converters can also be used.

Figure 11.28 Circuit diagram of the project

img

If you are using the EasyPIC 7 development board, then make sure that jumper J15 is not connected across RA0 or RA1 inputs.Also make sure that the jumpers Read-X and Read-Y of SW3 are in the OFF positions.

11.7.3 Project PDL

The PDL of this project is given in Figure 11.29.

Figure 11.29 PDL of the project

img

11.7.4 Project Program

The program is named LCD7.C and the program listing of the project is shown in Figure 11.30. At the beginning of the project, the connections between the microcontroller and the LCD are defined using sbit statements. PORT A is configured as an analogue port and pins RA0 and RA1 are configured as input pins. Then, PORT B is configured as a digital output port, the LCD is initialised, cleared, and the cursor is turned OFF. The A/D converter module is initialised by calling function ADC_Init. This function sets the A/D converter to default configuration where the clock is derived from the internal RC circuit, and the reference voltage is set to +5 V.

Figure 11.30 Program listing of the project

img

img

The program is executed in an endless loop formed using the for statement. Inside this loop, the output of LM35DZ is read using the A/D converter of the microcontroller. Function ADC_Get_Sample(0) reads the analogue voltage from Channel 0 (i.e. port pin RA0) of the microcontroller. Here, the converted digital data is stored in variable TemperatureData. The A/D converters on PIC18F45K22 microcontroller are 10 bits wide, providing 1024 steps. Thus, for a reference voltage of +5 V, each step corresponds to 4.88 mV, and this is the minimum voltage change that can be detected by our voltmeter. The digital data is then converted into millivolts and divided by 10 to find the temperature in °C. The temperature is stored in variable Temperature as a floating point number.

Then, the pressure is read from Channel 1 (i.e. port pin RA1) and stored in variable PressureData as a digital value. This value is then converted into volts and the pressure is calculated using equation (11.6) and stored in variable Pressure as a floating point number.

In the final part of the program, both the temperature and pressure are converted into strings using the built-in function FloatToStr and the resulting strings are displayed on the top and bottom rows of the LCD. Notice that the temperature reading is displayed as ‘T(C) = nnn.nnnn’, and the pressure reading is displayed as ‘P(mb) = nnn.nnnn’. The program waits for 1 second and the above process is repeated forever.

Figure 11.31 shows a typical display of the temperature and pressure.

Figure 11.31 Typical display of temperature and pressure

img
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.187.15