/*
# Auto waterer
# Editor : Mike
# Date : 1/25.2013
# Version : 1.0
# Connect the sensor analog out to the A0(Analog 0) pin on the Arduino board
# Connect the sensor VCC pin to 5v pin on Arduino the board
# Connect the sensor GND pin to GND pin on the Arduino board.
# the sensor value description
# 0 ~300 dry soil
# 300~700 humid soil
# 700~950 in water
*/
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int moisturesensor = 0; // analog pin used to connect the moisture sensor
int val; // variable to read the value from the analog pin
void setup()
{
Serial.begin(57600);
myservo.attach(1); // attaches the servo on pin 1 to the servo object
pinMode(moisturesensor, INPUT); // Assigns sensor to pin 0
}
void loop()
{
moisturesensor = analogRead(0); // reads the value of the sensor (value between 0 and 950)
}
if (moisturesensor < 300) // if soil is dry
{ // open water
myservo.write(90); // sets the servo position according to the sensor value.
delay(15); // waits for the servo to get there
}
else
{
myservo.write(0); // turns the water off
delay(15); // waits for the servo to get there
}
void loop()
{
moisturesensor = analogRead(0); // reads the value of the sensor (value between 0 and 950)
} <<< what does this do?
This is your entire loop now:
void loop()
{
moisturesensor = analogRead(0); // reads the value of the sensor (value between 0 and 950)
}
The stuff that follows is not part of loop.
You probably want to delete the } and put it at the end of the code.
Is 15mS enough time for the servo to move? Seems pretty quick.