We're trying to control an MG995 servo and a Johnson DC motor from Arduino at the same time. The DC motor is connected to a 6v (4xAA) battery supply and controlled by the Arduino with a transistor (like this: http://bildr.org/blog/wp-content/uploads/2011/03/tip120-solenoid.png ). The servo is connected to the Arduino's 5V and ground and controlled by a pin. We have common grounds.
When the Arduino is connected to the PC with a USB cable everything works fine. However if we supply the Arduino from an external battery the programme doesn't work properly or doesn't work at all. We tried a PP3 and two 4,5v batteries in series, none of them works. Seems like the servo is expecting more current or something like that. How could we make this thing work from an external supply?
Please help! Here's the code we used for a simple testing:
#include <Servo.h>
Servo myPointer;
int servoPin=3;
int dc=9;
void setup() {
myPointer.attach(servoPin);
pinMode (dc, OUTPUT);
}
void loop() {
myPointer.write(60); //Turn servo to 60 degrees
analogWrite(dc,255); //Turn on the DC motor
delay(2000); //Wait 2 secs
myPointer.write(120); //Turn the servo to 120 degrees
delay(2000); //Wait 2 secs
analogWrite(dc,0); //Turn off the DC motor
delay(2000);
}
The transistor is a TIP122 by the way, but we could use a MOSFET instead. Should we use another supply for the servo too? What should we connect to the Arduino to make this thing run? We would like to control a car with the motors, that's why we need to make it portable.