Doesn't work when powering from the barrel

Hello everyone, I'm trying to run this very simple code, just a servomotor controlled with a potentiometer:

#include <Servo.h>  // add servo library
 
Servo myservo;  // create servo object to control a servo
 
int potpin = 0;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin
 
void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}
 
void loop() {
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  val = map(val, 0, 1023, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
  myservo.write(val);                  // sets the servo position according to the scaled value
  delay(15);                           // waits for the servo to get there
}

Everything worked perfectly powered with the USB B.

But then i tried using a 5v power supply through the barrel connector.
At that point the board worked but after a few seconds the servomotor stopped responding to the potentiometer and made little sounds as if it wanted to move but it was stucked.

I then changed the power supply again, using a 12v (always through the barrel). It did the same exact thing as with the 5V, but then i got 3 board leds on (instead of the 2 that were on up to this point) (see pic) and now it's impossible to upload anything.

I'm using a very cheap board, is it possible that i broke it?
Do you know the meaning of the third led turned on?
And even before this point, how is it possible that the servo wasn't responding correctly with the different power method?

Thank you a lot in advance if you have any input for me!
Carlo

That is where you are going wrong. You need to supply the barrel connection with a minimum of 7V up to 12V.
This is because power from that goes through a diode (loose 0.7V) and then into a regulator. That needs more than it outs out.

Also the current you can draw from the 5V pin when powering it this way is limited to about 100 mA due to the poor thermal dissipation of the regulator.

1 Like

Yep that's why i changed to 12v hoping that that would be the solution, but the problem was the same (and even worse since now it looks like it can't upload anything).

Regarding the current that is possible to draw, the servomotor should go from 20mA to 100mA (i read with also peaks of 300mA), but it should be a problem that it is asking more than Arduino can provide right? At the beginning with the usb B it was working perfectly :confused:

That's the error message:

Arduino: 1.8.10 (Windows 10), Board: "Arduino Uno"

