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); 
}
Output

Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad