Go Down

Topic: Whats wrong with my device? (Read 4140 times) previous topic - next topic

aballen

Apr 14, 2009, 12:35 am Last Edit: Apr 14, 2009, 12:37 am by aballen Reason: 1
It started out as a little night list for my son, inside a frosted glass jar... but it was chewing up batteries because he fell asleep and never turned it off.  I tried adding a 555 to get it to turn off after one hour... but the 555 just does not seem to work with large intervals like that... so I decided to try using an arduino.  Overkill for sure, but I figure I can add some cool effects, like cyclons, pwm-ing etc.

I used a "dorkboard" due to the form factor and price, and I designed a little adapter board which connects 12 smt leds, and a button switch.

The device works, but with a problem.  I have it on for say 10 minutes, and I "sleep" the device, and it works exactly as expected... but when I change the time to 1 hour I seem to have power problems before the hour is out, lights flicker etc.

I'm using 12 of these
http://www.sureelectronics.net/goods.php?id=389
or
http://www.sureelectronics.net/goods.php?id=388

My math says 20ma * 12 = 240ma per hour for the leds.. add a little for the arduino running at 16mhz.  On three AA batteries that should get a few weeks of use right?

The only thing I can think of is a voltage drop, because there is no LM317 or regulated power on the dorkboard... just batteries straight to the mega168.  I'm thinking there is a voltage drop, so the mega16 resets and/or the voltage across the leds is just gettign too low.  Am I making the correct assumption?

If so I think I'll design my own purpose specific ardunio variant, all smt, with power reg built in.... but I'm not sure, I'm heading down the right path?  Perhaps I can just just make a tiny power regulator and put it inline with the device I already made?

P.S. my little kid said I am a "genius" when he saw what I made for him... so while he may be wrong... I have a lot of motivation to get this working. ;D

Thanks for the input.

AlphaBeta

Maybe you could post you code, there is always a chance that there are something not quite right with the code. :)

aballen

I don't think the code is the problem, but I can post it.  Works perfectly set to 5 minutes, powerd from my usb port it works as expected for 1 hour.  But it never makes it a full hour, even on fresh batteries.

here is the code anyway.

#include <avr/sleep.h>

/*
* NightLight
* This is a night light for gabe that will automatically turn off after one hour
*/

int MAX_SECONDS = 3600;
int countSeconds = 0;
/*
* pins 0 and 1 are not used... but available for debugging, pin 2 is the wake pin
*/
int wakePin = 2;
int lowLEDPin = 3;
int highLEDPin = 14;

void setup() {
 for(int i=lowLEDPin;i<=highLEDPin;i++) {    
   pinMode(i, OUTPUT);      // sets the digital pins as output
 }
 goHigh();  //turn them all on

 pinMode(wakePin, INPUT);  //set wake pin to input
 //Serial.begin(9600);
 //Serial.print("Turning on");
}

void loop() {
   goHigh();
   delay(1000);  
   countSeconds++;
   //Serial.print("seconds is ");
   //Serial.println(countSeconds);
   if(countSeconds>=MAX_SECONDS) {
     goLow();
     sleepNow();
   }
}

void wakeUpNow() {
   goHigh();
   countSeconds=0;
}


void sleepNow() {
   //Serial.println("Sleeping");
   set_sleep_mode(SLEEP_MODE_PWR_DOWN);  
   sleep_enable();
   attachInterrupt(0,wakeUpNow, LOW);
   sleep_mode();            
   sleep_disable();    
   detachInterrupt(0);        
}

void goLow() {
 //Serial.println("Turning off LEDs");
 for(int i=lowLEDPin;i<=highLEDPin;i++) {
   digitalWrite(i, LOW);   // sets the LED on    
 }
}

void goHigh() {
 //Serial.println("Turning on LEDs");
 for(int i=lowLEDPin;i<=highLEDPin;i++) {
   digitalWrite(i, HIGH);   // sets the LED on    
 }
}

AlphaBeta

I failed to read batteries in your original post.

Unfortunantly I'm a software guy, so I can not offer any advice or solution. I can however verify that the code is not the source of the problem. But then again; you already knew that.

/me fail

follower

Can you measure the actual current draw to check it matches your expectations?

