After receiving a command from the microcontroller, the sensor issues an acknowledgement pulse by pulling the DATA line LOW for one clock cycle. This takes place after the falling edge of the 8th clock on the SCK line, and the DATA line is pulled LOW until the end of the 9th clock on the SCK line.
The Status register is an internal 8 bit register that controls some functions of the device, such as selecting the measurement resolution, end of battery detection, and use of the internal heater. In order to write a byte to the Status register, the microcontroller must send the write command (‘00110’), followed by the data byte to be written. Note that the sensor generates acknowledge signals in response to receiving both the command and the data byte. Bit 0 of the Status register controls the resolution, such that when this bit is 1, both the temperature resolution and the relative humidity resolution are 12 bits. When this bit is 0, the temperature resolution is 14 bits and the relative humidity resolution is 12 bits.
The sensor includes an on-chip heating element that can be enabled by setting bit 2 of the Status register. By using the heater, it is possible to increase the sensor temperature by 5 to 10 °C. The heater can be useful for analysing the effects of changing the temperature on humidity. Notice that during temperature measurements, the sensor measures the temperature of the heated sensor element and not the ambient temperature.
The steps for reading the humidity and temperature are summarised below:
The steps for reading the temperature are similar, except that the command ‘00000011’ is sent instead of ‘00000101’
Figure 12.38 shows the timing diagram for reading the relative humidity with 12-bit resolution and ignoring the CRC. In this figure, it is assumed that the sensor has already been reset using the Reset_sequence.
The humidity sensor is non-linear and it is necessary to perform a calculation to obtain the correct reading. The manufacturer's data sheet recommends the following formula for the correction:
(12.7)
where SORH is the value read from the sensor and the coefficients are as given in Table 12.2.
For temperatures significantly different from the 25 °C, the manufacturers recommend another correction to be applied to the relative humidity as
(12.8)
where T is the temperature in °C where the relative humidity reading is taken, and the coefficients are as given in Table 12.3.
SORH | t1 | t2 |
12 bit | 0.01 | 0.00008 |
8 bit | 0.01 | 0.00128 |
The manufacturers recommend that the temperature reading of the SHT11 should be corrected according to the following formula:
(12.9)
where SOT is the value read from the sensor and the coefficients are as given in Table 12.4.
VDD | d1 (°C) | d1 (°F) |
5 | −40.1 | −40.2 |
4 | −39.8 | −39.6 |
3.5 | −39.7 | −39.5 |
3 | −39.6 | −39.3 |
2.5 | −39.4 | −38.9 |
SOT | D2(°C) | D2(°F) |
14 bit | 0.01 | 0.018 |
12 bit | 0.04 | 0.072 |
The block diagram of the project is shown in Figure 12.39. A rectangle will be drawn on the GLCD screen and the temperature and relative humidity will both be displayed, as shown in the figure.
The circuit diagram of the project is as shown in Figure 12.40. The SHT11 sensor is connected to PORT C of a PIC18F45K22 type microcontroller. The DATA pin is connected to RC4 and the SCK pin is connected to RC3. The DATA pin is pulled up using a 10 KB resistor, as recommended by the manufacturers. Also, a 100 nF decoupling capacitor is connected between the VDD pin and the ground.
The project was tested using a plug-in SHT11 module (manufactured by mikroElektronika) together with the EasyPIC 7 development board, where the module was connected to the PORT C I/O plug located at the edge of the EasyPIC 7 development board (see Figure 12.41).
The PDL of this project is given in Figure 12.42.
The program listing of the project is shown in Figure 12.43. At the beginning of the program, the connections between the GLCD and the microcontroller are defined. Then, the connections between the SHT11 sensor and the microcontroller are defined. The temperature and relative humidity correction coefficients are then given as floating point numbers.
The main program then configures PORT B, PORT C and PORT D as digital outputs, initialises the GLCD, and clears the display. The GLCD font is set to large. The SHT11 datasheet recommends that no commands should be sent to the device for the first 20 ms after power is applied to the device. This delay is implemented by function SHT11_StartupDelay. The program then enters an endless loop formed with a for statement. Inside this loop, the temperature is measured and corrected by calling function Measure with argument 3, and stored in floating point variable Ttrue. Then, the relative humidity is read, corrected and stored in floating point variable RHtrue. The measured values are converted into strings by using built-in function FloatToStr. Finally, the degree symbol and letter ‘C’ are appended to the temperature reading. Similarly, symbol ‘%’ is appended to the relative humidity reading before it is displayed.
Function Measure is the most complicated function in the program. This function implements the measurement steps described earlier in the project. Argument command specifies the type of measurement required: 3 for temperature measurement and 5 for relative humidity measurement. After calling to functions Reset_Sequence and Transmission_Start_Sequence, the address and command is sent to the SHT11 device. Bits of mode (3 or 5) are sent out through the MSB after shifting the data to the left in a loop. The program then waits until the conversion is ready, which is indicated by the DATA line going LOW. Once the data is ready, a loop is formed to read the two bytes from the sensor. At the end of the 8th clock pulse, an ACK signal is sent to the sensor. In the last part of this function, depending upon the type of conversion required, either the temperature or the relative humidity readings are corrected and returned to the calling program.
The program repeats after a delay of 5 seconds.
Figure 12.44 shows a typical display.
18.191.240.222