One of my first Arduino projects was an intervalometer used for taking time lapses. A very basic yet fully featured creation with an LCD and everything. However in planning for travelling this summer, this big RadioShack box full of wires and other conspicuous-looking stuff might not be very TSA friendly.
A new design I plan for is an atmega328 standing alone with a 16MHz oscillator. Alongside that are a small LED, 2N2222, and an 8 channel dip switch package.
The 8-channel dip switch is for setting the intervals in seconds with binary.
My question is weather or not I would be able to power the atmega328 and notification led with a single 3 volt CR2032 coin cell battery, and weather or not I could power it for very long. Any idea?
You’d have to run at a slower speed, 8-10 MHz, see Figure 28-1 of the 328 datasheet.
and likely not for very long with a CR2032.
They’re only good for 240mAH total,
So even if you could get 30mA out of it, it’s be dead in 8 hours.
Any chance you could use 3 AAAs or 3 AAs instead? Pololu.com has very nice 3 AAA battery boxes with switch, or a single battery with boos regulator if you want it even smaller.
You can get 8 MHz xtal, socket, two 22pf caps, 10K resister, 8 position dip switch from dip micro all for <$2 or so, $2 shipping.
I suppose I could go with a AA battery design.
I was originally planning for all this to be held in a small Altoids gum container, but now a regular Altiods tin seems fine. However in concern for space, could I power the 328 for a considerable time directly from 2 AA batteries instead of 3?
Perhaps look into making the chip sleep for a bit - I'm not sure of the specifics, but having it sleep of some sort for the majority of a second and wake up for the tiny bit of time it is needed could save you a bit of battery power.
Sure, you can do 2 AAs with a boost regulator like this
Sleep mode would help also - perhaps sleep after the interval is up, one button push to wake up & read new time to use from the switches (and to assure you you still have battery life with a couple of LED blinks or something) & 2nd push to start the timer
However in troubleshooting my code, I realised that the Arduino does not want to delay any value over 32000 milliseconds. Any quick ideas, or should I start a new thread elsewhere?
Check out the code:
// Binary Intervalometer
// By Physics_Dude
//
// Digi-pins 2 - 9 have dip switches
// Digi-pins 11 - 13 are for LED, focus, and shutter
// Set dip pins
const int buttonPin2 = 2;
const int buttonPin3 = 3;
const int buttonPin4 = 4;
const int buttonPin5 = 5;
const int buttonPin6 = 6;
const int buttonPin7 = 7;
const int buttonPin8 = 8;
const int buttonPin9 = 9;
// Set led, focus, and shutter pins
const int ledPin = 13;
const int focusPin = 12;
const int shutterPin = 11;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int buttonState5 = 0;
int buttonState6 = 0;
int buttonState7 = 0;
int buttonState8 = 0;
int buttonState9 = 0;
// Delays
int DelayVal = 0; //Delay value at startup
int hold = 100; // Time shutter held down for
void setup() {
// Inputs
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
pinMode(buttonPin4, INPUT);
pinMode(buttonPin5, INPUT);
pinMode(buttonPin6, INPUT);
pinMode(buttonPin7, INPUT);
pinMode(buttonPin8, INPUT);
pinMode(buttonPin9, INPUT);
// Outputs
pinMode(ledPin, OUTPUT);
pinMode(focusPin, OUTPUT);
pinMode(shutterPin, OUTPUT);
}
void loop(){
// Turn all outputs off
digitalWrite(ledPin, LOW); // LED off
digitalWrite(focusPin, LOW); // Focus not pressed
digitalWrite(shutterPin, LOW); // Shutter not pressed
// Read the states of the dip values:
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);
buttonState4 = digitalRead(buttonPin4);
buttonState5 = digitalRead(buttonPin5);
buttonState6 = digitalRead(buttonPin6);
buttonState7 = digitalRead(buttonPin7);
buttonState8 = digitalRead(buttonPin8);
buttonState9 = digitalRead(buttonPin9);
// Lazy math time!
// Bit 1
if (buttonState2 == HIGH) {
DelayVal = DelayVal + 1;
}
// Bit 2
if (buttonState3 == HIGH) {
DelayVal = DelayVal + 2;
}
// Bit 3
if (buttonState4 == HIGH) {
DelayVal = DelayVal + 4;
}
// Bit 4
if (buttonState5 == HIGH) {
DelayVal = DelayVal + 8;
}
// Bit 5
if (buttonState6 == HIGH) {
DelayVal = DelayVal + 16;
}
// Bit 6
if (buttonState7 == HIGH) {
DelayVal = DelayVal + 32;
}
// Bit 7
if (buttonState8 == HIGH) {
DelayVal = DelayVal + 64;
}
// Bit 8
if (buttonState9 == HIGH) {
DelayVal = DelayVal + 128;
}
// Full byte complete!
// Convert to milliseconds
DelayVal = DelayVal * 1000;
// Compensate for shutter press delay.
DelayVal = DelayVal - hold;
//Minimum Delay is 1 second
if (DelayVal < 1000)
{
DelayVal = 1000;
}
// Delay for "DelayVal" milliseconds
delay(DelayVal);
// Done? Now activate outputs!
digitalWrite(ledPin, HIGH); // LED on
digitalWrite(focusPin, HIGH); // Focus pressed
digitalWrite(shutterPin, HIGH); // Shutter pressed
delay(hold); // Time shutter is held down
// Reset DelayVal
DelayVal = 0;
}
" // Convert to milliseconds
DelayVal = DelayVal * 1000;"
So this is convert to seconds
0xFF = 255, * 100 = 255000, which is more than 16 bits (65,535 tops) that an int can hold
Your comments say the min delay is 1 second, 1000mS = 0x03e8
Why not make a blink without delay void loop instead?
unsigned long duration = 1000* (128*switch + 64*switch7 +32*switch5+16*switch4+8*switch3+4*swithch2+switch1)
Note the time that your timer started
unsigned long start_time =millis(), , then go thru void loop comparing how much time has gone by
unsigned long elapsed = millis() - start_time
if elapsed >= duration {stop the timer}