Programming Examples
Arduino program to interface soil moisture sensor

Interfacing a soil moisture sensor with an Arduino involves reading the analog values from the sensor and displaying the readings. Here is a simple Arduino program to do that:
Hardware Required:
- Arduino board (e.g., Uno)
- Soil moisture sensor
Connections:
- Connect the VCC pin of the soil moisture sensor to the 5V pin of the Arduino.
- Connect the GND pin of the sensor to the GND pin of the Arduino.
- Connect the analog output pin (usually labeled A0 or AO) of the sensor to an analog input pin on the Arduino (e.g., A0).
Solutionvoid setup()
{
pinMode(A0, OUTPUT);
pinMode(A1, INPUT);
Serial.begin(9600);
}
void loop()
{
int moisture = 0;
moisture = analogRead(A1);
Serial.println(moisture);
delay(100);
}
Output