Hello,
I search for do an action with my arduino weekly.
Could i use delay(604800000) for this action ?
Or it s a too long number for arduino memory ?
Thank you
Hello,
I search for do an action with my arduino weekly.
Could i use delay(604800000) for this action ?
Or it s a too long number for arduino memory ?
Thank you
delay() takes an unsigned long as a parameter
An unsigned long on most Arduinos can be used to time up to 49 and a bit days
Conclusion - delay() can be used to time a period of 1 week easily, but how accurate do you want/need it to be ? Would an error of say 1 hour be acceptable, 1 minute, 1 second ? What ?
You would be better off using a Real Time Clock (RTC) module for such long periods. Does the Arduino need to do anything else during the delay() period ? I hope not
An RTC would be the best solution, but if you want to do it all in the Arduino, there's a useful function in the FastLED.h library called EVERY_N_period that is non-blocking, so your Arduino could do other things during the week.
void loop() {
EVERY_N_HOURS(168) {
<your weekly code here>;
}
}
Perfect, thank you fo the answers.
It's a project for spray a garden automatically !
Some plant need water only 1 time every 15 days, an
arduino micro is adequate for it.
One advantage to using an RTC is you get some good ability to handle power interruptions.
There are other approaches.
What do you plan/hope/care about with respect to power interruptions? How likely do you think they might be?
Just wondering.
a7
I can put moisture sensors in soil to contrain spray under specific level, it's safer if an power interruption become.
But what is possible to do with RTC about power interruption ?
I had command RTC circuit with your advice.
Noisca, how long can hold arduino micro ? I don't know...
that depends on your battery.
I thougt plug my arduino for the power.
P1GOU1:
I thougt plug my arduino for the power.
Okay. Supposing almost a week has passed. It's almost time to water the plants. The mains power stops for some reason (maybe a lightning storm or a central transformer overloads...). When the power is restored, the Arduino will reset and the plants will not get water for another week. So they will be without water for 2 weeks, not just one. Using an RTC solves this problem by keeping the time when the power is gone.
Another option would be to use the simple timer library.
#include <SimpleTimer.h>
SimpleTimer timer;
unsigned long minute = 60*1000;
unsigned long hour = 60*minute;
unsigned long day = 24*hour;
void setup()
{
timer.setTimeout(day*5, waterfunction);
}
void loop()
{
timer.run();
}
void waterfunction()
{
//YOUR WATERING FUNCTION HERE
}
You could forgo an RTC if you save the Arduino time to EEPROM at power fail time.
However, a DS3231 costs $2.00 and is physically small.
Bite the bullet and use an RTC.
The RTC you picture has been found to damages the battery, which is the wrong type for the trickle charging the circuit provides.
Remove the SM resistor and diode near the SCL pad on the non-pins end of the PCB.
Or cut a certain PCB traces.
a7
I just remove the resistor. They're in series so that's all you need to stop the charging current. I figure the diode might be hard to find if I needed to put it back for some weird reason (i.e. using a rechargeable battery).
Get a medium dab of solder on the iron, put it on top of the resistor and nudge sideways gently. It should slide off and stick to the iron. Use eye protection if you try to cut it. It's exceedingly brittle.
Another nice thing about it, the dual I2C pin sets. So, you can daisy chain connect another I2C to it instead of the board. This is useful if the board doesn't have enough I2C pins. Also the on board EEPROM. This is a little hazy because I thought of it quite a while ago and got sidetracked, but I think if you run it on 3.3V the battery problem is either solved or very greatly reduced, but the EEPROM won't work on 3.3V.
aarg:
I just remove the resistor. They're in series so that's all you need to stop the charging current. I figure the diode might be hard to find if I needed to put it back for some weird reason (i.e. using a rechargeable battery).Get a medium dab of solder on the iron, put it on top of the resistor and nudge sideways gently. It should slide off and stick to the iron. Use eye protection if you try to cut it. It's exceedingly brittle.
Another nice thing about it, the dual I2C pin sets. So, you can daisy chain connect another I2C to it instead of the board. This is useful if the board doesn't have enough I2C pins. Also the on board EEPROM. This is a little hazy because I thought of it quite a while ago and got sidetracked, but I think if you run it on 3.3V the battery problem is either solved or very greatly reduced, but the EEPROM won't work on 3.3V.
Yes. I take a sort of belt and suspenders approach, and further challenge myself to get both components off without damaging them. Sometimes I succeed.
larryd:
…
However, a DS3231 costs $2.00 and is physically small.
I had a number of DS1307s with a soldered on battery and decided to replace them with newer and more accurate and replaceable battery DS3231s.
I found them for $5, ordered 8.
I received 8 packages of 5 units! so now I have a lifetime supply (old) of RTCs and 2032 coin cells.
I’ve been throwing them into everything.
a7