Pages: [1]   Go Down
Author Topic: Difference with UNO on USB power vs 9V external wall wart  (Read 1158 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

I hope this is something that I am overlooking but I have a simple sketch that does an analogWrite to set the brightness of an LED.  When I run it powered via USB it runs with the proper delays and everything is timed correctly.  Although when I plug in a 9V 1A power supply in it doesn't run as expected.  My question is why is there a difference in the sequence when I use the external power supply?  My power supply's voltage seems to be OK, my only thought is that the amperage is too high.  From my understanding the PS will only supply the current that is asked for so it shouldn't be the PS current.

Here is a video of what is happening.
http://youtu.be/qrAX4ok1jnk

Here is my sketch.
Code:
/*
Test Program to dim a UV LED
*/

typedef struct{
  byte brightVal;  // Value to set the LED to
  int waitVal;     // The integer part of the wait value
  int x10;         // The power (*10^) value of the wait value.
} pUnit;

const byte numSteps=6;
const byte thePin=11;

pUnit Pattern[numSteps] =
{
  {10,5,2},
  {40,5,2},
  {90,5,2},
  {150,5,2},
  {255,2,3},
  {0,1,4}
};

void setup(){
  pinMode(thePin,OUTPUT);
}


void loop(){
  byte i;
  for(i=0;i<numSteps;i++){    //Step through each of the steps.
    analogWrite(thePin,Pattern[i].brightVal);    //Set the brightness
    delay(Pattern[i].waitVal*pow(10,Pattern[i].x10));    //Wait based on waitVal*10^x10
  }
}

Thank you.

-Andy
Logged

Austin, TX
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6106
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What happens if you run with both USB and 9V connected?

You might consider adding some serial.prints() to display the value of the delay.  At least you can verify when the board is connected via USB that the delay()s are what you expect.

Lastly, what value current limiting resistor are you using with the LED?
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Offline Offline
Newbie
*
Karma: 3
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've noticed, but haven't bothered to fully track down, that the onboard DC regulator doesn't drop the Arduino to the same power level as the USB-supplied power.  I had a project with 4 different thermal sensors - 2 digital and 2 voltage dependent (DHT11 & DS18B20 vs LM35 & something similar), and when the board was running from USB everything agreed, but as soon as I changed to 9v in (or 6v or any of the other source voltages I had) the analog sensors started to skew.  I wasn't interested enough to do the right thing and adjust my script by whatever was coming in on AREF, but I suspect something similar is happening here.  If you have a multimeter, check the voltage difference between the GND and Vin / 5v pins when the Arduino is on USB versus 9v.  My suspicion is that the USB side is feeding your LED 4.5v while the 9v is supplying slightly more than that, causing the changes that I saw in your video.  The delay steps seem fine, but the baseline doesn't start at "off" it starts at something which is visible.

Otherwise yeah, slap some serial debugging in there.  Note that when testing timing sensitive effects, use the fastest serial speed available - 115200 if you can.  Anything slower and you run the risk of your serial transfer overwhelming the timing you are attempting to see.
Logged

Austin, TX
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6106
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

My suspicion is that the USB side is feeding your LED 4.5v while the 9v is supplying slightly more than that, causing the changes that I saw in your video. 
USB allows the 5V pin to range from 4.45 to 5.5V.  Also take into account a small drop from the USB itself plus whatever wire gets to the port on the computer.  The Arduino has a poly fuse built in on the Vusb.  The closer it gets to 500mA the more voltage it drops (that's how it works, by slowly opening up.)

Whereas the onboard regulator will do a very decent job of regulating very close to a nominal 5v (or whatever that particular part's nominal is.)

This is a very likely possibility for the sensor situation, but not with what the original poster is seeing.
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Pages: [1]   Go Up
Jump to: