Go Down

Topic: Garduino data output problem (Read 5845 times) previous topic - next topic



I'm trying to get the garduino moisture sensor to work, however, I've been running into a few problems.

I'm using a modified code in which temperature and light are omitted.

Code: [Select]
//define analog inputs to which we have connected our sensors
int moistureSensor = 0;

//define digital outputs to which we have connecte our relays (water)
int waterPump = 7;

//define variables to store moisture
int moisture_val;

//setup a variable to store seconds since arduino switched on
float start_time;
float seconds_elapsed;
float seconds_elapsed_total;
float seconds_for_this_cycle;

void setup() {
  //open serial port
  //set the water, light, and temperature pins as outputs that are turned off
  pinMode (waterPump, OUTPUT);
  digitalWrite (waterPump, LOW);

void loop() {
  // read the value from the moisture-sensing probes, print it to screen, and wait a second
  moisture_val = analogRead(moistureSensor);
  Serial.print("moisture sensor reads ");
  Serial.println( moisture_val );

  //turn water on when soil is dry, and delay until soil is wet (line 41)
  if (moisture_val < 850)
    digitalWrite(waterPump, HIGH);

  while (moisture_val < 850)

  digitalWrite(waterPump, LOW);

However, once hooked up, and plugged in, the serial monitor is showing me "moisture sensor reads 1023" repeatedly. This is much too high as, the sensor probes are not even touching.

Does anyone know what the problem could be?

Thanks in advance,


What is your schematic? (How is it hooked up)
Tell us or draw a picture and scan it, or you can do it on the computer.


moisture sensor reads 1023" repeatedly

That's full scale on the ADC, look suspicously like the sensor is not working or hooked up wrong.

Can you measure the voltage with it wet and dry?

Rob Gray aka the GRAYnomad www.robgray.com


[See above] This commonly happens if you forget a voltage divider. How are you setting up the sensor?


Jan 29, 2011, 06:52 am Last Edit: Jan 29, 2011, 06:54 am by futonsnstuff Reason: 1
I appreciate the responses =)

My sensor is hooked up pretty much exactly like this diagram here. I have reverified the connections, and they seem solid.

I am using a solderless breadboard, and am just sticking the wires inside the holes.

One thing is, that I do not yet have the galvanized nails attached to the wires. I was thinking that I could add them later, and I would get the same results from just touching the bare wires together. Am I mistaken for believing this?

Edit : In addition, I'm not familiar with what a voltage divider is?


Jan 29, 2011, 08:24 am Last Edit: Jan 29, 2011, 08:43 am by Graynomad Reason: 1
When inserted in the ground the two nails have a certain resistance between them (created by the soil). This and the actual resistor you have form a "voltage divider" and you are reading at the point between these two resistors.

The value you read will change if either of the resistors does, therefore as the soil changes it's resistance (wetness) the value you read also changes.

Now if you are just touching the two wires together the value is driven directly to 5v, you no longer have a voltage divider, just a pull down resistor and a wire connected to 5v.

So the ADC will read the max value, ie 1023.

To simulate the soil get another resistor (or better still a pot, that's potentiometer, not a pot of soil) and connect that to 5v where the nails should be. If using a pot turning the knob should give you different readings.


Rob Gray aka the GRAYnomad www.robgray.com


What value resistor are you using? I imagine that soil would have a very high resistance, so a 10k resistor might not give you the accuracy or range you want.


Jan 29, 2011, 04:56 pm Last Edit: Jan 29, 2011, 04:59 pm by futonsnstuff Reason: 1
I am using a 10k resistor, as you said. This was the value I was told to use in the instructions.

So currently, what is my best plan of action in order to get this to work? I will try replacing the nails with a separate resistor.


If you have a multimeter, find the resistance of the two  probes while they are in the soil. Tell us that number.


Okay, I have found the problem I was having. It turns out the wires I was using were faulty.

Now, I am getting correct readings from my probes, but there is another small hitch.

Once the serial monitor gives me one reading, it stops. It shows no additional readings.

How would I need to modify the code so it consistently takes readings every few seconds?


IDK. Show us the code.

A helpful hint:
Unless it is a REALLY basic question, always show us your schematic and code. Then we can help.


Thanks a ton, I was able to modify the code myself to show correct readings.

I appreciate all the help =)

Go Up