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