soil moisture sensor with 3 pins

Hello,

I got this sensor : moisture sensor
And it has 3 pins: VCC,Sig and GND.

I connected all the pins VCC to 5v, Sig to A0 and the GND to GND.

I have this sketch to check the sensor:

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

void loop() {
  // put your main code here, to run repeatedly:
int soilSensorValue = 0;
int thresholdUp = 400;
int thresholdDown = 250;
  soilSensorValue = analogRead(A0);
  Serial.println(soilSensorValue);
  if(soilSensorValue <= thresholdDown)
    Serial.println("Dry Water it!");
  else if (soilSensorValue >= thresholdUp)
    Serial.println("Wet Leave it!");

    delay(500);
}

And I always get 0… even if I put it in water.

what did I do wrong?
I saw many sensors with 4 pins… but this is the one I have.

Thanks in advance.

Try this code. Use map() function. make variable declarations outside of loop

int soilSensorValue = 0;
int thresholdUp = 400;
int thresholdDown = 250;

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

void loop() {
  // put your main code here, to run repeatedly:
  soilSensorValue = analogRead(A0);
  soilSensorValue = map(soilSensorValue,0,1023,0,500); //map
  Serial.println(soilSensorValue);
  if(soilSensorValue <= thresholdDown)
    Serial.println("Dry Water it!");
  else if (soilSensorValue >= thresholdUp)
    Serial.println("Wet Leave it!");
    delay(500);
}

double check your connections. and baud rate also.

ok that was the wiring.... but now I get random numbers all over the place.... from 1023 to 0... and it looks like it's going up stay at 1023 and then go down to 0 and stay at zero and all over again.... are you aware of this?

Thank you for helping me! :)

After checking only I have posted the code. Mine is working

Read the map() function in arduino site.

map(value, fromLow, fromHigh, toLow, toHigh);

this function only makes your exact adc 10 bit value to what you want from high to low.Means convert the adc 10 bit values from low value and high value, convert this value what you want between this to this.

for example

soilSensorValue = map(soilSensorValue,0,1023,0,500);

soilSensorValue is 10 bit resolution. So you need to convert what size you want.

As you can see 0 is the lowest value and 1023 is highest value in 10 bit adc resolution.

So I am converting the value from 0 to 1023. to 0 to 500.

Which means 0==0 and 1023==500. that is it.

Try your analog pin pull up or pull down. this may help. (I saw your moisture sensor in ebay. there is only transistor. I think it only provide to on and off). Any way try pull up or pull down what you want. Try another pins. A1,A2,etc.

Which board you used ?.

share your circuit.

Ok. Where is the module.? that simple board ?.

That can only to interface between your arduino and sensor.

Here find this I have attached below of that sensor and that module

soil moisture.jpg

Ok I got it to work finally....

I used wires I knew that would work and it work. I already know the map function but wanted to get good results before I used that.

now that I get them I'll use the map function.

Thank you so much for helping me!