Sharif University of Technology Microprocessor Arduino UNO Project Monitoring Temperature using LM35 and Arduino UNO Authors: Sadegh Saberian 92106226 Armin Vakil 92110419 Ainaz Hajimoradlou 92106142 Supervisor: Dr. Mehdi Modarressi Sara Mahdizade 92106261 July 11, 2016
1 Abstract In order to monitor temperature, we need three components: a temperature sensor, a microcontroller board and an interface for interactive communication. The temperature sensor will provide us with an analog voltage signal, which contains the temperature data. But this signal needs to be converted to a digital value, so that it can be understood by the board and microprocessor. Thus there should be an analog to digital conversion. Afterward the digital signal can be used to determine the temperature and be shown and monitored on the interface. Figure 1: circuit This procedure can be divided in three parts: circuit building, programming the board, programming the interactive graphical user interface (GUI). We will explore each part extensively. 1
2 Circuit Building We can connect the board, LCD and the temperature sensor using the design below. Here we have used LM35 sensor for measuring the temperature. This sensor is calibrated directly in Celsius, has linear +10.0 mv scale factor. This sensor is rated for full C 55 to +150 C range. In this design the output signal of LM35 is connected to pin A0 of Arduino for analog to digital conversion. The board is also connected to a LCD, which is used for showing the time and temperature. The LCD s data pins are connected to D4-D7 of the board. Figure 2: circuit 2
There is a small modification in the implemented circuit than this design which is lack of potentiometer. As we know, the third pin of LCD is for adjusting the contrast. Here, by using the potentiometer, we can adjust the contrast. However we have provided two ways for setting the LCD contrast without using potentiometer. Constant Contrast In this way we have supplied the VO pin with constant approximately 1V, which is obtained using resistor chain. The main drawback of this scheme is that the LCD contrast is no longer adjustable. The resistor chain can be seen in the picture below. Figure 3: circuit Arduino PWM Pulse Width Modulation, or PWM, is a technique for getting analog results with digital means. Digital control is used to create a square wave, a signal switched between on and off. This on-off pattern can simulate voltages in between full on (5 Volts) and off (0 Volts) by changing the portion of the time the signal spends on versus the time that the signal spends off. The duration of on time is called the pulse width. To get varying analog values, we change, or modulate, that pulse width. If we repeat this on-off pattern fast enough, then we will almost get the desired voltage. 3
Figure 4: PWM Using this PWM technique we can make the LCD contrast adjustable. We set digital pin 9 on board to be OUTPUT and then set the desired voltage, which represent the contrast, to that pin. But this voltage is carried in high frequencies, which can be seen in the LCD s pixels blinking. In order to solve this problem, we can use a Low Pass Filter (LPF) to eliminate the unwanted frequencies. We build this filter using capacitors and resistors. We have used R = 470 Ω and C = 30 µf. Thus the cutoff frequency will be: f C = 1 2πRC 11.29Hz Figure 5: LCD Contrast Now we send the PWM-generated signal to this LPF, and connect the output to the VO of LCD. Now there will be no pixel blinking problem and user can now simply selects the desired contrast from GUI. 4
Figure 6: LCD Contrast Below is a picture of the built circuit. Figure 7: circuit 5
3 Programming the Board We have to convert the sensor analog signal using the ADC module of Arduino. We also have to set up the LCD and serial communication. We have to provide a reference voltage for ADC module in order to work. We can use 5 V or 1.1 V, both provided by Arduino. We use 1.1 V, as it has higher resolution. We also know that the ADC module on Arduino is a 10-bit converter. Thus the ADC output(n) and temperature can be related together with what follows: temperature C = N 1024 1.1V 1000mV 1 V 1 C 10 mv = N 10 1.0742 We read the analog signal from A0, and the digital value for it(reading) is then used to calculating the temperature. N 9.31 Figure 8: ADC and Signal conditioning Afterward the temperature is converted to the user-desired unit, and will be shown on both LCD and PC GUI. The time, in seconds, is also shown on LCD. Arduino sends the calculated temperature (in C) to the serial communication with PC GUI. Arduino also listens the serial port in order to get the unit and brightness adjustments from GUI. Whenever user changes the temperature unit in GUI, Arduino gets two bytes on serial. One U which indicates that the temperature unit must change, and the other byte indicates what unit has been selected( R, K, C, F ). Afterward the temperature shown on LCD will change into selected unit, and the unit symbol on LCD would also be updated. When user changes the LCD contrast on GUI, it sends two bytes to Arduino. First one is B indicating that LCD contrast needs to change, the next byte indicates that which level was selected by user( H, L, M ). Then the value of PWM duty cycle is determined and set, using analogwrite() function, due to the selected level. Figure 9: LCD Constrast selection 6
4 Programming the GUI We need a graphical user interface (GUI), so that user can easily interact with the system. In order to implement such GUI, we have used Python. The designed GUI can be seen below. Figure 10: GUI As we can see, the are radio buttons for selecting temperature unit. There is also radio buttons for selecting the LCD contrast. The user can adjust them by just click on the desired unit or contrast level. User can set the sensor check time, which determines the amount of time between two temperature updates. The measured temperature and time are shown on GUI. There is also a plot of temperature versus time, which is updated every time the new measured temperature is ready. The update ratio for this plot is related to the sensor check time. The value of check time is the amount of time between two plot updates. 7