I'm following this tutorial to build my watering system.
I believe i've got all the essential parts :
Bigger version of image can be found here..
(i'll draw up a diagram if needed)
If the build is ok what I would like help on is the code.
/*
Automatic watering system
created 26 OCT. 2013
by Elecrow(www.elecrow.com)
*/
#include <Servo.h>
Servo horizontalServo; // create servo object to control a servo
Servo verticalServo;
//Define the moisture sensor pins
const int analogInPin0 = A0; //
const int analogInPin1 = A1;
const int analogInPin2 = A2;
//the value readed from each moisture sensor
int moistureValue0 = 0;
int moistureValue1 = 0;
int moistureValue2 = 0;
//the sum of the 30 times sampling
long int moistureSum0 = 0; //we need to sampling the moisture 30 times and get its average value, this variable is used to store the sum of the 30 times sampled value
long int moistureSum1 = 0;
long int moistureSum2 = 0;
//Define the water pump contorl 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()
{
delay(500);
pinMode(pumpAnodePin, OUTPUT);
pinMode(pumpCathodePin, OUTPUT);
}
void loop()
{
delay(1000);
moistureSampling();
if(moistureValue0 < triggerValue0)
{
proWatering(servoPosition0, wateringTime0);
return;
}
if(moistureValue1 < triggerValue1)
{
proWatering(servoPosition1, wateringTime1);
return;
}
if(moistureValue2 < triggerValue2)
{
wateringTime2);
return;
}
}
void moistureSampling()// read the value of the soil moisture
{
for(int i = 0; i < 30; i++)//samping 30 time within 3 seconds
{
moistureSum0 = moistureSum0 + analogRead(analogInPin0);
moistureSum1 = moistureSum1 + analogRead(analogInPin1);
moistureSum2 = moistureSum2 + analogRead(analogInPin2);
delay(100);
}
moistureValue0 = moistureSum0 / 30;//get the average value
moistureValue1 = moistureSum1 / 30;
moistureValue2 = moistureSum2 / 30;
// print the results to the serial monitor:
Serial.print("Moisture0 = " );
Serial.print(moistureValue0);
Serial.print("\t Moisture1 = ");
Serial.print(moistureValue1);
Serial.print("\t Moisture2 = ");
Serial.println(moistureValue2);
Serial.println();
moistureSum0 = 0;//reset the variable
moistureSum1 = 0;
moistureSum2 = 0;
delay(4000); //delay 4 seconds
}
void proWatering(int servoPosition, int wateringTime) //sweep watering
{
horizontalServo.write(servoPosition - 10); // setting the servo to the position of the flower
delay(500); //waiting the servo go to right position
digitalWrite(pumpAnodePin, HIGH); //the pump start working
digitalWrite(pumpCathodePin, LOW);
for(int pos1 = 15; pos1 < 33; pos1 +=6)//
{
verticalServo.write(pos1);
for(pos = servoPosition - 10; pos <= servoPosition + 10; pos += 1) // goes from 0 degrees to 180 degrees //25,160
{ // in steps of 1 degree
horizontalServo.write(pos); // tell servo to go to position in variable 'pos'
delay(wateringTime); // waits for the servo to reach the position
}
/*(void basicWatering(int servoPosition, int wateringTime) //watering in one point
{
Serial.println(servoPosition);
horizontalServo.write(servoPosition);
delay(800);
digitalWrite(pumpAnodePin, HIGH);
delay(wateringTime);
digitalWrite(pumpAnodePin, LOW);
delay(500);
initPosition();
}*/
That's the automatic watering.
This is the moisture sensor code.
/*
This program is used to sampling the soil moisture,
to get the different values of the different moisture
created 26 OCT. 2013
by Elecrow(www.elecrow.com)
This example code is in the public domain.
*/
//Define the moisture sensor pins
const int analogInPin0 = A0; //
const int analogInPin1 = A1;
const int analogInPin2 = A2;
//the value readed from each moisture sensor
int moistureValue0 = 0; //the variable to store the moisture of the sensor1
int moistureValue1 = 0; //the variable to store the moisture of the sensor1
int moistureValue2 = 0; //the variable to store the moisture of the sensor1
//the sum of the 30 times sampling
long int moistureSum0 = 0; //we need to sampling the moisture 30 times and get its average value
long int moistureSum1 = 0;
long int moistureSum2 = 0;
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}
void loop() {
// read the analog in value:
for(int i = 0; i < 30; i++)//samping 30 time within 3 seconds
{
moistureSum0 = moistureSum0 + analogRead(analogInPin0);
moistureSum1 = moistureSum1 + analogRead(analogInPin1);
moistureSum2 = moistureSum2 + analogRead(analogInPin2);
delay(100);
}
moistureValue0 = moistureSum0 / 30;//get the average value
moistureValue1 = moistureSum1 / 30;
moistureValue2 = moistureSum2 / 30;
// print the results to the serial monitor:
Serial.print("Moisture0 = " );
Serial.print(moistureValue0);
Serial.print("\t Moisture1 = ");
Serial.print(moistureValue1);
Serial.print("\t Moisture2 = ");
Serial.println(moistureValue2);
Serial.println();
moistureSum0 = 0;//reset the variable
moistureSum1 = 0;
moistureSum2 = 0;
delay(4000); //delay 4 seconds
}
I've only got one sensor so I will have to remove moistureSum 1 & 2 won't i?
I've tried to change what I think I understand however it's proving difficult.
This is not enough information. We are not going to run through your code line by line (at least I'm not) unless I know what I am looking for. Just stating you need help tells us nothing. You need to ask a question or tell us what isn't working.
First thing to do would be to get it to compile - the watering code is missing some closing braces at the end, but even with those added, there are a bunch of undeclared items e.g. triggervalue0. It looks as though you've deleted a bunch of necessary items from the code in the instructable.
I can't get it to compile because as my avatar states I'm a newb.
So in conclusion i would like some help on writing code which doesn't include the servo section.
Any help on this would be appreciated
First things first. Edit your code and completely remove any code you are not using and save it somewhere on your computer in a notepad file. Then REPOST your code USING THE "#" CODE TAGS tool button so we don't have to look at code that is not relevant.
Next, if you are a Noob as you stated, you need research whatever it is you want to do by googling "arduino [subject]".
We're not going to write your code for you so if tell us what you need help with specifically we can point you in the right direction.
I can't get it to compile because as my avatar states I'm a newb.
So in conclusion i would like some help on writing code which doesn't include the servo section.
Any help on this would be appreciated
First things first. Edit your code and completely remove any code you are not using and save it somewhere on your computer in a notepad file. Then REPOST your code USING THE "#" CODE TAGS tool button so we don't have to look at code that is not relevant.
Next, if you are a Noob as you stated, you need research whatever it is you want to do by googling "arduino [subject]".
We're not going to write your code for you so if tell us what you need help with specifically we can point you in the right direction.
/*
Automatic watering system
created 26 OCT. 2013
by Elecrow(www.elecrow.com)
*/
#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 the moisture sensor pins
const int analogInPin0 = A0; //
//the value readed from each moisture sensor
int moistureValue0 = 0;
//the sum of the 30 times sampling
long int moistureSum0 = 0; //we need to sampling the moisture 30 times and get its average value, this variable is used to store the sum of the 30 times sampled value
//Define the water pump contorl 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
{
delay(1000);
moistureSampling();
if(moistureValue0 < triggerValue0)
}
void moistureSampling()// read the value of the soil moisture
{
for(int i = 0; i < 30; i++)//samping 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);
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);
for(int pos1 = 15; pos1 < 33; pos1 +=6)//
{
}
This is the moisture monitoring code. I believe I have removed everything to do with other sensors and servo.
/*
This program is used to sampling the soil moisture,
to get the different values of the different moisture
created 26 OCT. 2013
by Elecrow(www.elecrow.com)
This example code is in the public domain.
*/
//Define the moisture sensor pins
const int analogInPin0 = A0; //
//the value readed from each moisture sensor
int moistureValue0 = 0; //the variable to store the moisture of the sensor1
//the sum of the 30 times sampling
long int moistureSum0 = 0; //we need to sampling the moisture 30 times and get its average value
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}
void loop() {
// read the analog in value:
for(int i = 0; i < 30; i++)//samping 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
}
I believe I have removed all the code that I don't need. Code that mentioned the servo especially. I'm now left with that. and i have included it in the "#".
I'd google what I was looking for in the code, if I knew what i was looking for.
The specifics I need help with are coding it so that the watering system works without the servo.
Ok, I don't know what you're talking about . Without going through all your code can you just state exactly what your want ?
"Help with my code so the watering system works etc.. " is too vague.
When I asked you to state the problem, I meant specifically.
I don't like writing code without the hardware breakdown so list all the hardware you want to control and what devices you are using to control it. ("There are 2 pumps , driven by MOSFETS (or relays) etc etc. )
Include the sensors. (everything interfaced to the uC)
A schematic would be even better (hand drawn and photographed with a cell phone) but that's probably asking a bit much. Let's see if we can just do this without it. If it turns out we need it later then we can deal with it then.
raschemmel:
Ok, I don't know what you're talking about . Without going through all your code can you just state exactly what your want ?
"Help with my code so the watering system works etc.. " is too vague.
When I asked you to state the problem, I meant specifically.
I don't like writing code without the hardware breakdown so list all the hardware you want to control and what devices you are using to control it. ("There are 2 pumps , driven by MOSFETS (or relays) etc etc. )
A schematic would be even better (hand drawn and photographed with a cell phone) but that's probably asking a bit much. Let's see if we can just do this without it. If it turns out we need it later then we can deal with it then.
I basically want the code to make my sensors check the moisture level in my plant, then if there is no moisture it would then proceed to water the plant.
The problem is that I'm not confident with code and need guidance on coding.
SITREP:HARDWARE SITREP= Mil-speak for SITUATION REPORT)
What have you tested and how ? ( I can't seem to find any statements in your post indicating you have done the following)
Hint: (Correct answer) What I want you to tell me is that you did preliminary testing on all your hardware.
1-Moisture sensor-You took it outside , stuck it in the ground and read the analog voltage with your arduino running off a battery plugged into the ext. dc jack. and the readings were such & such for these conditions etc.(various amounts of moisture)
2. Motor driven pumps: you ran basic motor tests on them and are able to turn them on & off and control the speed
MOTOR DRIVER: I can't see the labels for the input pins. I need to know what they are labeled (DIR?/ENABLE ?)
3. Sensor shield : ? What is this for ?
NOTE- If you have not done the above please state that so we can proceed with address that. (walk you through it)
raschemmel: SITREP:HARDWARE SITREP= Mil-speak for SITUATION REPORT)
What have you tested and how ? ( I can't seem to find any statements in your post indicating you have done the following)
Hint: (Correct answer) What I want you to tell me is that you did preliminary testing on all your hardware.
1-Moisture sensor-You took it outside , stuck it in the ground and read the analog voltage with your arduino running off a battery plugged into the ext. dc jack. and the readings were such & such for these conditions etc.(various amounts of moisture)
2. Motor driven pumps: you ran basic motor tests on them and are able to turn them on & off and control the speed
MOTOR DRIVER: I can't see the labels for the input pins. I need to know what they are labeled (DIR?/ENABLE ?)
3. Sensor shield : ? What is this for ?
NOTE- If you have not done the above please state that so we can proceed with address that. (walk you through it)
Thanks for the reply.
Unfortunately i've done none of the above. I would need help carrying these tasks out.
Forgot to mention, also need SITREP info on your power source(s) , if any:
Power source for Arduino
power source for motor driver (must be separate power source)
What kind of power source do you plan to use for motor driver ?
a.-Walwart (would need to be within the allowable voltage specified for your pumps)
b- battery /single (same criteria)
c.- battery pack holder consisting of plastic holder that allows you to clip in batteries and change them when necessary)
d- DC variable power supply rated for voltage & current range of pump motors
Schematics:
You will need to document your wiring by drawing a schematic with pen & paper and taking a photo of it with a cell phone.
If you know how to use Fritzing or would like to learn, here is the website link:
Testing
All sub-system testing is preceded by a wiring checkout PRIOR to applying power. Please do not power up anything other than
your arduino until you have passed the wiring checkout phase which consists of you posting the schematic and a photo of your wiring taken directly ABOVE the circuit , showing all connections to power and arduino.
raschemmel:
Forgot to mention, also need SITREP info on your power source(s) , if any:
Power source for Arduino
power source for motor driver (must be separate power source)
What kind of power source do you plan to use for motor driver ?
a.-Walwart (would need to be within the allowable voltage specified for your pumps)
b- battery /single (same criteria)
c.- battery pack holder consisting of plastic holder that allows you to clip in batteries and change them when necessary)
d- DC variable power supply rated for voltage & current range of pump motors
Schematics:
You will need to document your wiring by drawing a schematic with pen & paper and taking a photo of it with a cell phone.
If you know how to use Fritzing or would like to learn, here is the website link: http://fritzing.org/home/
Testing
All sub-system testing is preceded by a wiring checkout PRIOR to applying power. Please do not power up anything other than
your arduino until you have passed the wiring checkout phase which consists of you posting the schematic and a photo of your wiring taken directly ABOVE the circuit , showing all connections to power and arduino.
I will be doing 'D' using a DC variable power supply.
I have the exact same motor driver(the standalone one) That;s the one I will be using. I can't find it on frizzing though to make a diagram.
I have drawn up schematics to the best of my ability.
Your schematic shows arduino d6 & d7 connected to IN3 & IN4.
Your photo shows the a sensor shield connected . I don't see any processor chips on that sensor shield so it must be controlled by the arduino. Why is the motor driver connected to the sensor shield ?
You said you haven't actually done any testing yet so how did you come up with this wiring ?
Why are you not using analog pins on the arduino for the PWM Enable signals for the motor ? (only one , right?)
What kind of signal is that sensor shield providing to the motor driver ?
Where did you come up with that wiring ?
raschemmel:
Your schematic shows arduino d6 & d7 connected to IN3 & IN4.
Your photo shows the a sensor shield connected . I don't see any processor chips on that sensor shield so it must be controlled by the arduino. Why is the motor driver connected to the sensor shield ?
You said you haven't actually done any testing yet so how did you come up with this wiring ?
Why are you not using analog pins on the arduino for the PWM Enable signals for the motor ? (only one , right?)
What kind of signal is that sensor shield providing to the motor driver ?
Where did you come up with that wiring ?
The motor driver is connected to the sensor shield because of the way it is on the tutorial, however from looking around i think it's possible to do this without the sensor shield and just a arduino uno.
I don't understand the kind of signal that the sensor shield is providing the motor driver, i think the sensor shield is providing the information on the moisture levels in the plant?
I am using analogue pins(they go into the soil right?) it' just that I couldn't fit them in the picture.
The wiring was from the tutorial shown on instructables.
I still need to know the labels on the motor driver. I can't read them in the photo. How many input pins and what are they labeled ? (NOT including power)
raschemmel:
I still need to know the labels on the motor driver. I can't read them in the photo. How many input pins and what are they labeled ? (NOT including power)