Pages: [1]   Go Down
Author Topic: Garduino data output problem  (Read 2472 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

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:
//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
  Serial.begin(9600);
  //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 );
  delay(1000);

  //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)
  {
    delay(10000);
  }

  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,
Logged

Connecticut
Offline Offline
Edison Member
*
Karma: 16
Posts: 1216
RTFD (Datasheet in our case)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 121
Posts: 8442
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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

Logged

Rob Gray aka the GRAYnomad www.robgray.com

Connecticut
Offline Offline
Edison Member
*
Karma: 16
Posts: 1216
RTFD (Datasheet in our case)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?






« Last Edit: January 29, 2011, 12:54:33 am by futonsnstuff » Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 121
Posts: 8442
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

« Last Edit: January 29, 2011, 02:43:29 am by Graynomad » Logged

Rob Gray aka the GRAYnomad www.robgray.com

Connecticut
Offline Offline
Edison Member
*
Karma: 16
Posts: 1216
RTFD (Datasheet in our case)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: January 29, 2011, 10:59:54 am by futonsnstuff » Logged

Connecticut
Offline Offline
Edison Member
*
Karma: 16
Posts: 1216
RTFD (Datasheet in our case)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Connecticut
Offline Offline
Edison Member
*
Karma: 16
Posts: 1216
RTFD (Datasheet in our case)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

I appreciate all the help =)
Logged

Pages: [1]   Go Up
Jump to: