Hello, I'm working on a project with some students building a simple robot with an arduino and two small continuous rotation servos.
The first sketch we created simply ran the servos for one second and then paused for one second (robot moves forward and then pauses). We subsequently tried a second sketch that drove forward two seconds and then moved the servos in opposite directions to turn the robot. When connected via usb we can upload and run the second sketch, but when we revert to external power using a 9V battery, the first sketch runs.
We can make the robot do anything we want via usb, but it always reverts to the 1 s forward and 1 s pause when running from the battery.
Could the programmer be an issue? I had been working with some students on another project and had "Arduino as ISP" set as the programmer, then changed it as we were working on the new project (I don't recall when in the sequence).
Our circuit: 9V battery provides external power to the arduino. Two servos are connected to the 5 V power supply on the arduino and controlled via pins 9 and 10.
First sketch:
#include <Servo.h>
Servo john1;
Servo john2;
void setup() {
john1.attach(9);
john2.attach(10);
}
void loop() {
john1.write(180);
john2.write(0);
delay(1000);
john1.write(90);
john2.write(90);
}
The second sketch is identical except:
void loop() {
john1.write(180);
john2.write(0);
delay(3000);
john1.write(90);
john2.write(90);
delay(1000);
john1.write(180);
john2.write(180);
delay(1000);
john1.write(90);
john2.write(90);
delay(1000);
john1.write(0);
john2.write(0);
delay(1000);