11.Arduino learning notebook - temperature sensor experiment

 11.Arduino learning notebook - temperature sensor experiment

    Juvtmall ( a company supply PCB PrototypingPCBA service and sell kinds of components, modules and so on) ( Catduino has the same function of Arduino)

Through the last experiment, we learned the use of 1602 LCD. Here we make a simple temperature sensor, through a LM35 temperature sensor to read the room temperature, the temperature displayed on the 1602 LCD screen.

The last time we used the hand-written code to drive the LCD, this time we directly use  LiquidCrystal library to drive, this library file allows arduino control board to control the LCD based on Hitachi HD44780 or be compatible with most of the chip. Working in 4bit or 8bit state.

The picture below shows the location of the LiquidCrystal library file for arduino we use, and the library file only shown here can be called by arduino.



What is a temperature sensor?

Temperature sensor is that: making use of the regular of the material changed by the temperature, is a sensor can convert the temperature to electricity. According to the measurement method can be divided into contact and non-contact. According to the sensor material and component characteristics can be divided into thermal resistance sensor and thermocouple sensor. White iron tip uses the thermocouple sensor, this time uses LM35, a thermal resistance sensor.

LM35 temperature sensor as shown below:


LM35 is very commonly used, it used in the internal compensation mechanism, the output can start from 0 ℃. Package for T0992, working voltage 4-30V. In the above voltage range, the working current of the chip does not exceed 60ua. According to the product manual, it is known that the output voltage of the LM35 sensor is linear with the temperature of Celsius. When output 0℃ displays 0V. Every increase 1 ℃, the output voltage will increase 10 mv.

The following figure shows the experimental hardware connection:





Arduino code
1. #include <LiquidCrystal.h> // use LiquidCrystal library owned by arduino
2. 
3. LiquidCrystal lcd (12, 11, 5, 4, 3, 2); // set the interface
4. 
5. int potPin = 4; / / set the analog port 4 as the LM35 signal input port
6. float temperature = 0; // set the temperature as a floating point variable
7. long val = 0; // set val as a long integer variable
8. 
9. void setup ()
10. {
11.   lcd.begin (16, 2); // initialize the LCD
12. lcd.print ("LM35 Thermometer"); // Make the screen display text LM35 Thermometer
13. delay (1000); // delay 1000ms
14. }
15. 
16. void loop ()
17. {
18. 
19. val = analogRead (potPin); // val variable is the value read from the LM35 signal port
20. temperature = (val * 0.0048828125 * 1000); / / Convert the read val to 10 times of the temperature value
21. lcd.clear (); // clear screen
22. lcd.print ("LM35 Thermometer"); // Make the screen display text LM35 Thermometer
23. lcd.setCursor (0, 1); // set the cursor position as the first position of the second row
24. lcd.print ((long) temperature / 10); // display temperature integer bits
25. lcd.print ("."); // display the decimal point
26. lcd.print ((long) temperature% 10); // shows the first number after the temperature decimal point
27. lcd.print ((char) 223); // display the symbol o
28. lcd.print ("C"); // display the letter C
29. 
30. delay (2000); / / delay 2 seconds, here is the refresh rate.
31. 
32. }



The other blog

评论

此博客中的热门博文

21. Arduino learning notebook-- Experiment of controlling steering engine

20.Arduino learning notebook--Use Arduino Duemilanove to download the bootloader to other chips

19.Arduino learning notebook--Atmega8 makes the minimum arduino system