C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\Carlo\AppData\Local\Arduino15\packages -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\Carlo\AppData\Local\Arduino15\packages -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\Carlo\Documents\Arduino\libraries -fqbn=arduino:avr:uno -vid-pid=1A86_7523 -ide-version=10810 -build-path C:\Users\Carlo\AppData\Local\Temp\arduino_build_140257 -warnings=none -build-cache C:\Users\Carlo\AppData\Local\Temp\arduino_cache_969257 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avrdude.path=C:\Users\Carlo\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17 -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Users\Carlo\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17 -prefs=runtime.tools.avr-gcc.path=C:\Users\Carlo\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Users\Carlo\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.arduinoOTA.path=C:\Users\Carlo\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.3.0 -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Users\Carlo\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.3.0 -verbose C:\Users\Carlo\AppData\Local\Temp\untitled1330819492.tmp\sketch_mar07a\sketch_mar07a.ino
C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\Carlo\AppData\Local\Arduino15\packages -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\Carlo\AppData\Local\Arduino15\packages -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\Carlo\Documents\Arduino\libraries -fqbn=arduino:avr:uno -vid-pid=1A86_7523 -ide-version=10810 -build-path C:\Users\Carlo\AppData\Local\Temp\arduino_build_140257 -warnings=none -build-cache C:\Users\Carlo\AppData\Local\Temp\arduino_cache_969257 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avrdude.path=C:\Users\Carlo\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17 -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Users\Carlo\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17 -prefs=runtime.tools.avr-gcc.path=C:\Users\Carlo\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Users\Carlo\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.arduinoOTA.path=C:\Users\Carlo\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.3.0 -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Users\Carlo\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.3.0 -verbose C:\Users\Carlo\AppData\Local\Temp\untitled1330819492.tmp\sketch_mar07a\sketch_mar07a.ino
Using board 'uno' from platform in folder: C:\Users\Carlo\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.3
Using core 'arduino' from platform in folder: C:\Users\Carlo\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.3
Detecting libraries used...
"C:\Users\Carlo\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10810 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Users\Carlo\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.3\cores\arduino" "-IC:\Users\Carlo\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.3\variants\standard" "C:\Users\Carlo\AppData\Local\Temp\arduino_build_140257\sketch\sketch_mar07a.ino.cpp" -o nul
Generating function prototypes...
"C:\Users\Carlo\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10810 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Users\Carlo\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.3\cores\arduino" "-IC:\Users\Carlo\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.3\variants\standard" "C:\Users\Carlo\AppData\Local\Temp\arduino_build_140257\sketch\sketch_mar07a.ino.cpp" -o "C:\Users\Carlo\AppData\Local\Temp\arduino_build_140257\preproc\ctags_target_for_gcc_minus_e.cpp"
"C:\Program Files (x86)\Arduino\tools-builder\ctags\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\Users\Carlo\AppData\Local\Temp\arduino_build_140257\preproc\ctags_target_for_gcc_minus_e.cpp"
Compiling sketch...
"C:\Users\Carlo\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10810 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Users\Carlo\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.3\cores\arduino" "-IC:\Users\Carlo\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.3\variants\standard" "C:\Users\Carlo\AppData\Local\Temp\arduino_build_140257\sketch\sketch_mar07a.ino.cpp" -o "C:\Users\Carlo\AppData\Local\Temp\arduino_build_140257\sketch\sketch_mar07a.ino.cpp.o"
Compiling libraries...
Compiling core...
Using precompiled core: C:\Users\Carlo\AppData\Local\Temp\arduino_cache_969257\core\core_arduino_avr_uno_4e26c2eb007148dcb27998e0f15a79db.a
Linking everything together...
"C:\Users\Carlo\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-gcc" -w -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega328p -o "C:\Users\Carlo\AppData\Local\Temp\arduino_build_140257/sketch_mar07a.ino.elf" "C:\Users\Carlo\AppData\Local\Temp\arduino_build_140257\sketch\sketch_mar07a.ino.cpp.o" "C:\Users\Carlo\AppData\Local\Temp\arduino_build_140257/..\arduino_cache_969257\core\core_arduino_avr_uno_4e26c2eb007148dcb27998e0f15a79db.a" "-LC:\Users\Carlo\AppData\Local\Temp\arduino_build_140257" -lm
"C:\Users\Carlo\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-objcopy" -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 "C:\Users\Carlo\AppData\Local\Temp\arduino_build_140257/sketch_mar07a.ino.elf" "C:\Users\Carlo\AppData\Local\Temp\arduino_build_140257/sketch_mar07a.ino.eep"
"C:\Users\Carlo\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-objcopy" -O ihex -R .eeprom "C:\Users\Carlo\AppData\Local\Temp\arduino_build_140257/sketch_mar07a.ino.elf" "C:\Users\Carlo\AppData\Local\Temp\arduino_build_140257/sketch_mar07a.ino.hex"
"C:\Users\Carlo\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-size" -A "C:\Users\Carlo\AppData\Local\Temp\arduino_build_140257/sketch_mar07a.ino.elf"
Sketch uses 444 bytes (1%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
An error occurred while uploading the sketch

Is that with the power from the USB and nothing connected to the barrel?
If so you could have broken it. Even powering from the USB is too much current for the 5V pin when driving one servo, let alone more.

1 Like

I'm not sure I understand your question. I've used the usb B initially, but then both the 5v and 12v had been supplied through the barrel connector

Edit: now i got it it think. The 3 leds are on even with only the usb B connected and nothing else, as shown in the picture in the first message

Wrong. Asking the Arduino to supply more current than it can will damage something. A servo motor can peek at 1A.

1 Like

So is it correct that i could then power the servomotor externally and connect to the arduino only the signal cable?

1 Like

Correct, but you also have to connect the ground of the Arduino to the ground of this external supply as well.

1 Like

Great. But could that explain why the motor was behaving wrongly?

Even after this consideration, the fact that now i can't upload anything is something fixable?

If you draw too much current from an Arduino (or any other electronic device) the voltage from that device drops. If the voltage drops to the servo this affects the electronics inside the servo and so it readjusts itself to compensate. So it twitches.

Also there is not a one to one relationship between the pulse signal you give a servo and its position. Each has its own tolerances. Noise (very small changes in voltages) on the system can leave the servo not exactly in the right position and the servo makes a chattering noise as it hunts for the correct position. This is normal and is how servos work. So at some angles you might get twitching and at others nothing.

1 Like

Thank you so much for the detailed explanation!

I don't understand why It was working perfectly using the USB B supply and not with the barrel. In both cases the servo was drawing directly from the board

When things are wrong they don't always go "puff" immediately. Sometimes if it is just marginally wrong they can work for a time and then fail.

The time between being put in a stressed position, and when it fails, increases the less it is abused. In effect the lifetime or time to failure is increased. This is what results in so many bad tutorials on the internet. Some one gets something "working" writes an Instructable (other crap sites are available) and goes onto the next one. They never get to see it fail. Also they think that if a device functions then everything is fine. They never check the waveform on a design for signs of trouble, hence lots of designs for I2C circuits with no pull up resistors.

Professional engineers spend more time studying the design and the component's data sheets to make sure no rating on each device is being exceeded.

Even then a product needs testing to make sure it is going to last the design time. This is not just one sample but typically could be 50 to 100 samples. This is done at high temperature because for every 10˚C hotter you run a product the lifetime typically halves. Then when ever a device fails it is examined to find out what component failed. Then they concentrate on that part.

1 Like

Yep i get what you are saying.
Should I connect also the potentiometer to an external power supply just to be safe?

The reason here is, the USB power supply can supply more current than the poor little regulator on the Arduino, and when the USB is connected the USB power bypasses that regulator. So with USB plugged in, you're running your servo with USB 5V, not Arduino-regulator 5V.
That, by the way, can be hard on your USB output, though they're generally pretty well protected internally, so it's hard to kill them. Depending on the servo, stall currents can exceed 1 Ampere, even for the little SG90 servos, so using an external 5V supply is a wise move.

No I wouldn't bother. I am assuming that they are between 10K and 100K.

1 Like

Thank you a lot!! I will try as you told me :slight_smile:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.