Go Down

Topic: Potted plant watering system. (Involves water pumps.) (Read 11 times) previous topic - next topic

PaulS

There is a world of difference between
Code: [Select]
         digitalWrite(solenoid_[i],HIGH);
and
Code: [Select]
    digitalWrite(ledPins[thisPin], HIGH); 

The compiler converts names to addresses. Then, it discards the names. There is nothing in the hex file that gets uploaded to the Arduino that is called solenoid_ anything.

You can create an array of pins that the solenoids are attached to (solenoidPins[]), similar to ledPins[] in the code that works, and then use
Code: [Select]
         digitalWrite(solenoidPins[i],HIGH);

wildbill

Repeating what I suggested in a prior similar thread:

Consider raising the captured water container so you can use gravity feed. Then you can dispense with level detection and the pump.

lost_and_confused


There is a world of difference between
Code: [Select]
         digitalWrite(solenoid_[i],HIGH);
and
Code: [Select]
    digitalWrite(ledPins[thisPin], HIGH); 

The compiler converts names to addresses. Then, it discards the names. There is nothing in the hex file that gets uploaded to the Arduino that is called solenoid_ anything.

You can create an array of pins that the solenoids are attached to (solenoidPins[]), similar to ledPins[] in the code that works, and then use
Code: [Select]
         digitalWrite(solenoidPins[i],HIGH);



So this _ character makes a big difference?

I was starting to think along those lines, but had not got around to checking myself on it.

Thanks for the info.

WRT lifting the water and using gravity:
Well, nice idea, but it is a LOT of water.  Probably 100 Litres or more.  That is a lot of weight to eleveate.  That means making a support for the container and all that kind of stufff.

Thanks, but for now I am wanting to concentrate on the programming side of things and not have to get too muchh into the mechanical side of building "structures" to support 100KG of water above a certain height.

lost_and_confused

#13
Jul 17, 2012, 10:03 am Last Edit: Jul 17, 2012, 10:23 am by lost_and_confused Reason: 1
Well,

"I give up".

Here is what I did:

Code: [Select]

//  Array for each pot's fill time
int sol_run_time[5];
//  Array for the values for the system to look for to indicate "full"
int level[6];
//  Solenoid array
int solenoid[5];
//  Sensor array
int sensor[6];


//  These are the sensors for each pot and the main reserve
#define sensor[0] 14
#define sensor[1] 15
#define sensor[2] 16
#define sensor[3] 17
#define sensor[4] 18
#define sensor[5] 19



//  These are the pins to drive each solenoid for each pot.
//  They are OR'd together to turn on the motor/pump.
//int solenoid[5];
#define solenoid[1] 0
#define solenoid[2] 1
#define solenoid[3] 2
#define solenoid[4] 3
#define solenoid[5] 4



#define LED 5
#define btn_1 6

//  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()
{
   //
   pinMode(sensor[0],INPUT);
   pinMode(sensor[1],INPUT);
   pinMode(sensor[2],INPUT);
   pinMode(sensor[3],INPUT);
   pinMode(sensor[4],INPUT);
   pinMode(sensor[5],INPUT);

The rest is not included.

Still fails.

V1.cpp: In function 'void setup()':
V1:83: error: expected primary-expression before '[' token
V1:84: error: expected primary-expression before '[' token
V1:85: error: expected primary-expression before '[' token
V1:86: error: expected primary-expression before '[' token


So I am really missing something.


Hang on!

Ok, "Pins" is missing in the text.

Changing now.



lost_and_confused

Eurika!

Is this it?

Code: [Select]

/*
    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"


//  Array for each pot's fill time
int sol_run_time[5];
//  Array for the values for the system to look for to indicate "full"
int level[6];
//  Solenoid array
int solenoid[5];
//  Sensor array
int sensor[6];


//  These are the sensors for each pot and the main reserve
#define sensorPins[0] 14
#define sensorPins[1] 15
#define sensorPins[2] 16
#define sensorPins[3] 17
#define sensorPins[4] 18
#define sensorPins[5] 19



//  These are the pins to drive each solenoid for each pot.
//  They are OR'd together to turn on the motor/pump.
//int solenoid[5];
#define solenoidPins[1] 0
#define solenoidPins[2] 1
#define solenoidPins[3] 2
#define solenoidPins[4] 3
#define solenoidPins[5] 4



#define LED 5
#define btn_1 6

//  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()
{
    //
    pinMode(sensor[0],INPUT);
    pinMode(sensor[1],INPUT);
    pinMode(sensor[2],INPUT);
    pinMode(sensor[3],INPUT);
    pinMode(sensor[4],INPUT);
    pinMode(sensor[5],INPUT);

    pinMode(btn_1,INPUT);   
   
    pinMode(solenoid[1],OUTPUT);
    pinMode(solenoid[2],OUTPUT);
    pinMode(solenoid[3],OUTPUT);
    pinMode(solenoid[4],OUTPUT);
    pinMode(solenoid[5],OUTPUT);

    pinMode(LED,OUTPUT);
   
    digitalWrite(LED,LOW);
    digitalWrite(solenoid[1],LOW);
    digitalWrite(solenoid[2],LOW);
    digitalWrite(solenoid[3],LOW);
    digitalWrite(solenoid[4],LOW);
    digitalWrite(solenoid[5],LOW);

    // Time in seconds each pot takes to be "filled".
    //  All values to be set.
    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;
   
    //  All values to be set.
    level[1] = 20;
    level[2] = 20;
    level[3] = 20;
    level[4] = 20;
    level[5] = 20;
    level[6] = 20;      //  This will be the main reserve, and when it is empty rather than full.

}

void loop()
{
    //  Get time from RTC.
    int rtc[7];
    RTC.get(rtc,true);
    int flag;
    //  Have time, check what time it is.
    if (btn_1 == HIGH)
    {
        Solenoid();
    }
    //
    if (rtc[2] == run_time_hr)
    {
        if (rtc[1] == run_time_mn)
        {
            if (flag == 0)
            {
                //
                Solenoid();
                flag = 1;
            }
        }
    }
   
}

//*************************************************************************************************

void Solenoid()
{
    int i;
    for (i=0;i<5;i++)
    {
        //  Get time value for i
        //  Turn on soldenoid i
        //  Wait the specified time
        //  Check sensor for input
        //  Abort if active
        //  Turn off solenoid i
        digitalWrite(solenoid[i],HIGH);
        sensor_delay(i);
    }
}

//*************************************************************************************************

int sensor_delay(int x)
{
    //  Read threashold values for all sensors.
    //  i is current one, but Main gets read every time anyway.
    int i = x;
    int reading;
    int TTG;
    int time_up;
    TTG = sol_run_time[i];
    time_up = timer(TTG);
    if (time_up > 0)
    {
        reading = digitalRead(sensor[0]);
        if (reading > level[6])      //  Main reserve is good.
        {
            reading = digitalRead(sensor[i]);
            if (reading > level[i])
            {
                //  Water level reached.  Stop pumping and go to next plant.
                TTG = 0;
                digitalWrite(solenoid[i],LOW);
            }
            //  This is if the plant's water is already good
        }
        //  This is if the main level is not good.
    }
    // time_up = 0
}
//return 0;
   
//*************************************************************************************************
   
int timer(int foo)
{
    static int counter;
    counter = foo;
    int rtc[7];
    int min_flag;
    RTC.get(rtc,true);
        if (counter >0)
        {
           if (min_flag != rtc[1])
           {
               min_flag = rtc[1];
               counter = counter - 1;
           }
        }
    return counter;
}

//*************************************************************************************************


It complies ok.


Go Up