Arduino Cảm biến độ ẩm đất và bơm nước

Trong hướng dẫn này, chúng ta sẽ học cách sử dụng Arduino và cảm biến độ ẩm đất cảm ứng để điều khiển bơm.

Phần cứng cần chuẩn bị

1×Arduino Uno R3
1×USB 2.0 cable type A/B (for USB-A PC)
1×USB 2.0 cable type C/B (for USB-C PC)
1×Capacitive Soil Moisture Sensor
1×Relay
1×12V Pump
1×Vinyl Tube
1×12V Power Adapter
1×DC Power Jack
1×dây jumper
1×(Khuyến nghị) Screw Terminal Block Shield for Arduino Uno
1×(Khuyến nghị) Breadboard Shield for Arduino Uno
1×(Khuyến nghị) Enclosure for Arduino Uno
1×(Khuyến nghị) Prototyping Base Plate & Breadboard Kit for Arduino UNO

Or you can buy the following kits:

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

Về cảm biến độ ẩm đất và máy bơm

Nếu bạn chưa biết về máy bơm và cảm biến độ ẩm đất (bố trí chân, cách hoạt động, cách lập trình ...), hãy tìm hiểu về chúng trong các bài hướng dẫn sau:

Cách hoạt động

Arduino định kỳ đọc giá trị từ cảm biến độ ẩm đất cảm ứng điện dung. Dựa trên giá trị độ ẩm đất, nó sẽ thực hiện các hành động sau:

  • Nếu giá trị độ ẩm của đất thấp hơn một ngưỡng, Arduino tự động kích hoạt một rơ-le để bật máy bơm.
  • Ngược lại, Arduino tự động ngắt một rơ-le để tắt máy bơm.

Sơ đồ đấu dây

sơ đồ đấu nối cảm biến độ ẩm đất Arduino và bơm

This image is created using Fritzing. Click to enlarge image

Mã Arduino

/* * Mã Arduino này được phát triển bởi newbiely.vn * Mã Arduino 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/arduino-soil-moisture-sensor-pump */ #define RELAY_PIN 2 // Arduino pin that controls the pump via relay #define MOISTURE_PIN A0 // Arduino pin that connects to AOUT pin of moisture sensor #define THRESHOLD 530 // => CHANGE YOUR THRESHOLD HERE void setup() { Serial.begin(9600); pinMode(RELAY_PIN, OUTPUT); } void loop() { int value = analogRead(MOISTURE_PIN); // read the analog value from sensor if (value > THRESHOLD) { Serial.print("The soil moisture is DRY => activate pump"); digitalWrite(RELAY_PIN, HIGH); } else { Serial.print("The soil moisture is WET => deactivate the pump"); digitalWrite(RELAY_PIN, LOW); } Serial.print(" ("); Serial.print(value); Serial.println(")"); delay(1000); }

Hướng dẫn từng bước

  • Thực hiện hiệu chuẩn để xác định ngưỡng ướt-khô, xem Arduino - Cảm biến độ ẩm đất
  • Cập nhật giá trị đã hiệu chuẩn thành THRESHOLD trong mã
  • Mở Serial Monitor trên Arduino IDE
  • Tải mã lên Arduino
  • Xem kết quả trên Serial Monitor
COM6
Send
The soil moisture is DRY => activate the pump The soil moisture is DRY => activate the pump The soil moisture is DRY => activate the pump The soil moisture is DRY => activate the pump The soil moisture is WET => deactivate the pump The soil moisture is WET => deactivate the pump The soil moisture is WET => deactivate the pump The soil moisture is WET => deactivate the pump
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

Giải thích mã nguồn

Đọc lời giải thích theo từng dòng trong các dòng chú thích của mã nguồn!

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.