- Intelligent IoT Projects in 7 Days
- Agus Kurniawan
- 328字
- 2021-07-02 18:25:51
Soil moisture sensor
One of the parameters of gardening is soil moisture. We should measure soil moisture to ensure our plant grows well. There are many options when it comes to soil moisture sensors. You can use the SparkFun Soil Moisture Sensor, for example. You can find this module at https://www.sparkfun.com/products/13322 .
You can see the SparkFun Soil Moisture Sensor in the following image:

You can use other soil moisture sensors from cheap manufacturers in China. You can order them from Alibaba or Aliexpress.
To read soil moisture values, we can use analog I/O. To use analog I/O, you should be familiar with the following Sketch APIs:
- analogRead() is for reading analog data from an analog pin on Arduino
- analogWrite() is for writing analog data to an analog pin on Arduino
For demonstration, we'll connect an Arduino board to the SparkFun Soil Moisture sensor. The following is the wiring used:
- VCC is connected to 5V on the Arduino
- GND is connected to GND on the Arduino
- SIG is connected to A0 on the Arduino
A complete wiring can be seen in the following figure:

Now you can open the Arduino software. If you haven't installed it yet, you can download and install the tool from https://www.arduino.cc. Once done, you can write a Sketch program. Create this script:
void setup() {
Serial.begin(9600);
}
void loop() {
int val;
val = analogRead(A0);
Serial.print("Soil moisture: ");
Serial.print(val);
delay(3000);
}
The program starts by initializing a Serial object with a baud rate of 9600. In a looping program, we read soil moisture levels using the analogRead() method. Then the measurement is printed to the serial port.
Save this Sketch file and upload the program to the Arduino board. To see the output data, you can use the serial monitor in the Arduino software. You can find it by going to Tools | Serial Monitor. You should see a soil moisture reading in the Serial Monitor tool.
- Learning Microsoft Windows Server 2012 Dynamic Access Control
- Docker技術入門與實戰(第3版)
- Power Up Your PowToon Studio Project
- 精通搜索分析
- Android Application Development Cookbook(Second Edition)
- Python編程:從入門到實踐
- RISC-V體系結構編程與實踐(第2版)
- C# 8.0核心技術指南(原書第8版)
- PHP從入門到精通(第4版)(軟件開發視頻大講堂)
- Python圖形化編程(微課版)
- 響應式架構:消息模式Actor實現與Scala、Akka應用集成
- 零基礎學Kotlin之Android項目開發實戰
- Raspberry Pi Robotic Blueprints
- Building Serverless Architectures
- 從0到1:HTML5 Canvas動畫開發