Smart Garden

Hi there!

I've been trying to build a DIY Smart garden using the Ardunio Uno. I've completely new at Arduino so I basically have a very limited idea at how things work. Anyway, I'm trying to build a system that uses a moisture sensor to detect if there's a lack of water, resulting in a solenoid valve to open releasing water into the garden. I tried using these tutorials:

Which resulted in me having this code after I smashed them both up together:

int sensor_pin = A0;
int solenoidPin = 4;
int output_value ;
void setup()
{
output_value= analogRead(sensor_pin);
output_value = map(output_value,550,0,0,100);
Serial.print("Mositure : ");
Serial.print(output_value);
Serial.println("%");
delay(1000);
digitalWrite(solenoidPin, HIGH); //Switch Solenoid ON
delay(10000); //Wait 10 Second
digitalWrite(solenoidPin, LOW); //Switch Solenoid OFF
delay(1000); //Wait 1 Second
}
void loop()

(Apologises to those that can see how badly I built this)
As you can see, it does not work so I came here asking to see if anyone would be able to help me fix the issues and hopefully get it to work.

Thank you in advanced
Erik

Please modify your post above and put code tags around your code, as described in the forum guide in the sticky post, which you should read fully before your next post. Also some part of the code you posted is missing.

the sticky post at the top of every forum is HOW TO USE THIS FORUM
and #7 talks about how to post code.

since void setup ()
only runs once, it might be better to do it like this

int sensor_pin = A0;
int solenoidPin = 4;
int output_value ;
void setup()
 {
}
void loop()
output_value= analogRead(sensor_pin);
output_value = map(output_value,550,0,0,100);
Serial.print("Mositure : ");
Serial.print(output_value);
Serial.println("%");
delay(1000);
  digitalWrite(solenoidPin, HIGH);    //Switch Solenoid ON
  delay(10000);                      //Wait 10 Second
  digitalWrite(solenoidPin, LOW);     //Switch Solenoid OFF
  delay(1000);                      //Wait 1 Second
}

alas, you are missing a few housekeeping bits.
open one of the examples of serial and see how to put the bits into setup()

I wont spoil daves excellent post by telling you what to put in your setup (but dont forget to configure your pins);

however apart from that your program does not provide any interaction between the moisture measurement and the solenoid operation.

The program needs to be in the loop() to run continuously; as is it will just thrash the solenoid.

As a simple start point you could use an if()
eg

if(outputValue<20){  //if its too dry
digitalWrite(solenoidPin, HIGH);    //Switch Solenoid ON
  delay(10000);                      //Wait 10 Second
  digitalWrite(solenoidPin, LOW);     //Switch Solenoid OFF
  delay(1000);                      //Wait 1 Second
}

Have a look at blink without delay to see a better way to do this.

as johnerrington noted, my post lacks all the stuff put into setup.

best thing we can offer is to open the examples in the IDE and work through them.

they are pretty quick to work through and if you learn by doing, they are fun to use because you get to see the blinking lights.

as a general note about microcontrollers. if you can light an LED on a pin, you can (with some minor additional bits) control most simple things that go off and on. solenoids, relays, etc.

also, once you set up the soil sensor to work, have it post once every 5 minutes or so to the serial monitor and then after letting it run for a day, copy the data and put into a spreadsheet to see how it looks.

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom.. :slight_smile: