Power issues

Hello, I made a robot with some easy code:

#define IN1 3
#define IN2 5
#define IN3 6
#define IN4 9
#define ENABLE_A 2
#define ENABLE_B 13
#define trigpin 7
#define echopin 8
#define trigpin2 10
#define echopin2 11
#define MAX_DISTANCE 154
#include <Servo.h> 
 
Servo myservo;  // create servo object to control a servo 
                // twelve servo objects can be created on most boards
 

void setup() {
   Serial.begin(115200);
    pinMode(trigpin, OUTPUT);
    pinMode(echopin, INPUT);
    pinMode(trigpin2, OUTPUT);
    pinMode(echopin2, INPUT);
    pinMode(ENABLE_A, OUTPUT);
    pinMode(ENABLE_B, OUTPUT);
    pinMode(IN1,OUTPUT);
    pinMode(IN2,OUTPUT);
    pinMode(IN3,OUTPUT);
    pinMode(IN4,OUTPUT);
    myservo.attach(12); 
    myservo.write(0); 
}
void loop() {  
long duration, distance;  
digitalWrite(trigpin, LOW);
delayMicroseconds(2);
digitalWrite(trigpin, HIGH);
delayMicroseconds(10);
digitalWrite(trigpin,LOW);
duration = pulseIn(echopin, HIGH);
distance = (duration/2)/29.1;

if (distance < 8){
    digitalWrite(ENABLE_A, HIGH);
    digitalWrite(ENABLE_B, HIGH);
    digitalWrite(IN1, LOW);
    digitalWrite(IN2, HIGH);
    digitalWrite(IN3, LOW);
    digitalWrite(IN4, HIGH);
    myservo.write(60); 
    }
else {
    digitalWrite(ENABLE_A, HIGH);
    digitalWrite(ENABLE_B, HIGH);
    analogWrite(IN1, 125);
    analogWrite(IN2, 0);
    analogWrite(IN3, 125);
    analogWrite(IN4, 0);
    myservo.write(0); 
   
}

}

It works good when attached to my PC + powered by 6 AA batteries. However when I detach the PC it doesn't work anymore. It goes in shocks and I think it still responds but just really slow so it's not like it should anymore.
Any ideas on what's causing this issue? So yes, how can I fix it?
Thanks in advance,
Charles

Any ideas on what's causing this issue?

My guess is dead batteries.

PaulS:
My guess is dead batteries.

Fully charged, I'll try other batteries. Maybe it can be caused by maybe bad quality batteries?

Check the onboard voltage regulator to see if it's getting hot.

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Showing how you are powering the arduino and other accessories.

Thanks.. Tom.... :slight_smile:

TomGeorge:
Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Showing how you are powering the arduino and other accessories.

Thanks.. Tom.... :slight_smile:

I made this a while ago, not sure if it can help you...
Imgur

And here is a picture of the robot itself (battery pack is mounted on the bottom)
Imgur

You appear to have two regulators in tandem which is inefficient in itself, but worse given that the linear regulator in the Arduino UNO is one.

If you want to operate from a 9 V battery, you need to use a switchmode "buck converter" to generate the Arduino 5 V directly. Do not use series regulators (such as the one in the Arduino) with batteries.

Hi,
Do I count 4 motors and a servo?
Have you a DMM?
Measure the battery volts while the robot is malfunctioning.

Tom.... :slight_smile:

Paul__B:
You appear to have two regulators in tandem which is inefficient in itself, but worse given that the linear regulator in the Arduino UNO is one.

If you want to operate from a 9 V battery, you need to use a switchmode "buck converter" to generate the Arduino 5 V directly. Do not use series regulators (such as the one in the Arduino) with batteries.

Hey, thanks for your response.
The robot has actually worked before with this setup. It are just operations involving the distance sensor and servo in combination that are causing problems...

TomGeorge:
Hi,
Do I count 4 motors and a servo?
Have you a DMM?
Measure the battery volts while the robot is malfunctioning.

Tom.... :slight_smile:

Hey
I'll have to borrow one from school. I'll do some tests when I get my hands on it.
Thanks, Charles