#include Servo myservodx; Servo myservosx; void setup() { Serial.begin(9600); myservodx.attach(9); myservosx.attach(10); } void loop() { int val; val=analogRead(0); //connect grayscale sensor to Analog 0 Serial.println(val,DEC);//print the value to serial delay(100); // wait 0.1 s if (val > 850) { // in this case the light is large enough: we abandoned // the black line myservodx.write(86); myservosx.write(100); } else { // go forward (the two values differs depending on the // friction between the wheel and the floor. The two motors // must move in opposite directions because they are mounted // back to back. myservodx.write(100); myservosx.write(86); // wait 5 s delay(5000); // stop (writing 90 to servomotors they stop) myservodx.write(90); myservosx.write(90); } }