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

We're not talking about the solenoid pin array.

Look at the first two quoted line in reply #48.

Quote
But when I compile I get this:

V4b:21: error: expected `}' before numeric constant
V4b:21: error: expected ',' or ';' before numeric constant
V4b:21: error: expected declaration before '}' token
21 is the line I posted above.
Posting error messages without the exact code that caused them is pointless.
Please don't do it.
« Last Edit: July 21, 2012, 05:16:03 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: 4
Posts: 708
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry, got distracted with the other post.

Shall look again.

Logged

Oz
Offline Offline
God Member
*****
Karma: 4
Posts: 708
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

AWOL,

with all the reading things have changed.

I am trying and trying to get it working.  It isn't that I am sitting here waiting for help.

So what was is no more - another reason I like to keep old code in the sketch.

Now I have this in the sketch instead of what was there:

Code:
//  This sets up the output pins to drive the solenoids
int solenoid_outputPins[] = {8, 9 10, 11, 12};
int sol_run_time[] = {20, 20, 20, 20, 20};
int level[] = {155, 155, 155, 155, 155};
But it doesn't work.
(See other recent posts here)


Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It's this -
Quote
Arrays are zero indexed
- that you should be concentrating on.

Code:
level[6] = 20;
is referencing the seventh element of the array.
Code:
int level[6];
which only has six elements.
« Last Edit: July 21, 2012, 05:23:21 am by dxw00d » Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
int solenoid_outputPins[] = {8, 9 10, 11, 12};
still has a missing comma.
Logged

Oz
Offline Offline
God Member
*****
Karma: 4
Posts: 708
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks.

Yeah, found the missing coma.

Weird, I was looking for something like that, but (obviously) missed it.

Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Good. Now forget about that bit, and read reply #63.
Logged

Oz
Offline Offline
God Member
*****
Karma: 4
Posts: 708
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

With you.

Zero counting.

So I "should" have done something more like:
The level[] is now gone.

Got deleted.

Shall put it back in a mo'.

Now I have this bit worked out, indexing them is the next order of business.

I have:
solenoid_outputPins
sol_run_time
and
level

Now I just put a loop around them with an index (like for index = 1 to 5 - English version here) and it can point to the required values.

Am I getting it right?
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
like for index = 1 to 5 - English version here

Zero to five for six elements.
Logged

Oz
Offline Offline
God Member
*****
Karma: 4
Posts: 708
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yeah.

Long day.

Been out running around buying things today for this sketch.
IC, Vero board, looking for pumps and solenoids, etc.

As well as food.....    smiley-roll-blue


But as there are only 5 pots, I guess in the Zero counting way, it would be 0 to 4.
Logged

Oz
Offline Offline
God Member
*****
Karma: 4
Posts: 708
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Continuing to beat my head against the wall, this is the situation now:

Code:
/*
    Automamtic plant pot watering system.
   
    Concept:
    Daily or weekly it waters plant pots.
    Sensors detect if the saucer under the pot is
    full or not, and stop the pump when it detects
    the water depth.
    There is also a "timeout" period per pot incase
    there is a problem with filling the pot.
   
*/

#include <arduino.h>
#include <Wire.h>
#include <stdio.h>
#include "DS1307_1.h"
#include "alarm_clock.h"


//  This sets up the output pins to drive the solenoids
int solenoid_outputPins[] = {8, 9, 10, 11, 12};
//  These are the sensors for each pot and the main reserve
//const byte sensorPins [6] = {};

// Time in seconds each pot takes to be "filled".
//  All values to be set.

int sol_run_time[] = {20, 20, 20, 20, 20};
int level[] = {155, 155, 155, 155, 155};


/*
//  These are the sensors for each pot and the main reserve
//  These need re-assigning because of new output pins used.
#define sensorPins[0] 9
#define sensorPins[1] 10
#define sensorPins[2] 11
#define sensorPins[3] 12
#define sensorPins[4] 13
//#define sensorPins[5] 14
*/

int LEDPin = 13;
int SecondLED = 2;
int buttonPin = 1;
int buttonState = 1;
//  This is used to control the LED for status indication.
int led_status = 0;

//  Set time for daily run.
//int run_time_dow 2;
int run_time_hr = 12;
int run_time_mn = 00;
//int run_time_sec = 00;

// RTC stuff
int rtc[7];
DS1307 RTC=DS1307();             // Create RTC object


//#define setRTC
#ifdef setRTC
// Set/init RTC
  RTC.stop();
  RTC.set(DS1307_SEC,0);
  RTC.set(DS1307_MIN,50);
  RTC.set(DS1307_HR,0);
  RTC.set(DS1307_DOW,3);           // value from 1 to 7. User define whether 1 is sun or mon.
  RTC.set(DS1307_DATE,10);
  RTC.set(DS1307_MTH,06);
  RTC.set(DS1307_YR,12);
  RTC.start();
#endif


void setup()
{

  //  Set up button input and activate internal pull up resistor.
    pinMode(buttonPin,INPUT);   
    digitalWrite(buttonPin,HIGH);
   
    pinMode(LEDPin,OUTPUT);
    pinMode(SecondLED,OUTPUT);
   
    // Set the output pins
//    pinMode(7,OUTPUT);
    pinMode(8,OUTPUT);
    pinMode(9,OUTPUT);
    pinMode(10,OUTPUT);
    pinMode(11,OUTPUT);
    pinMode(12,OUTPUT);

//    digitalWrite(LEDPin,LOW);
//    digitalWrite(SecondLED,LOW);
//    digitalWrite(7,LOW);
    digitalWrite(8,LOW);
    digitalWrite(9,LOW);
    digitalWrite(10,LOW);
    digitalWrite(11,LOW);
    digitalWrite(12,LOW);
   

}

void loop()
{
  buttonState = digitalRead(buttonPin);
  if (buttonState == LOW)
  {
      Solenoid();
  }
 
}
//*************************************************************************************************


void Solenoid()
{
    //
    int need_water;

//    digitalWrite(12,HIGH);

digitalWrite(12,HIGH);

    need_water = sensor_main();
    if (need_water == 1)
    {
        //
        digitalWrite(SecondLED,HIGH);
        led_control(1);
        need_water = sensor_1();
        if (need_water == 1)
        {
            digitalWrite(8,HIGH);
            delay(1000);
        }
//    delay(2000);
        need_water = sensor_2();
        if (need_water == 1)
        {
            digitalWrite(9,HIGH);
            delay(500);
            digitalWrite(8,LOW);
            delay(1000);
        }
//    delay(8000);
        need_water = sensor_3();
        if (need_water == 1)
        {
            digitalWrite(10,HIGH);
            delay(500);
            digitalWrite(9,LOW);
            delay(1000);
        }
//    delay(2000);
        need_water = sensor_4();
        if (need_water == 1)
        {
            digitalWrite(11,HIGH);
            delay(500);
            digitalWrite(10,LOW);
            delay(1000);
        }
//    delay(2000);
        need_water = sensor_5();
        if (need_water == 1)
        {
            digitalWrite(12,HIGH);
            delay(500);
            digitalWrite(11,LOW);
            delay(1000);
            digitalWrite(12,LOW);
        }
        digitalWrite(SecondLED,LOW);
    }
    if (need_water == 0)
    {
          //  Set off alarm saying main tank is low
    }
}
/*
    Call with 0 to turn off indication LED.
    Call with 1 to turn on indication LED.
*/
int led_control(int foo)
{
  static int status;
  status = foo;
  if (status == 0)
  {
      digitalWrite(SecondLED,LOW);
  }
  if (status == 1)
  {
      digitalWrite(SecondLED,HIGH);
  }
}
//*************************************************************************************************
/*
    This is called and returns 1 if more water is needed.
    If it returns 0, the water level is good, so stop the pump.
*/

int sensor_1()
{
    int reading;
    reading = digitalRead(9);
//    if (reading > level1)
    if (reading > level[1])
    {
        return 0;
    }
    return 1;
}

int sensor_2()
{
    int reading;
    reading = digitalRead(10);
//    if (reading > level2)
    if (reading > level[2])
    {
        return 0;
    }
    return 1;
}

int sensor_3()
{
    int reading;
    reading = digitalRead(11);
//    if (reading > level3)
    if (reading > level[3])
    {
        return 0;
    }
    return 1;
}


int sensor_4()
{
    int reading;
    reading = digitalRead(12);
//    if (reading > level4)
    if (reading > level[4])
    {
        return 0;
    }
    return 1;
}

int sensor_5()
{
//    return 1;

    int reading;
    reading = digitalRead(13);
//    if (reading > level5)
    if (reading > level[5])
    {
        return 0;
    }
    return 1;

}

//  This is the main water reserve.
int sensor_main()
{
    int reading;
    reading = digitalRead(14);
    if (reading > level[6])
    {
        return 0;
    }
    return 1;
}

I hope there is not any extra code.

Each LED is supposed to flash on/off.
Further more:  Led 1 turns on, waits.  Led 2 turns on, Led 1 turns off, waits.
Repeats this sequence for 3 to 5.
Then 5 turns off.
All the time another LED is glowing indicating the loop is active.

Now, all things being "normal":  only Led's 1 - 4 glow.  5 Doesn't.
I added an extra line(third-ish line in solenoid):
digitalWrite(12, HIGH);
way before any LED is turned on.

Strange thing is that it doesn't.
But when Led # 3 turns on, Led # 5 turns on.

Ok, I'm open for suggestions.
Logged

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

Code:
if (reading > level[6])
(see reply #48)
Code:
int led_control(int foo)
{
  static int status;
  status = foo;
(see reply #39)

Quote
Ok, I'm open for suggestions.
My suggestion is "Start paying attention to what you're being told".
« Last Edit: July 21, 2012, 07:07:26 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
Shannon Member
****
Karma: 223
Posts: 12577
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, I'm open for suggestions.

My suggestions:

Stop using the sketch you're working on as a dumping ground for bits of code that you have used in the past but no longer need, or bits of code that didn't work, or anything else that your sketch doesn't need right now. It sounds as if you have only got one sketch file and are relying on that for everything. That's a very bad habit to get into. Get into the habit of saving historical versions of your sketch. You can do this either just by taking a copy of the source files, or using a utility such as FileHamster which will keep a backup of every change you make. Or for a little more effort, you can install a full blown change control system - although that is probably overkill for most people.

I see that you're still struggling with the concept and correct use of arrays. If there's something you don't understand, create a minimal sketch to test/explore it. You can copy/paste code between here and the main sketch you're working on. But the time you are desperate enough to trouble the people here to help you, I'd have expected you to put significant effort into solving the problem for yourself and then if you decide you really need help, extract the problematic code into a separate sketch so that you can demonstrate the exact problem with no extraneous code. Most often, the act of doing this will make you realize what was going wrong and you'll find you've solved the problem for yourself.

Expect to read ten times more than you write. You're putting a lot of posts on this thread but ignoring many of the suggestions offered. I suggest you STOP writing comments, STOP coding, and go back and READ all the suggestions people on this thread have already made. If you don't understand them then ask. If you keep ignoring suggestions, then people will naturally stop making them.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
But it still has me perplexed why different LEDs are glowing at different brightnesses in "the other sketch" where I have the pin modes defined.

The operation LEDs generally is generally straight foward. The apparent brightness of an LED can be changed by varying the level of voltage applied, or pulsing the LED on/off faster than the eye can detect, making it seem dimmer. Check to see if the LED is being subjected to some type of fast on/off action in your code (most likely in a loop).
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Oz
Offline Offline
God Member
*****
Karma: 4
Posts: 708
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Zoomkat,

Thanks.  I realise what the problem was.  I fixed it and have actually removed that post.

But I am sitting here looking at the 5 LEDs blink quite happily with a simple sketch.

The output pins are declared (I won't say defined in case it is the wrong word) and written to.
Then the HIGH, LOW cycle is done.  All LED's glow/work as expected.

In my "real" sketch, it is pretty well the same code but LED 5 doesn't want to play the game.

Sure it is a programming issue - it has to be as with another program the LED works.

But I can sit here "until the cows come home" and I am not seeing the problem.

I have cut/pasted lines in case there is a mistake in it which I can't see and change the pin number.  Same result.

I honestly don't see what is stopping LED 5 glowing in one sketch but it does in the other.
Yes, there are differences - they are different sketches - but I have cut/pasted/remarked things out to try and see where/what is causing the problem to no avail.

I can read command structure (again) until the cows come home.  Something isn't "jelling" and so I am missing it.
Logged

Pages: 1 ... 3 4 [5] 6 7 8   Go Up
Jump to: