Hello,
I am trying to create a modified version of this project.
The modification being I dont need a servo to move/aim the nozzle output and I only have one sensor / one plant.
https://dl.dropboxusercontent.com/u/726782/AA%20...%20Projects/Arduino/Plant%20Project/2014-09-07%2015.33.15.jpg
https://dl.dropboxusercontent.com/u/726782/AA%20...%20Projects/Arduino/Plant%20Project/2014-09-07%2015.33.59.jpg
So far, I've managed to connect:
1 Arduino Uno
1 Sensor shield
1 Mini water pump
http://www.ebay.co.uk/itm/121425001384?_trksid=p2059210.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT
1 Soil Hygrometer
http://www.ebay.co.uk/itm/350961143799?_trksid=p2059210.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT
1 L298N Dual H Bridge Stepper Motor Driver
http://www.ebay.co.uk/itm/281239216460?_trksid=p2059210.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT
Im pretty sure its wired correctly.
For the soil sensor I connected it up to the Analogue 0 input ... tested this code
// define humidity variable to hold the final value
int humidity = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
// read soil moisture from sensor
int sensorValue = analogRead(A0);
/* constraint function will limit the values we get so we can work better with map
* since I only need values in the bottom limit of 300, will make it the outer limit and 1023 the other limit
*/
sensorValue = constrain (sensorValue, 300,1023);
// print the values returned by the sensor
//Serial.println(sensorValue);
// create a map with the values
// You can think we have the 100% to 300 and 0 % to 1023 wrong, but no !
// 300 - or 100 % - is the target value for moisture value in the soil
// 0% of humidity - or moisture - is when the soil is dry
humidity = map (sensorValue, 300, 1023, 100, 0);
Serial.print (humidity);
Serial.println ("%");
delay(1000); //collecting values between seconds
}
on it to make sure it all works ... and it does, I opened up the serial monitor and it correctly displays the moisture percentage level
Now for the bit I'm struggling with ...
I left the moisture sensor as is, and connected up the motor driver
Driver <--> Sensor Shield
??IN3 <--> D6
??IN4 <--> D7
??+5V <--> VIN
??GND <--> GND
I used the following code
#define triger 250
//Define the parameters of the pump
#define triggerValue0 135 //the trigger value of the moisture, the minimum value is 0, means the moisture is 0, the soil is very dry. the maximum value is 1024.
#define wateringTime0 35 //the time for watering, millisecond. delay 35ms, uses about 70ML water
//Define the moisture sensor pins
const int analogInPin0 = A0; //
//the value read from each moisture sensor
int moistureValue0 = 0;
//the sum of the 30 times sampling
long int moistureSum0 = 0; //sampling the moisture 30 times to get its average value, this variable is used to store the sum of the 30 times sampled value
//Define the water pump control pins
const int pumpAnodePin = 6; //pin 6 connect to the anode of the pump
const int pumpCathodePin = 7; //pin 7 connect to the cathode of the pump
void setup()
{
Serial.begin(9600);
delay(500);
pinMode(pumpAnodePin, OUTPUT);
pinMode(pumpCathodePin, OUTPUT);
}
void loop()
{
int
moistureSampling();
if(moistureValue0 < triggerValue0)
{
proWatering(wateringTime0);
return;
}
}
void moistureSampling()// read the value of the soil moisture
{
for(int i = 0; i < 30; i++)//sampling 30 time within 3 seconds
{
moistureSum0 = moistureSum0 + analogRead(analogInPin0);
delay(100);
}
moistureValue0 = moistureSum0 / 30;//get the average value
// print the results to the serial monitor:
Serial.print("Moisture0 = " );
Serial.print(moistureValue0);
Serial.println();
moistureSum0 = 0;//reset the variable
delay(4000); //delay 4 seconds
}
void proWatering(int wateringTime) //sweep watering
{
digitalWrite(pumpAnodePin, HIGH); //the pump start working
digitalWrite(pumpCathodePin, LOW);
delay(5000);
digitalWrite(pumpAnodePin, LOW);
digitalWrite(pumpCathodePin, LOW);
}
void watering(int wateringTime)
{
delay(1000);
digitalWrite(pumpAnodePin, HIGH);
delay(10000);
digitalWrite(pumpAnodePin, LOW);
delay(3000);
}
When I monitor the serial ... it reads 1024 when there is no moisture, and a lower value when there is ... why is this happening ?