--Phil.

westfw

Quote
My math says 20ma * 12 = 240ma per hour for the leds.. add a little for the arduino running at 16mhz.  On three AA batteries that should get a few weeks of use right?
Well, no.  A set of AA batteries is probably good for about 2500mAH of power, so they'd run out of juice in a 240mA circuit in about 10 hours.  On the other hand, it still shouldn't flake out after less than one hour.

OTOH, even 240mA is above the limit that is supposed to be allowed for the whole chip (200mA)

You DO have current limiting resistors of some sort in there, don't you?  An LED will happily consume more than it's rated current without a resistor, and doing THAT 12x over could be a problem in several ways.  I would be inclined to use ~100 ohm resistors for each TWO leds (in the side to the power rail), which would preserve your ability to do patterns and such and give you "full brightness" if you happened to only light one of each pair, and reduced overall current if you have both LEDs in a pair turned on.

aballen

#6
Apr 14, 2009, 07:18 pm Last Edit: Apr 14, 2009, 07:19 pm by aballen Reason: 1
Quote
Can you measure the actual current draw to check it matches your expectations?


yes, I'll try to do that.

Quote
You DO have current limiting resistors of some sort in there, don't you?


yes I do, but I thought the resistors dropped the voltage, not the current.  Regardless I have the correct resistors in line with every led.  One resistor per led.  Wouldn't the leds burn out if the current was too high?

anachrocomputer

Quote
yes I do, but I thought the resistors dropped the voltage, not the current.


Yes, but they also limit the current, compared to the high current that would flow if the resistor was not there.

Quote
Regardless I have the correct resistors in line with every led.  One resistor per led.


Good!

Quote
Wouldn't the leds burn out if the current was too high?


Yes.

aballen

um ok, here is my newb understanding then... I though the resistor limited teh voltage, and the load set the current... so these leds would pull 20ma, even though the mega168 was capable of 40ma on each pin.... did I screw up on the resistors?


westfw

The current and voltage are intimately related (V=I*R), and the current everywhere in a series circuit is the same, so it sounds like you have it wired right, even if your understanding is slightly off (the voltage across the LED will be approximately constant regardless of current, and if the voltage of the supply is greater than the voltage of the LED, in theory LOTS of current will flow, which is why you need the resistor.)  What value of resistor are you using?

While putting an LED directly across a 5V supply will probably burn out the LED, the AVR in the arduino has some internal resistance , and will USUALLY not do so.  But you can get yourself into trouble expecting that to scale to lots of LEDs, or in other circumstances.  You should have resistors, but just because your LEDs haven't burnt out doesn't mean you have the RIGHT resistors.

aballen

I love learning, which is why I play with this stuff.... so this is fun to me, and I appreciate your explanations.

From what I think I am understanding, is though I have the voltage correct, thanks to the resistors, there may be a lot more than 20ma going across each led... and that would not fry them... but it would eat up the battery.... so what can I do to drop the current?  I don't want to change the circuit if I don't have to , I already got a few from batch pcb

Also, I know I mentioned it already, but when powered off my usb... it works perfectly.... just not when on batteries.

I'll check the draw tonight.

aballen

ok one of the leads on the battery broke off last night... so I'm thinking there simply was a bad connection, but it was an opportunity to check the current.

I checked the current, and with the dial at 200m it read 108.5... and I watched it slowly drop to 105.6 before I resoldered the connection... not totally sure what these numbers mean or how to interpret them.

It seemed to work for 1 hour and then turn off... I'll try it again tonight.


westfw

Quote
I checked the current, and with the dial at 200m it read 108.5.

That should be fine overall.  Let us know if the bad connection fix doesn't seem to fix it afterall...

mikalhart

aballen, you had me at "It started out as a little night light for my son..." and then I saw that his name is Gabe just like my son.  A lot of my Arduino motivation comes from enjoying being a "genius" in his shining eyes. :)

Do let us know how you get on.

Mikal

aballen

ok still having a problem.  It seemed to work for one night... and then the next night it started randomly blinking on/off etc..

One think I stated incorrectly was it is powered by 3AAA, not 3AA so there is less ma available... is it possible the voltage is dropping and BOD is just resetting it over and over?


Go Up