I am a novice in Arduino programming and I'm setting up an Arduino controlled, underwater time-lapse camera to take a picture every 2 hours. It's going in the ocean for a month and I want to be sure that the code will not fail because of the upper limit that normal integers can go. The Arduino simply switches on a relay (connected to the LED_PIN 11) and the camera does the rest, using a script from the awesome Canon Hackers Development Kit C.H.D.K.
I've tried several variations of sketch, some using simple delay, some with millis and some with counters that print what increment the loop it up to.
One of my fast running test sketches, that used a counter, stopped prematurely, I suspect due to hitting the integer limit but I'm not sure if this only occurred due to the fact that it had a counter in the sketch. So I've gone back to the simplest sketch I can find hoping it will not have this issue.
I think I read that once the integer limit is reached, the sketch will simply restart. Or maybe it will become unpredictable. I'd rather the former than the latter.
Any suggestions would be welcome.
I am sure there are many ways to go about this but I'm looking for the simplest and most robust one I can find, so that I can adjust the async timing easily ie. loop starts CameraOn for 10 seconds CameraOff for 2 hours Loop repeats
thanks in advance for your consideration
Here's the sketch I'm testing right now.
#define LED_PIN 11
#define LED_OFF 7200000 // 2 hours in millis
#define LED_ON 8000 // 6 seconds in millis
unsigned long ms; //time from millis()
unsigned long msLast; //last time the LED changed state
boolean ledState; //current LED state
void setup(void)
{
pinMode(LED_PIN, OUTPUT);
}
void loop(void)
{
ms = millis();
blinkLED();
}
void blinkLED(void)
{
if (ms - msLast > (ledState ? LED_OFF : LED_ON)) {
digitalWrite(LED_PIN, ledState = !ledState);
msLast = ms;
}
}
==================================================================
Okay, I've come up with a new, much simpler sketch based on delay. Can someone please tell me if this is more robust in terms of continued looping for weeks on end?
#define LED_PIN 11
void setup()
{
Serial.begin(9600);
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, HIGH);
}
void loop()
{
delay(7200000); // 2 hours in millis
digitalWrite(LED_PIN, LOW);
delay(8000); // 8 seconds in millis
digitalWrite(LED_PIN, HIGH);
}
#define LED_ON 10000 // 1 seconds in millis
..... tell me, what doesmilli
mean? .... hint: it is a prefix, like in millimeter and milliliter and milliseconds – jsotola Oct 14 '18 at 3:1726,000mAh USB power bank
... Good luck with that... The best 18650 battery packs you can get retail (panasonic) are 13400mAh (4P, 3350/cell). Each one costs £70, so about £18/cell. To get 26,000mAh you would need 8 cells, totalling about £140. And that is with proper batteries. Stuff off eBay / Amazon you'd be lucky to total 2600mAh from all the cells in it. A typical eBay battery has cells of about 1000mAh in them. You'd need 20+ cells in your battery for that to add up... – Majenko♦ Oct 14 '18 at 12:06