Introduction: Soil Moisture Sensor Experiment Based on Arduino

About: I am a electrical student,like DIY and travel and reading.Recently I am interested in arduino proejct

It is a experiment of Soil moisture sensor experiment based on Arduino

Step 1: The Code

There are total four pins Soil

moisture sensor (you can redeem it free from PCBWay) :

VCC pin: power supply positive

GND pin: power negative

A0 pin: Output the analog voltage value of soil moisture sensor, range from 0 to 1023

D0 pin: Output the switch value of soil moisture sensor, 0 and 1,

Use a simple code to test, check the output value of the A0 pin, the program as follows:

const int buttonPin = A0;

int inputValue = 0;

void setup() {

pinMode(buttonPin, INPUT);




void loop() {

inputValue = analogRead(buttonPin);



Step 2: The Experiment

There is a large flowerpot in my home. I

put the soil moisture sensor in the flowerpot to test. The picture of the flowerpot as follows. The soil moisture sensor will insert in different positions during the test.

The output of A0 pin is 1023 when the
soil moisture sensor didn’t insert into flower pot..

When the soil moisture sensor inserted into a certain position of the flower pot, the output value of the A0 pin rapidly drops to a certain stable value. Then pull out the soil moisture sensor, and insert it into other positions of the flower pot. At this time, the A0 pin outputs different analog values depend on the humidity in different positions.