2 DC Motor with H-Bridge Interference with Servo Motor

Hi,
I have two DC Motor connect with H-Brdige, and powered with a 9V Battery, and then a Servo Motor powered via arduino, powered via USB, my problem is that with simple code:

#include <NewPing.h>
#include <HalfBridge.h>
#include <Servo.h>

const int SERVOPIN = 5;

#define FAST 200
#define SLOW 100
#define STOP 0

Motor motors[2] = { Motor(11, 12, 13), Motor(6, 7, 8) };
Servo myServo;

void setup()
{
  Serial.begin(115200);
  motors[0].init();
  motors[1].init();

  myServo.attach(SERVOPIN);
}

void loop()
{ 

motors[0].setSpeed(SLOW);
motors[1].setSpeed(SLOW);
}

the servo motor move with the DC Motor even if I do not write anything with the servo motor, and and it seems that it moves in the same direction of dc motors, also if i remove this line from the setup myServo.attach(SERVOPIN); do the same thing, the only to avoid this is remove the 5 PWM from the board. anyone can help me to solve this problem? i want use the servo motor and the dc motor separately without interference.

have two DC Motor connect with H-Brdige, and powered with a 9V Battery, and then a Servo Motor powered via arduino, powered via USB, my problem is that with simple code:

If the 9v battery is one of the small square PP3 types, it will quickly die trying to power motors. Also trying to power a servo from the arduino usually results in crashing the arduino due to under voltage. Motors and servos need separate external power supplies.

zoomkat:
If the 9v battery is one of the small square PP3 types, it will quickly die trying to power motors. Also trying to power a servo from the arduino usually results in crashing the arduino due to under voltage. Motors and servos need separate external power supplies.

thanks for your answer, so you think that the servo move without reason due to a power problem? so what you suggest to power the motors and the servo? it's a micro servo like this:

http://cdn.hobbyking.com/hobbyking/store/catalog/TG9e(1).jpg

The vast majority of issues associated with motors/servos is powering from the arduino or an inadequate power supply. Four or six rechargeable AA batteries would be the minimum battery power supply setup similar to below.

servo-wire.jpg

zoomkat:
The vast majority of issues associated with motors/servos is powering from the arduino or an inadequate power supply. Four or six rechargeable AA batteries would be the minimum battery power supply setup similar to below.

i have tried to power the servo with an external battery, 4x1.5V AA, but i have the same problem, i don't think it's a power supply problem...any other idea?

  1. Never power a motor or servo from Arduino's 5V line - its not going to work, it could
    destroy the Arduino and even the computer at the other end of the USB cable.

  2. Trust us, its likely a power supply issue.

Though its worth checking you haven't got a short between pin 5 and 6, thinking about
it a bit more...

MarkT:
Though its worth checking you haven't got a short between pin 5 and 6, thinking about
it a bit more...

Thank you for you answer, i have checked every single pin, i have also tried to switch the Pin 5 To Pin 3, and i have the same problem, i'm going crazy...any other idea?

no one can help me?

I believe I have a similar problem to Piero. When my motors on a little car/robot are spinning, my HC-SR04 distance sensor always reads zero. When I power the motors from battery while powering the Arduino from USB and the HC-SR04 the Arduino's VCC pin, all is well.

Piero, you could narrow down where your issue is by doing as I have done. You'll want a common ground for the Arduino, motors, and servo, but try running the Arduino from USB power and everything else from the battery.

And you'll have to work out a better power source than a little 9V battery. That was part of my issue a few days ago. A 6xAA battery box populated by decent NiMH rechargeable batteries is a much better option, and much less expensive in the long run.

Hello,

I am building an obstacle avoidance robot using the Arduino UNO board. The robot consists of a pair of dc motors being driven using the L293D H-Bridge which has been functioning just fine for a line tracer robot project. I have added a HiTEC HS-422 servo motor (in parallel with a 100 micro farad decoupling capacitor) for the distance measurement part to be able to rotate the ping sensor to the left (~10 degrees) and right (~170 degrees).

Both DC motors and the servo have their own dedicated power source not to overload the Arduino power output and their grounds are connected to the common ground with the Arduino board (reported as a common mistake).

DC motors and the servo work just fine on their own as the robot goes forward and backward and turns right and left and servo passes the sweep test and moves nicely to any predefined angle. As I try to run the DC motors and the servo together, the servo turns to almost 0 degree and kind of twitches around 0 degree regardless of the predefined angle such as 90 or 170 degrees. I have tried the following scenarios and the following code for wiring the H-Bridge to overcome the problem but had no success:
First scenario:
Controlling the speed of the DC motors with a potentiometer and analogWrite(right_mot_Enable_Pin,Motor_Speed):
L293D-pin-1 connected to Arduino-pin- ~6
L293D-pin-2 connected to Arduino-pin- 8
L293D-pin-3 connected to left motor
L293D-pin-4 connected to common ground
L293D-pin-5 connected to common ground
L293D-pin-6 connected to left motor
L293D-pin-7 connected to Arduino-pin- ~10
L293D-pin-8 connected to + 9 V Battery

