Programming Examples

Arduino program to interface soil moisture sensor


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).
Solution

void setup()
{
  pinMode(A0, OUTPUT);
  pinMode(A1, INPUT);
  Serial.begin(9600);
}

void loop()
{
  int moisture = 0;
  moisture = analogRead(A1);
  Serial.println(moisture); 
  delay(100); 
}
▶ RUN

Output/ Explanation:

Latest Current Affairs 2026 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad