Pages: 1 2 3 [4] 5 6 ... 18   Go Down
Author Topic: Time and TimeAlarms Libraries – Ask here for help or suggestions  (Read 71701 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I am having a problem compiling a sketch in Arduino 1.0 that compiled and uploaded just fine in Arduino 23. Any suggestions on how I can fix these errors:

C:\Arduino\arduino-1.0\libraries\TimeAlarms\TimeAlarms.cpp:25:22: error: WProgram.h: No such file or directory
C:\Arduino\arduino-1.0\libraries\TimeAlarms\TimeAlarms.cpp: In member function 'void TimeAlarmsClass::delay(long unsigned int)':
C:\Arduino\arduino-1.0\libraries\TimeAlarms\TimeAlarms.cpp:256: error: 'millis' was not declared in this scope

Is anyone else having this trouble?

Thanks,
Jeff
Logged

Adelaide, South Australia
Offline Offline
Full Member
***
Karma: 0
Posts: 144
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

you need to read through "Readme.txt" file on the downlaod opage for Arduino 1.0. It explains a few changes that you will need to make, such as replacing "Wprogram.h" with "Arduino.h" in you programs and any libraries using it.
Logged

ottawa, canada
Offline Offline
God Member
*****
Karma: 6
Posts: 990
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There may be a new version of the library posted to correct the problem - look wherever you got it.  If not, find the file C:\Arduino\arduino-1.0\libraries\TimeAlarms\TimeAlarms.cpp and open it with notepad.  At line 25 you'll find the reference to Wprogram.h which you can change to Arduino.h and save.
Logged

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

Yes, thank you. That worked fine. Just change the reference from Wprogram.h to Arduino.h and all is well again.
Logged

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

Hi there,
I'm making a self watering system, that has a reed switch that indicates if the water level is low, a moisture sensor for the soil, and a battery voltmeter to let me know when I should recharge my batteries, and a relay to turn on the pump.
Here is what I want to do.
  • Blink the LED if my battery gets below 7 volts - it would be nice to check this every 5 minutes or so.
  • If the water level goes below a certain point, I also want the LED to blink - want to check the value while pumping water
  • If the moisture is < 900, start the pump for 5 seconds, wait 10 seconds, then check the moisture sensor.  If it's still <900 continue until it isn't
  • I want to run this code every 3 days (don't want too much water going to my plant)

I've been trying to work with the Time library to do the following:
  • check battery level every 5 minutes
  • wait 10 seconds for another moisture reading before starting the pump again
  • Run the code after 36 hours

I've taken out the time code from the sketch because I wanted to show that this working how I want it, just not with respect to the time I'm looking for.


Just getting a little frustrated with all these times.  Any help or suggestions would be greatly appreciated.


Code:
/*
 * Gardening Project v1.2
 * Combining the capacitive sensor, moisture sensor, pump and led indicator.
 * Reading how much water is in the container.
 * Reading how much moisture is in the ground.
 * Pumping water if moisture is dry.
 * LED
 * Red - low battery , blink
 
 */
#include <Bounce.h>
#include <Time.h>
#include <TimeAlarms.h>

#define LED 9  // LED on pin 9
#define SWITCH 10  // Defines the Reed switch on digital pin 10
int reed_val = 0;  // used to store the input of the reed switch
Bounce bouncer = Bounce( SWITCH,10 );

//  Volt monitoring
  int batteryPin = 1;
  float vout = 0;
  int value = 0;
  float R1 = 991;    // !! resistance of R1 !!
  float R2 = 995;     // !! resistance of R2 !!
  float vin = 0;

// Moisture Sensor
  int moistureSensor = 5;  // Sensor pin 5, other pin connected to GRN through a 10k resistor
  int moisture_val;  // Storing the current value of the Sensor pin
  int waterpump = 7;  // Initializing pin 7 for waterpump


void setup()  {
  Serial.begin(9600);
  pinMode(SWITCH, INPUT);  // Defines the switch as an input
  digitalWrite(SWITCH, HIGH);
  pinMode(LED,OUTPUT);  // LED as an output
  pinMode(waterpump,OUTPUT);  // Setting waterpump to output
  digitalWrite(waterpump,LOW);  // waterpump off

 
}

void loop()  {
 
  analogReference(EXTERNAL);
  bouncer.update();
  int reed_val= bouncer.read();
  moisture_val = analogRead(moistureSensor);
 
  // Volt Monitoring
  value = analogRead(batteryPin);
  vout= (value * 5)/1024.0;  //voltage coming out of the voltage divider
  vin = vout / (R2/(R1+R2));  //voltage to display
 

  // Debugging with LCD
  Serial.print("V: ");  // Print out V:
  Serial.println(vin);  // This is where the number of volts are displayed
  Serial.print("M: ");
  Serial.println(moisture_val);
  Serial.print("Reed: ");
  Serial.print(reed_val);
  delay(100);

  if (vin < 7.0)  {
    digitalWrite(waterpump,LOW);
    digitalWrite(LED,HIGH);  // LED turns on
    delay(200);
    digitalWrite(LED,LOW);
    delay(200);
 }

// Reed Switch monitoring
 
  if (reed_val==HIGH)  {
    Serial.println("Fill Water");
    digitalWrite(waterpump,LOW);
    digitalWrite(LED,HIGH);
    delay(200);
    digitalWrite(LED,LOW);
    delay(200);
   
  }


  // Check whether input is LOW (switch closed)
  if (moisture_val < 900 && reed_val==LOW)  {
    Serial.println ("Turning on pump");   // Debugging or adding add to LCD
    digitalWrite(waterpump,HIGH);  // waterpump on
    delay(5000);
   
   
  }
  digitalWrite(waterpump,LOW);

 
  }
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 613
Posts: 49310
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't see that you need the Time or TimeAlarm libraries at all.

What you want to do can be done with a pencil and paper (variables on the Arduino) and a watch/clock (the millis() function on the Arduino).

On each pass through loop, see if it is time to check the battery level. If it is, check the battery level, and set the lastChecked time to now.

See if it is time to turn the water on. If it is, turn the water on and set the lastWaterOn time to now.

Do the same for moisture reading.

The 3 day pause affects everything? The plant dries out and dies during that 3 days, and that's OK? The battery does dead in that 3 days, and that's OK?

If you turn the system off for 3 days (i.e. do nothing in that time) and then check the water level, and it is fine, so you turn off for three days again, it could take a long time before you check the battery level. So, be careful that you check everything before going into do-nothing-for-three days mode.

Frankly, I think you have some contradictory requirements, which might explain your difficulties implementing them.
Logged

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

Thanks for your help PaulS.

Are you suggesting not to use the Time library at all?  Instead use  millis() ?
One of the reasons I would like to use the Time library is due to the draw of mA.  If I use the code without the Time library I'm drawing about 30mA, then when the relay turns on it uses up to 90mA.
If I'm counting using the Time library I seem to be only using 20mA while it's counting, then of course it uses the same 90mA when the relay kicks in.

My thought was that as long as I'm checking the battery every 5 minutes or so, if the battery drops below 7 volts, I will be notified by a blinking LED and go and charge it.  Since this is outside of the 3 day pause, i would be notified at least within 5 minutes and not have to wait for a full 3 days before I found out.

The plant is a palm and it's winter...so I doubt the plant is going to completely dry out in 3 days, plus I figured this should save battery power.  I can change the amount of time to check later if I find it drying out too fast.  I understand what you're saying about checking every three days, perhaps I should start with every day to check. 

Battery check - every 5 minutes
Waterlevel check - once every day
Moisture check - once every day

Cheers




Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 613
Posts: 49310
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So, you want the Time library to wake the Arduino every 5 minutes

Check the battery level and increment a counter for the number of times the timer has disturbed your sleep.

If the battery voltage is low, stay awake, blinking the LED.

If the counter hits some value, check for the need for water. If it needs watering, stay awake and water the plant. Reset the counter when done.

Go back to sleep. Repeat when the timer goes off again.

Watering the plant should be completed in 5 minutes, so go back to sleep at the 5 minute mark, to get back on the 5 minute sleep/wake cycle.
Logged

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

Yes , I want to wake the Arduino every 5 minutes to check the battery and water level.
Not sure what you mean about incrementing a counter for the number of times the timer has disturbed you sleep?
Yes, stay awake and blink the LED if the voltage is low. 
Wake the Arduino every 24 hours and check if the moisture value is below 900 (900 is wet soil).  If it needs watering, turn on pump for 5 seconds, then wait 5 seconds before reading the value again.  If it needs watering, turn on pump for another 5 seconds, then wait 5 seconds before reading value again.  Continue this procedure until the value is above 900.

Thanks again, I appreciate the help.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 613
Posts: 49310
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The Arduino starts. It does some stuff, and goes to sleep. 5 minutes later, the alarm goes off. That's 1. It does some stuff, and goes to sleep. 5 minutes later, the alarm goes off. That's 2. It does some stuff, and goes to sleep. 5 minutes later, the alarm goes off. That's 3...

That is counting. When the counter gets to 12, that's 1 hour. When it gets to 288, that's 1 day.
Logged

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

Thanks for all your help.
I have it working as you suggested (sort of).
The one thing that has me a bit stumped right now is that I can't seem to get the waterpump to turn on and off every 5 seconds (while it's within the Water (); function) so that it can re-check the moisture value and the reed switch value.  
I have listed the code that I have so far.
You'll notice that I have the "Battery" function set to run every 5 seconds ( this is for testing purposes only).  Normally I will have this set for
Code:
Alarm.timerRepeat(0,5,0,Battery);
The Counter == 5 in the loop is also for testing purposes only.  Normally this would be set as you suggested.
Code:
if (Counter == 12)  {
    Water();
    Counter = 0;
  }




Code:
/*
 * Gardening Project v1.2.3
 * Combining the capacitive sensor, moisture sensor, pump and led indicator.
 * Reading how much water is in the container.
 * Reading how much moisture is in the ground.
 * Pumping water if moisture is dry.
 * LED
 * Red - low battery , blink
 
 */
#include <Bounce.h>
#include <Time.h>
#include <TimeAlarms.h>
#define LED 9  // LED on pin 9
#define SWITCH 10  // Defines the Reed switch on digital pin 10

int reed_val = 0;  // used to store the input of the reed switch
Bounce bouncer = Bounce( SWITCH,10 );

int Counter = 0;  // Set counter
int waterCounter = 0;  // Set watering counter

//  Volt monitoring
  int batteryPin = 1;
  float vout = 0;
  int value = 0;
  float R1 = 991;    // !! resistance of R1 !!
  float R2 = 995;     // !! resistance of R2 !!
  float vin = 0;

// Moisture Sensor
  int moistureSensor = 5;  // Sensor pin 5, other pin connected to GRN through a 10k resistor
  int moisture_val;  // Storing the current value of the Sensor pin
  int waterpump = 7;  // Initializing pin 7 for waterpump


void setup()  {
  Serial.begin(9600);
  pinMode(SWITCH, INPUT);  // Defines the switch as an input
  digitalWrite(SWITCH, HIGH);
  pinMode(LED,OUTPUT);  // LED as an output
  pinMode(waterpump,OUTPUT);  // Setting waterpump to output
  digitalWrite(waterpump,LOW);  // waterpump off
  // Time
  setTime(0,0,0,13,12,11);
  Alarm.timerRepeat(5,Battery);

}

void loop()  {
  // Display the countdown timer
  digitalClockDisplay();
  Alarm.delay(1000); // wait one second between clock display
  
  if (Counter == 5)  {
    Water();
    Counter = 0;
  }
  
}

// Start of Functions

  void Water()  {
    
  analogReference(EXTERNAL);
  bouncer.update();
  int reed_val= bouncer.read();
  moisture_val = analogRead(moistureSensor);
  Serial.print("M: ");
  Serial.println(moisture_val);
  // Check whether input is LOW (switch closed)
  if (moisture_val < 900 && reed_val==LOW)  {
    Serial.println ("Turning on pump");   // Debugging or adding add to LCD
    digitalWrite(waterpump,HIGH);  // waterpump on
    Alarm.delay(5000);
    bouncer.update();
    int reed_val= bouncer.read();
    moisture_val = analogRead(moistureSensor);
  
    if (reed_val==HIGH)  {
      return;
    }
  }
  }
  
  void Battery()  {
  // Volt Monitoring
  analogReference(EXTERNAL);
  value = analogRead(batteryPin);
  vout= (value * 5)/1024.0;  //voltage coming out of the voltage divider
  vin = vout / (R2/(R1+R2));  //voltage to display
  while (vin < 7.0)  {
    digitalWrite(waterpump,LOW);
    digitalWrite(LED,HIGH);  // LED turns on
    Alarm.delay(200);
    digitalWrite(LED,LOW);
    Alarm.delay(200);  
  }
  // Debugging with LCD
  Serial.print("V: ");  // Print out V:
  Serial.println(vin);  // This is where the number of volts are displayed
  
  // Reed Switch monitoring
  bouncer.update();
  int reed_val= bouncer.read();
  while (reed_val==HIGH)  {
    Serial.println("Fill Water");
    digitalWrite(waterpump,LOW);
    digitalWrite(LED,HIGH);
    Alarm.delay(200);
    digitalWrite(LED,LOW);
    Alarm.delay(200);
    bouncer.update();
    int reed_val= bouncer.read();
    if (reed_val==LOW)  {
      return;
    }
  }
  Counter++;
  
  }
  
 void digitalClockDisplay()  {
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.println();
  }

void printDigits(int digits)  {
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
  }

« Last Edit: December 21, 2011, 02:54:56 am by Happyworker » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 613
Posts: 49310
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Apparently you do know how to use the Serial.print() function to print values. Use it to print messages, too. How often does Battery() get called. What is the value of Counter in loop?

I don't see anything in your code that puts the Arduino to sleep between Alarm calls to Battery.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

Is there any incompatibility between these libraries?
#include <Wire.h>
#include <Time.h>
#include <TimeAlarms.h>

I am working on Arduino 1.0, Windows 7. My aim is to build an intervallometer. It works fine but I do some calculations based on the time from Arduino was started (millis()). The use of Alarm.timerRepeat appears usefull for me. It compiles well alone, but when I try to use this function into my original project, it has no effects: project compiles, but my function is never call.
I was wondering if some libraries were using same ressources (same timer ?).

Logged

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

Hey all just wanting to know if it is possible to parse variable via the functions specified in the setting of alarms.

I have included an example below as i am unsure how to explain it. Not going to be my arduino for a few days and really really want to know if it will work for when i am smiley-grin.

Thanking you in advanced.

 

Code:
#include <Time.h>
#include <TimeAlarms.h>

void setup()
{

int length = 1000;

  Serial.begin(9600);
  setTime(8,29,0,1,1,11); // set time to Saturday 8:29:00am Jan 1 2011
 
  // create alarm
  Alarm.alarmRepeat(8,30,0, MorningAlarm(length));


 

}

void  loop(){ 
  digitalClockDisplay();
  Alarm.delay(1000); // wait one second between clock display
}

void MorningAlarm(int slen){
  Serial.println("Alarm sounding.");   
  Alarm.delay(slen);
}


void digitalClockDisplay()
{
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.println();
}

void printDigits(int digits)
{
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 613
Posts: 49310
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Hey all just wanting to know if it is possible to parse variable via the functions specified in the setting of alarms.
If, as it appears, you are asking if you can use a variable to hold the value passed to the functions, then the answer is yes, of course you can.
Logged

Pages: 1 2 3 [4] 5 6 ... 18   Go Up
Jump to: