Problem with sensors and servos


I make a line tracking car. I use two continuous servos and 5 line tracking sensors. My big problem is that the servos dont work proparly with my sensors. My sensors detect the line but the servos still keep running forward…

#include <Servo.h>

Servo leftServo; //creats left servo object
Servo rightServo;
int s1Left = 2;
int s2Left = 4;
int s3Center = 7;
int s4Right = 8;
int s5Right = 12;
void setup() {
        pinMode (s1Left,INPUT);// Lezen van de waardes
        pinMode (s2Left, INPUT);
        pinMode (s3Center, INPUT);
        pinMode (s4Right, INPUT);  
		pinMode (s5Right, INPUT);
void loop() {
        if ((digitalRead(s1Left) == LOW) && (digitalRead(s2Left) == LOW) && (digitalRead(s3Center) == HIGH) && (digitalRead(s4Right) == LOW) && (digitalRead(s5Right) == LOW))  { //rechts hard  


Servo test code you can use to find the actual servo value that stops the servos if that is the issue.

// zoomkat 10-22-11 serial servo test
// type servo position 0 to 180 in serial monitor
// or for writeMicroseconds, use a value like 1500
// for IDE 0022 and later
// Powering a servo from the arduino usually *DOES NOT WORK*.

String readString;
#include <Servo.h> 
Servo myservo;  // create servo object to control a servo 

void setup() {
  myservo.writeMicroseconds(1500); //set initial servo position if desired
  myservo.attach(7);  //the pin for the servo control 
  Serial.println("servo-test-22-dual-input"); // so I can keep track of what is loaded

void loop() {
  while (Serial.available()) {
    char c =;  //gets one byte from serial buffer
    readString += c; //makes the string readString
    delay(2);  //slow looping to allow buffer to fill with next character

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured string 
    int n = readString.toInt();  //convert readString into a number

    // auto select appropriate value, copied from someone elses code.
    if(n >= 500)
      Serial.print("writing Microseconds: ");
      Serial.print("writing Angle: ");

    readString=""; //empty for next input

I see code trying to stop the servos, but I don't spot any code to start them. Have you tested the servos to see what values you need to set them to for forwards, stop, reverse?

Once you know how to drive the servos, I suggest you add Serial.println() to tell you whether those sensor conditions are actually being met.

ok thanks i have seen my problem, i had a potentiometer on my servo ;/

To calibrate a continous rotation servo that still has a pot, send a 1500us position to the servo and then tweek the pot until the servo stops rotating.

Thank you. I have done it and its working :)