Servo works with USB not with battery

This will probably be a Homer Simpson "Duh" moment but I can't figure it out. I have the basic 2 wheel rover with an ultrasonic sensor mounted on a servo as a obstacle avoidance rover. It has a UNO with the Sensor Shield v5.0. This used to work, I pulled it out as part of a different project recently. There's a L298N motor driver. There are 6 AA batteries going into the L298N, I get 5V from the onboard regulator to power the Arduino.. Everything works except the servo when it is battery powered. If I have the USB plugged in the servo works. Under battery power the motors and ultrasonic work as does the sketch as when I put something in front of the ultrasonic the motors reverse direction.

I don't think it's a program or pin configuration issue, could be, as it works when both USB and battery on. So I won't include my sketch but here's the pin assignments.
// Pins
#define TRIG_PIN A4
#define ECHO_PIN A5

//Define all the connections maps to the L298N
#define enA 6
#define in1 7
#define in2 5
#define in3 4
#define in4 2
#define enB 3
#define servoPin 10
int speedSP = 200;

Why does the servo not work when just the battery is on?

Thanks
John

In the Arduino IDE, use Ctrl T or CMD T to format your code then copy the complete sketch.

Use the </> icon from the ‘reply menu’ to attach the copied sketch.


Show us a good schematic of your proposed circuit.
Show us a good image of your ‘actual’ wiring.
Give links to components.

It appears your batteries do not have the capability (current) for driving your configuration.When you post your schematic also post links to technical information on your hardware devices. The L298N motor driver is not very efficient, you lose almost 3 volts between the batteries and the motor.

@LarryD Typically I would include my sketch and schematic but as mentioned where everything worked as far if I had both power sources plugged in I felt they weren't needed.

@gilshultz I had thought about the battery, I figured this problem had something to do with that, so you made me go back and look at my original robot car. I knew I originally had just the 6 AA batteries so it had to be something else. I had used a different, smaller servo on that one. I swapped out the servo and it worked with battery power only.

Thanks to both of you for taking the time to reply and for your comments

Sorry, we would love to help, but no schematic + no code = no help.

Not because of any principles, only practicalities.

1 Like

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