How would I read the current from a moisture sensor connected to a analog pin in arduino?

I tried normally reading the input on the analog pin using analogRead but the value isn't consistent even when the sensor is soaked with water.

I found from the internet that I must convert it to voltage first using Ohm's Law. So if I want to convert it, do I need a resistor that would give 5 V as output?

How would I go about that since the output range from the sensor is 20mA to 30mA?

int MoistureAnalogInput = A0;

void setup() 
{
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() 
{
  // put your main code here, to run repeatedly:
  float MoistureAnalogRead = analogRead(MoistureAnalogInput);
  Serial.print(MoistureAnalogRead);
  Serial.print("\n");
  delay(2000);
}

Hi, @gohanhango

Can you please post a link to specs/data of the sensor?

Thanks.. Tom.. :grinning: :+1: :coffee: :australia:

hello @TomGeorge, here are the specs the seller sent me.

I moved your topic to an appropriate forum category @gohanhango.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

Hi,
Please post images directly into the post.

The current is the consumption of the sensor.
You use the AO output into the Arduino analog input measuring voltage.
What model Arduino are you using?

Can you please post a link to where you purchased it?
Can you please post a picture of it?

Thanks.. Tom.. :grinning: :+1: :coffee: :australia:

What´s the name of the sensor?

My bad about the image. I thought I can't post image directly. About the voltage and current, I'm not sure if it outputs voltage. I asked the seller and they said it outputs the current.

There is the link of the sensor.

I'm using arduino uno.

And here is a picture of the sensor.

Sorry, I don't think they gave the exact detail about it. It's only named soil moisture sensor even when I look at the details of it.

Okay, thank you.

Connect as follows:

+ ---> Arduino 5V

- ---> Arduino GND

AO ---> Arduino A0

That's what I did and printed the output to the serial monitor and proceeded to soak the sensor in water but the values appearing were not consistent.

The readings will fluctuate, that is normal with the cheap soil moisture probes.
You need to take several readings, try 25 then take the average.

okay, thank you. I'll try that.

Let us know your findings

1 Like

I will. Thank you.

As you've now discovered it delivers a voltage. A google search delivers several helpful results. Here's the first YT tutorial I briefly looked at:

https://www.youtube.com/watch?v=7K7ygqA6DC8

Changed the code up a bit. Here are the results first (completely soaked in water):
0.00
1023.00
0.00
1023.00
0.00
1023.00
0.00
925.20
393.00
20.10

Here is the code:

int MoistureAnalogInput = A0;

void setup() 
{
  // put your setup code here, to run once:
  Serial.begin(9600);

}

void loop() 
{
  // put your main code here, to run repeatedly:
  float MoistureAnalogRead = 0;
  for (int i = 0; i < 10; i++)
  {
    MoistureAnalogRead += analogRead(MoistureAnalogInput);
  }
  MoistureAnalogRead /= 10;
  Serial.print(MoistureAnalogRead);
  Serial.print("\n");
  delay(2000);
}

I'm not sure what I'm doing wrong here.

Take 50 readings
Put a delay(1) after you do the analogRead
Put the probe in a glass of water and make sure at least half the probe length is covered with water.
Wait about a minute before taking readings.

If the readings are still going from 0 to 1023, you may have a bad probe or a bad board, or a broken wire, or a bad connection somewhere.

Okay, I'll try that. Thank you.

Haven't tried anything yet but I asked my friend whom I borrowed the arduino from and said that the analogRead for the board is faulty. Will try another board and post and update here. Thank you guys.