Pages: 1 [2] 3 4 ... 8   Go Down
Author Topic: Potted plant watering system. (Involves water pumps.)  (Read 10345 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26348
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
It complies ok.
I'm guessing it doesn't work though.

Code:
pinMode(sensor[0],INPUT);
All of "sensor" was initialised to zero by the compiler, so "sensor [0]", "sensor [1]" all have the value zero, so you're setting the pinMode of pin zero multiple times.

Code:
#define sensorPins[0] 14
#define sensorPins[1] 15
I've been programming in C a long time, and I've never seen that construct before.

Did you mean
Code:
const byte sensorPins [] = { 14, 15 etc
?

Code:
int solenoid[5];
Code:
    pinMode(solenoid[5],OUTPUT);
You don't have a "solenoid[5]" to set the pinMode of.
« Last Edit: July 17, 2012, 06:00:04 am by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

UK
Offline Offline
Faraday Member
**
Karma: 99
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Just to throw a spanner in the works (no, not Graham Taylor), how about some kind of feedback from the soil?

You can detect how wet the soil is to know if it's been raining or not, and even if the plants need watering - no need for "timing" then, you can make it intelligent.

There's 2 normal ways of detecting soil moisture content:

1. Resistance.

This involves passing a current through the soil and measuring the voltage drop - essentially using the soil as one half of a potential divider.  It is incredibly simple to do, but you will end up corroding your electrodes in no time.

2. Capacitance.

This is the better way of doing it.  Two probes in the ground, both insulated, and close together.  As the soil moisture content changes, so does the capacitance between the two electrodes.  This is a much harder way of sensing the moisture content as you have to detect the capacitance not the resistance, but the electrodes can last for many many years (decades, millennia) longer as they aren't in direct contact with the soil.
Logged

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

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

What kind of pump, solenoids and valves are you gonna use? I have made something similar to water my tomato plants. It's really simple; a 10 l bucket of water, a cheap aquarium pump from Sparkfun, and a Uno set up to start the pump for about one second each 4 hours. I'm running a silicon hose from the pump to the potted plants at the moment. I've cut a hole halfway on the hose where it passes plant no 1, then the end of the hose goes to the second plant. If I had some valves I could get better control of the amount of water for each plant
Logged

Oz
Offline Offline
God Member
*****
Karma: 5
Posts: 748
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Morning folks.

It is 07:13 here.   Day kind of just starting.

AWOL:
Yes, I am probably not making sense.  However as I have said I know jack about this type of code.  I look at what is and try to work out what does what and make it do what I want.

Your question/suggestion for what I want is probably true, but I have NO knowledge of the structure and vocabulary.

I shall have to research that "command" and see if that is what I want to do.

Yes, I probably don't have all the assignments worked out.  The code was constructed "on the fly" and I kind of just "cut/paste" the lines a few times and made the numbers sequencial.



Majenko:
The sensors.
I haven't got that far yet.  I have defined their inputs and done an "example" idea of how their values change indicating the different "staes".  Either with or without water detected.

As to moisure content, etc.  Well the idea is that the sensors will simply detect the water levevl in the saucer that the pot is sitting.  Nothing too elaborate.

I resolved that moisture would/may not be good because if I am watering the pots and the water isn't detected soon enough they will "over fill".  Although I have timeout  values I am opting for a simple level detection.


It was mentioned about  corrosion on the "sensors".  So someone suggested I use gavanised nails.  They won't rust.

Ferryp:
Again:  The types of solenoids/valves are still future work.  I am working on the program for now.
Though probably something like what you are suggesting with a cheap pump.

The only difference is that the size and ammount of water each plant/pot needs is too different to use
ONE hose with holes.   Thus the solenoids.

As this is only my firt full sketch I am not wanting to get too far ahead of myself by looking at the hardware
until I get the software working.
« Last Edit: July 17, 2012, 04:50:08 pm by lost_and_confused » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26348
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, some vocab.

Code:
#define sensorPins[0] 14
(this is a macro definition)
Here, I assume you're trying to tell your sketch that there's an array called "sensorPins", and element zero has the value 14.
At some point, I assume, you're going to set the pinMode of pin 14 to be INPUT.
So, I search your sketch (as you could have done) for the string "sensorPins", but apart from the five other similar macro definitions, there are no occurrences of the string "sensorPins", so you never use it anywhere.

Instead, you confuse the pin a sensor is attached to with the value you're eventually going to read from that sensor.
Code:
//  Sensor array
int sensor[6];
and
Code:
   pinMode(sensor[0],INPUT);
    pinMode(sensor[1],INPUT);
    pinMode(sensor[2],INPUT); // etc
But you haven't given the elements of the array "sensor" any values, so, because "sensor" has global scope, the compiler has kindly assigned the value zero to all of its elements. So, you're setting the pinMode of pin zero to be INPUT six times.

Similar, but subtly more dangerous situation with the solenoids, you have macros for the pins but never use them.
However:
Code:
int solenoid[5];
Code:
  pinMode(solenoid[1],OUTPUT);
    pinMode(solenoid[2],OUTPUT);
    pinMode(solenoid[3],OUTPUT);
    pinMode(solenoid[4],OUTPUT);
    pinMode(solenoid[5],OUTPUT);
The array "solenoid" has five elements with subscripts 0, 1, 2, 3 and 4, and again the compiler has helpfully set all the elements that it knows about to zero.
But then, you invent a sixth element (no doubt starring Bruce Willis), retrieve it value (do you know what it is? I don't), and set the corresponding pin's mode to be an OUTPUT.

Code:
sol_run_time[1] = 20;
    sol_run_time[2] = 20;
    sol_run_time[3] = 20;
    sol_run_time[4] = 20;
    sol_run_time[5] = 20;
Ditto.

Quote
//#define setRTC
#ifdef setRTC
Don't even think about removing the // comment marks off that macro definition.

Code:
int i = x;
    int reading;
    int TTG;
    int time_up;
    TTG = sol_run_time[i];
    time_up = timer(TTG);
is bad for the eyes.
Code:
int i = x;
    int TTG = sol_run_time[i];
    int time_up = timer(TTG);
is shorter and easier on the eyes.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Oz
Offline Offline
God Member
*****
Karma: 5
Posts: 748
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

AWOL,

Thanks very much for the effort of the reply.

My learning curve:
(kind of, and worded around this sketch)

I want inputs and outputs.  Originally I called them input_1, input_2, input_3 and so on.   And output_0, output_1, output_2 and so on.

To save the the repetitive nature of typing near exact lines I did a loop around it.
So from other things I have seen, I made them look like:
input_[0], input_[1], and so on.

But it didn't work and I was pointed in the direction of the example sketch on how to do arrays.

I mis-understood what was initially explained/read and changed it to:
input[0], input[1] and so on.  No   _

But what I missed was the 'Pin' included in the definition.

So I changed it to things like:
inputPin[0], inputPin[1], etc.

That then worked better but I still don't understand what is "really happening".

Again:  I am only doing this to save a lot of typing and being able to use an index (in this case the ubiquitous letter i) between routines so the next function can get the required values easily.


So now I shall try to work through what you mentioned:

#define sensorPins[0] 14
#define sensorPins[1] 15

That is where I want to tell the system I want these pins (the last number) to be inputs called sensorPins0, sensorPins1, sesnsorPins2, etc.
Ok, some parts of that may be deleted/negated on compilation.

With the status quo, in the setup() I had:
   pinMode(sensor[0],INPUT);

and it was mentioned that this won't work.
Granted I don't know what I am doing.   But don't you just love my enthusiasum - how ever you spell it?

So....  (digging myself further towards stupidity) I try "completing" the name so it matches the name declared in the GLOBAL part and have this:

    pinMode(sensorPins[0],INPUT);
    pinMode(sensorPins[1],INPUT);

Obviously that doesn't work - well hindsight for me - but I am not see what is going on.

In the big picture I hope you can see what I am TRYING to do, but am obviously failing at getting done.

I guess it wouldn't kill me to do the whole thing the long way and get it working initially then try to optimise it down to something like this structure style.

const byte sensorPins [] = { 14, 15 etc

Is probably what I am wanting to do, but I don't know what it means.

Yes:  My problem.  I need to do more leg work and maybe read.  I shall.  But again I shall mention I don't know the entire vocabulary and so don't know for what commands to search to achieve my desired result.


So indulge me about how what I shall call "Arrays" work.
Which I am guessing are things like:
int My_variable[10]
means there are 10 "My_variable" variables. 
My_variable1, My_variable2, My_variable3, My_variable4, and so on.

This way it would save me manually making them all, and being able to index them with something like:
i = 3
xx = My_variable

would make xx equal to what is My_variable3

Ok, I may have the syntax slightly wrong in that it is:
My_variable[3].

I don't know.

I'd better stop now because I think I have dug myself in deep enough for now.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26348
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
#define sensorPins[0] 14
No.
As I said, I'm not even sure what that will do.

Use
Code:
const byte sensorPins [6] = {14, 15, .. etc};
instead.

This defines an array of bytes (8 bit unsigned ) of constants, and assigns the value 14 to index zero, 15 to index one and so on.
If the list on the right (the "{14, 15 }" bit) does not contain as many entries as specified on the left hand side of the assignment (the "[6]" bit), then the array is padded to the end with zeroes.
The indices of this array run from zero to five inclusive.
« Last Edit: July 18, 2012, 03:29:13 am by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Oz
Offline Offline
God Member
*****
Karma: 5
Posts: 748
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

(I'm going to have to dig up my other Arduino and my prototype board and build this so I can see what is going on.)

Thanks though.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26348
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
int sensor_delay(int x)
It looks to me like this function doesn't return anything, so it would be better described as
Code:
void sensor_delay(int x)
(it would also be better if you thought of a better name than "x")

It is also confusing me why you're assigning the value of "x" to the variable "i", instead of simply using "x" throughout this function.
« Last Edit: July 18, 2012, 03:39:04 am by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Oz
Offline Offline
God Member
*****
Karma: 5
Posts: 748
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well,

sensor_delay(i)

The "index" i is sent to the function.

From that, the "run time" is derived.
(    TTG = sol_run_time;  )

While the value of time_up > 0 it loops.

Then it calls the "timer" routine with TTG.

"Timer" gets the TTG value and counts down that many minutes.
The remaining value is returned and if not zero, it aborts the loop.

I just noticed that I goofed in line 197 in that it should be time_up and not TTG.

In that loop, it looks at the sensor input for that pot and checks it hasn't become active/exceeded/what ever the defined value for THAT pot - for now it is all just set to a nominal value.


Am I making sense?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26348
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Well,

sensor_delay(i)

The "index" i is sent to the function.

...where you call it "x", then assign it to another variable called "i".
There is no reason for this, you'd cause less confusion calling the formal parameter "i", or leave it as "X" and use "x" instead of assigning it to "i".
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Oz
Offline Offline
God Member
*****
Karma: 5
Posts: 748
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I call it x then rename it i only because

solenoid() has a loop with "i" in it.

It goes from 1 to 5 - the number of pots.
In each cycle the loop calls "sensor_delay" with "i".

As this is a new function, I understand that you call it with the value you need:

        sensor_delay(i);


Then in sensor_delay
int sensor_delay(int x)

Which tells this function to expect a variable (int x), and in this function I need to use "i" and so must assign it to the local name "x" (I don't have much of an imagination for transitory variables)
So I have to define it in "sensor_delay" as so:
    int i = x;

Originally I would have made it two lines, but I have since learned the trick of combining the two into one.


Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26348
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
in this function I need to use "i"
No, you don't.
An array index can be any integer datatype and name.
Since the formal parameter is called "x", you'd be better off using "x" throughout your function, instead of assigning the value of "x" to another variable called "i".
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Oz
Offline Offline
God Member
*****
Karma: 5
Posts: 748
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, bad choice of words.

All/most of the examples I have seen have used i to do something like that.

So the "habit" is formed.

I can change it to something else, but again:  this is a transitory variable so I didn't' put much stock in the importance of the name.

Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26348
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
this is a transitory variable so I didn't' put much stock in the importance of the name.
You may not now, but what about in six weeks time when you come back to make changes?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Pages: 1 [2] 3 4 ... 8   Go Up
Jump to: