Arduino UNO R4 Cảm Biến Nhiệt Độ LM35

Hướng dẫn này sẽ chỉ bạn cách sử dụng Arduino Uno R4 với cảm biến nhiệt độ LM35. Cụ thể, chúng ta sẽ học:

Arduino UNO R4 lm35 cảm biến nhiệt độ

Linh Kiện Cần Thiết

1×Arduino UNO R4 WiFi hoặc Arduino UNO R4 Minima
1×(Tùy chọn) DIYables STEM V4 IoT, tương thích với Arduino Uno R4 WiFi
1×Arduino UNO R4 Minima (Thay thế)
1×Cáp USB Type-C
1×Cảm Biến Nhiệt Độ LM35
1×breadboard
1×Dây Jumper
1×(Khuyến nghị) Screw Terminal Block Shield for Arduino UNO R4
1×(Khuyến nghị) Breadboard Shield for Arduino UNO R4
1×(Khuyến nghị) Enclosure for Arduino UNO R4
1×(Khuyến nghị) Power Splitter for Arduino UNO R4
1×(Khuyến nghị) Prototyping Base Plate & Breadboard Kit for Arduino UNO

Or you can buy the following kits:

1×DIYables STEM V4 IoT Starter Kit (Arduino included)
1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)

Về Cảm Biến Nhiệt Độ LM35

Sơ Đồ Chân

Cảm biến nhiệt độ LM35 có ba chân.

  • Chân GND: kết nối với GND (0V)
  • Chân VCC: kết nối với VCC (5V)
  • Chân OUT: đây là chân tín hiệu. Nó xuất ra điện áp tương ứng với nhiệt độ. Kết nối chân này với một chân analog trên Arduino UNO R4.
lm35 cảm biến nhiệt độ sơ đồ chân

Nguyên Lý Hoạt Động

LM35 cung cấp một điện áp tăng theo nhiệt độ. Mỗi độ C làm cho đầu ra tăng lên 10 millivolt (mV). Để tìm nhiệt độ, chia điện áp cho 10.

Sơ Đồ Đấu Nối

Arduino UNO R4 lm35 cảm biến nhiệt độ sơ đồ đấu dây

This image is created using Fritzing. Click to enlarge image

Cách Lập Trình Cho Cảm Biến Nhiệt Độ LM35

  • Sử dụng hàm analogRead() để lấy giá trị ADC từ cảm biến nhiệt độ.
int adcVal = analogRead(PIN_LM35);
  • Chuyển đổi giá trị ADC thành điện áp được đo bằng millivolt.
float milliVolt = adcVal * (ADC_VREF_mV / ADC_RESOLUTION);
  • Chuyển đổi điện áp thành nhiệt độ Celsius.
float tempC = milliVolt / 10;
  • Chuyển đổi Celsius sang Fahrenheit nếu cần.
float tempF = tempC * 9 / 5 + 32;

Code Arduino UNO R4

/* * Mã Arduino UNO R4 này được phát triển bởi newbiely.vn * Mã Arduino UNO R4 này được cung cấp để sử dụng công khai, không có ràng buộc. * Để xem hướng dẫn chi tiết và sơ đồ kết nối, vui lòng truy cập: * https://newbiely.vn/tutorials/arduino-uno-r4/arduino-uno-r4-lm35-temperature-sensor */ #define ADC_VREF_mV 5000.0 // in millivolt #define ADC_RESOLUTION 1024.0 #define PIN_LM35 A0 void setup() { Serial.begin(9600); } void loop() { // get the ADC value from the temperature sensor int adcVal = analogRead(PIN_LM35); // convert the ADC value to voltage in millivolt float milliVolt = adcVal * (ADC_VREF_mV / ADC_RESOLUTION); // convert the voltage to the temperature in Celsius float tempC = milliVolt / 10; // convert the Celsius to Fahrenheit float tempF = tempC * 9 / 5 + 32; // print the temperature in the Serial Monitor: Serial.print("Temperature: "); Serial.print(tempC); // print the temperature in Celsius Serial.print("°C"); Serial.print(" = "); // separator between Celsius and Fahrenheit Serial.print(tempF); // print the temperature in Fahrenheit Serial.println("°F"); delay(1000); }

Các Bước Thực Hiện

Thực hiện theo các hướng dẫn sau từng bước:

  • Nếu đây là lần đầu tiên bạn sử dụng Arduino Uno R4 WiFi/Minima, hãy tham khảo hướng dẫn về Arduino UNO R4 - Cài Đặt Phần Mềm.
  • Kết nối Arduino Uno R4 với cảm biến LM35 theo sơ đồ được cung cấp.
  • Kết nối bo mạch Arduino Uno R4 với máy tính của bạn bằng cáp USB.
  • Khởi chạy Arduino IDE trên máy tính của bạn.
  • Chọn bo mạch Arduino Uno R4 phù hợp (ví dụ: Arduino Uno R4 WiFi) và cổng COM.
  • Sao chép code ở trên và mở nó trong Arduino IDE.
  • Nhấp vào nút Upload trong Arduino IDE để chuyển code lên Arduino UNO R4.
  • Cầm cảm biến trong tay của bạn.
  • Kiểm tra kết quả trên Serial Monitor.
COM6
Send
Temperature: 26.31°C = 79.36°F Temperature: 26.44°C = 79.59°F Temperature: 26.50°C = 79.70°F Temperature: 26.56°C = 79.81°F Temperature: 27.06°C = 80.71°F Temperature: 27.75°C = 81.95°F Temperature: 28.37°C = 83.07°F Temperature: 29.00°C = 84.20°F Temperature: 29.56°C = 85.21°F Temperature: 30.00°C = 86.00°F Temperature: 30.31°C = 86.56°F Temperature: 30.62°C = 87.12°F Temperature: 30.87°C = 87.57°F
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

Video Tutorial

Việc sản xuất video tốn rất nhiều thời gian. Nếu video hướng dẫn hữu ích cho việc học của bạn, hãy đăng ký kênh YouTube để ủng hộ. Nếu nhu cầu đủ cao, chúng tôi sẽ cố gắng làm thêm nhiều video.

Tài Liệu Tham Khảo Hàm

Bình Luận