Page 222 - ARM Based Microcontroller Projects Using MBED
P. 222

208                          8. INTERMEDIATE LEVEL PROJECTS

                 development board. A relay is connected to GPIO pin PC_0 through a bipolar transistor
                 switch. The heater is connected to one of the relay contacts and to the power supply as shown
                 in the figure.

                 8.23.5 The PDL

                   Fig. 8.74 shows the program PDL.

                 8.23.6 Program Listing

                   Fig. 8.75 shows the program listing (program: ONOFF). At the beginning of the program, a
                 heading is displayed and the desired set-point temperature is read from the keyboard and
                 stored in a floating point variable called SetPoint. The remainder of the program runs in an
                 endless loop. Inside this loop, the ambient temperature is measured and compared with the
                 set point. The relay is turned ON or OFF depending on whether the set point is below or above
                 the measured value, respectively. Both the desired set point and the measured temperatures are
                 displayed on the screen at line 7, column 0. The above process is repeated every second.
                   Fig. 8.76 shows a typical run of the program.


                 8.23.7 Suggestions for Additional Work
                   Modify the program in Fig. 8.75 to save the measured temperature values in an array. Then,
                 draw a graph (e.g., using Excel) to show the variation of the measured temperature with time.

                       BEGIN
                              Configure relay as output
                              Display heading
                              Read the desired Set-Point temperature
                              DO FOREVER
                                      Read the sensor voltage
                                      Convert to Degrees centigrade
                                      IF measured temperature < Set-Point THEN
                                             Turn ON relay
                                             Display message that the relay is ON
                                      ELSE IF measured temperature > Set-Point THEN
                                             Turn OFF relay
                                             Display message that the relay is OFF
                                      ENDIF
                                      Wait 1 second
                              ENDDO
                       END

                 FIG. 8.74  Program PDL.
   217   218   219   220   221   222   223   224   225   226   227