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

Latest Current Affairs 2026 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Python Programming Tutorials 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 Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz