Go Down

Topic: Sketch different behavior using external power instead of USB cable (Read 1 time) previous topic - next topic

nisant

Hi all, I'm new at Arduino and at Arduino Forum so I hope not to be OT here with my question.
I have a simple sketch that drives a led using another one as light sensor.

It works well when the board is powered through USB cable attached to the computer.
When I power it through external power (9V ac-dc) the behavior changes.

Is this a strange thing or something that I could expect?

I can't verify values in the second configuration because inserting USB cable to use serial monitor switches power back to USB source (at least that seems to me).
Any suggestion to debug in this situation?

Thanks in advance for you help.
:)

Bye.
Antonio

Arrch


When I power it through external power (9V ac-dc) the behavior changes.


But you're not going to tell us the expected behavior, the actual behavior, or provide us any code and/or wiring diagram?

nisant

You are absolutely right ...  :smiley-fat:

Adruino UNO.

This is the sketch:

/*
  Switch ON yellow LED when casting shadow over green LED
*/

int g = 9, y = 11, carica;

void setup() { 
  pinMode(y, OUTPUT);
  Serial.begin(9600); 
       
}

void loop() {
  pinMode(g, OUTPUT);
  digitalWrite(g, HIGH); 
  delay(50);
  pinMode(g, INPUT);
  carica = analogRead(A1);
  Serial.println(carica);
  digitalWrite(g, LOW);
  delay(200);
  Serial.println(analogRead(A1));
  if (carica - analogRead(A1) < 180)
    digitalWrite(y, HIGH);
  else digitalWrite(y, LOW);
  delay(30);
}

The two LEDs (green pin 9 sensor, yellow pin 11 light emitter) are driven through 220ohm resistors.
I "charge" green LED as a capacitor at the beginning of loop and read its tension through pin A1, then I read the residual tension after 200ms.
Knowing that the discharge is faster if the LED is in light condition than in shadow I decide to switch yellow LED OFF or ON (I use a threshold of 180).

Using USB power I have the expected behavior (yellow LED ON in shadow and OFF in light).
Using external power (9V) yellow LED OFF in light an slowly blinking in shadow.
Using external power (15V) yellow LED blinks slowly regardless light conditions.

I can't explain it.

PeterH


Using USB power I have the expected behavior (yellow LED ON in shadow and OFF in light).
Using external power (9V) yellow LED OFF in light an slowly blinking in shadow.
Using external power (15V) yellow LED blinks slowly regardless light conditions.

I can't explain it.


Your sketch prints messages to the USB port, so perhaps the timing is affected by whether the USB port is connected. If you remove the Serial.print statements do you still see any difference?
I only provide help via the forum - please do not contact me for private consultancy.

mkwired

The USB voltage is not guaranteed to be 5V.  It could be as low as 4.4V and as high as 5.25V.  With the linear regulator used with external power, you will get 5V.

retrolefty

#5
Jan 22, 2013, 12:11 am Last Edit: Jan 22, 2013, 12:13 am by retrolefty Reason: 1

The USB voltage is not guaranteed to be 5V.  It could be as low as 4.4V and as high as 5.25V.  With the linear regulator used with external power, you will get 5V.


Not likely. Voltage regulators are subject to their own device tolerance allowed, just like the 5vdc voltage source powering the PC's USB port.
                 
A typical output voltage tolerance for a linear 5 vdc regulator might be:
IO = 5 mA to 1 A, VI   = 7 V to 20 V, 25°C =    4.8 - 5.2  VDC
                                      0°C to 125°C =    4.75 - 5.25 VDC

Or did you believe that the Arduino folks hand pick and select their voltage regulators for 5.000 vdc output so that the analogRead() function would be as accurate as possible?  ;)

Lefty

mkwired


nisant


Your sketch prints messages to the USB port, so perhaps the timing is affected by whether the USB port is connected. If you remove the Serial.print statements do you still see any difference?

Same result, unfortunately.



The USB voltage is not guaranteed to be 5V.  It could be as low as 4.4V and as high as 5.25V.  With the linear regulator used with external power, you will get 5V.

Can this tolerance explain
Not likely. Voltage regulators are subject to their own device tolerance allowed, just like the 5vdc voltage source powering the PC's USB port.
                 
A typical output voltage tolerance for a linear 5 vdc regulator might be:
IO = 5 mA to 1 A, VI   = 7 V to 20 V, 25°C =    4.8 - 5.2  VDC
                                      0°C to 125°C =    4.75 - 5.25 VDC

Or did you believe that the Arduino folks hand pick and select their voltage regulators for 5.000 vdc output so that the analogRead() function would be as accurate as possible?  ;)

Lefty


I have changed the threshold to 280 first and 380 after and in the USB power configuration the sketch has continued to work fine.
In external power, instead, the behavior has become erratic.

It is hard to understand if I can't see values returned by reading A1 pin ... is there any workaround to force external power while USB cable is connected?

retrolefty

Quote
It is hard to understand if I can't see values returned by reading A1 pin ... is there any workaround to force external power while USB cable is connected?


That is how the existing auto-voltage switching circuit already works. If both USB and proper external DC power is available at the same time, the circuit utilizes only the 5vdc regulated from the external DC voltage source and switches off the FET switch path to the USB 5vdc power source.

Lefty


retrolefty


The NCP1117ST50T3G is trimmed to be +/- 1%.


That is an impressive spec. Older arduino boards used less accurate tolerance regulators.

Lefty

nisant


That is how the existing auto-voltage switching circuit already works. If both USB and proper external DC power is available at the same time, the circuit utilizes only the 5vdc regulated from the external DC voltage source and switches off the FET switch path to the USB 5vdc power source.

Lefty

I read that but I can't understand why the sketch works fine while the board is connected to both the sources and doesn't work if connected only to external source.
It should be powered by external source in both cases.

retrolefty

Quote
I read that but I can't understand why the sketch works fine while the board is connected to both the sources and doesn't work if connected only to external source.
It should be powered by external source in both cases.


I'm not sure you have described your problem symptom(s) description well enough for anyone to actually help you with it. Also a wiring drawing might be helpful as it might be a current limiting situation when using one voltage source Vs the other.

Lefty

PeterH

The current (sorry!) suspicions point towards variations in the supply voltage. It would be worth getting an accurate volt meter and measuring what the +5V voltage is in each case to see whether there is any significant variation.

It may be that the external voltage supply is not sufficiently smoothed, in which case a simple meter may not show that. I'm not sure what to suggest for that - I suppose you could write a sketch that monitors the Arduino's own supply voltage by using a voltage divider?
I only provide help via the forum - please do not contact me for private consultancy.

nisant

I'm gonna follow these suggestions and post here the results along with a wiring diagram.
A question about making Arduino board self measuring voltage using one of its analogRead().
Could the floating voltage involve a significant loss of precision in voltage readings?
In other words, an external voltmeter is a must in such a case?

mkwired

You can measure AREF indirectly by measuring the internal voltage reference.  This can be done by applying a known voltage to AREF and measure internal voltage reference.  This will tell you the voltage of the internal voltage reference.  Store this value somewhere so that you can measure it again in the future and back calculate the voltage on AREF.  Vcc and AREF are connected through a low-pass filter.  There is no need for a voltage divider.

Go Up