I am building a car using an Arduino. I have a 11.2 V battery that I connect to my Arduino, but the servo's keep pausing in the after about one second (I am using FS90R continuous servo's) , and after another second they turn on again. If I connect the Arduino to my laptop, the servo's do turn continuously but move really slow. It is my first time using the Arduino, so I don't know things I can try.
#include <Servo.h>
#define LED_GROEN 4
#define LED_ROOD 2
#define LED_GEEL 3
Servo servolinks;
Servo servorechts;
// defines pins numbers
const int trigPin = 7;
const int echoPin = 5;
// defines variables
long afstand_ms;
int afstand_cm;
void setup()
{
servolinks.attach(9);
servorechts.attach(10);
servolinks.write(0);
servorechts.write(180);
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Inputer
Serial.begin(9600); // Starts the serial communication
pinMode(LED_GROEN, OUTPUT);
pinMode(LED_ROOD, OUTPUT);
pinMode(LED_GEEL, OUTPUT);
}
void loop()
{
digitalWrite(LED_GROEN, LOW);
digitalWrite(LED_GEEL, LOW);
digitalWrite(LED_ROOD, LOW);
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(2);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
afstand_ms = pulseIn(echoPin, HIGH);
// Calculating the distance
afstand_cm = (afstand_ms * 0.034) / 2;
//
if (afstand_cm < 20)
{
digitalWrite(LED_ROOD, HIGH);
servolinks.write(60);
servorechts.write(60);
}
else if (afstand_cm < 50)
{
digitalWrite(LED_GEEL, HIGH);
servolinks.write(60);
servorechts.write(120);
}
else if (afstand_cm < 100)
{
digitalWrite(LED_GROEN, HIGH);
servolinks.write(0);
servorechts.write(135);
}
else
{
servolinks.write(0);
servorechts.write(150);
}
}