L293D-pin-9 connected to Arduino-pin- ~3
L293D-pin-10 connected to Arduino-pin- ~5
L293D-pin-11 connected to right motor
L293D-pin-12 connected to common ground
L293D-pin-13 connected to common ground
L293D-pin-14 connected to right motor
L293D-pin-15 connected to Arduino-pin- ~9
L293D-pin-16 connected to +5 V from Arduino

Servo-signal-pin connected to Arduino-pin- ~11

Second scenario:
No speed control on the DC motors:
L293D-pin-1 connected to +5 V from Arduino
L293D-pin-2 connected to Arduino-pin- ~5
L293D-pin-3 connected to left motor
L293D-pin-4 connected to common ground
L293D-pin-5 connected to common ground
L293D-pin-6 connected to left motor
L293D-pin-7 connected to Arduino-pin- ~6
L293D-pin-8 connected to + 9 V Battery

L293D-pin-9 connected to +5 V from Arduino
L293D-pin-10 connected to Arduino-pin- 8
L293D-pin-11 connected to right motor
L293D-pin-12 connected to common ground
L293D-pin-13 connected to common ground
L293D-pin-14 connected to right motor
L293D-pin-15 connected to Arduino-pin- ~9
L293D-pin-16 connected to +5 V from Arduino

Servo-signal-pin connected to Arduino-pin- 4

#include <Servo.h>

Servo myservo;
int Motor_Speed = 0;

const int left_mot_forward_Pin = 8; // Left Motor connected to digital pin 8
const int left_mot_backward_Pin = 10; // left Motor connected to digital pin 10
const int right_mot_forward_Pin = 9; // right Motor connected to digital pin 9
const int right_mot_backward_Pin = 5; // right Motor connected to digital pin 5
const int left_mot_Enable_Pin = 6; // Left Motor Enable Pin
const int right_mot_Enable_Pin = 3; // Right Motor Enable Pin
const int Pot_Pin = A3; // Pot Pin
void setup()
{
Serial.begin(9600);
Motor_Speed = map(analogRead(Pot_Pin), 0, 1023, 0, 255);
myservo.attach(11); // attaches the servo on pin 11 to the servo object
pinMode(left_mot_forward_Pin, OUTPUT); // Left Motor
pinMode(left_mot_backward_Pin, OUTPUT); // Left Motor
pinMode(right_mot_forward_Pin, OUTPUT); // Right Motor
pinMode(right_mot_backward_Pin, OUTPUT); // Right Motor
}

void loop()
{
myservo.write(90); //Rotate the servo to face the front
moveForward();

}
void moveForward() //This function tells the robot to go forward
{
digitalWrite(right_mot_forward_Pin, HIGH); //Right Motor Forward
digitalWrite(right_mot_backward_Pin, LOW); //Right Motor Backward
analogWrite(right_mot_Enable_Pin,Motor_Speed);

digitalWrite(left_mot_forward_Pin, HIGH); //Left Motor Forward
digitalWrite(left_mot_backward_Pin, LOW); //Left Motor Backward
analogWrite(left_mot_Enable_Pin,Motor_Speed);
}

Measure the supply voltage(s) with the system operating - are any of them dipping significantly (more
than 0.25V say)?

If you have an oscilloscope you can see what really happening in terms of short-duration drop-outs and
spikes.

Budget a minimum of 1A per servo and the full stall current of the motors (unless you are ramping
their speed using PWM). Something like a LiPo or SLA battery is normally used for robotics to ensure
enough current for the peak demands of motors and servos.

If you use AA batteries use quality branded batteries, perferably high-capacity rechargables,
especially look out for ones labelled as for high-current drain.

Avoid budget batteries at all costs.

I am building an obstacle avoidance robot using the Arduino UNO board.

Probably best to start a new discussion of your project using #7 below:

http://forum.arduino.cc/index.php/topic,148850.0.html

What others said about battery issues is likely to be true, but the problems you described were very similar to my own.

I had a two DC motors and two servos receiving serial data over xbee as part of my robot.

However I found the two couldn't operate together since they seemed to interfere with each other.

What I discovered was that the new Servo.h library in Arduino uses interrupt-based technology instead of PWM as I thought it did.

This can cause conflict when you're using serial.

Instead I reverted to using the old PWMServo.h library and this solved my problems. Just realise though that the library only works for two servos and only on pins 9 & 10.

You can find out more about this here