Problem solved many thanks
It turns out that it was the change in dorection that cause the problem, like an overflow from HIGH-LOW.
I turn off the motors before a change in direction and it works.
Thank you again for the help in debugging. Now the program of the robot works
Donald
// Motor A
int minspeed = 200;
int enA = 8;
int in1 = 6;
int in2 = 7;
// Motor B
int enB = 10;
int in3 = 12;
int in4 = 11;
void setup()
{
Serial.begin(9600);
// Set all the motor control pins to outputs
pinMode(enA, OUTPUT);
pinMode(enB, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
}
void demoOne()
{
// This function will run the motors in both directions at a fixed speed
// SET FORWARD
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
// Turn on motor A and B
analogWrite(enA, minspeed);
analogWrite(enB, minspeed);
Serial.println("Forward ... HIGH-LOW ...");
delay(500);
// stop motors
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
delay(50);
// Now change motor directions
Serial.println("Reverse ... HIGH-LOW ...");
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
// Turn on motor A and B
analogWrite(enA, minspeed);
analogWrite(enB, minspeed);
delay(500);
// Now turn off motors
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
}
void demoTwo()
{
// This function will run the motors across the range of possible speeds
// Note that maximum speed is determined by the motor itself and the operating voltage
// Turn on motors
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
// Accelerate from zero to maximum speed
for (int i = 150; i < 255; i++)
{
analogWrite(enA, i);
analogWrite(enB, i);
Serial.print("Speed at : ");Serial.println(i);
delay(10);
}
// Decelerate from maximum speed to zero
for (int i = 255; i >= 150; --i)
{
analogWrite(enA, i);
analogWrite(enB, i);
delay(10);
}
// Now turn off motors
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
}
void loop()
{
//demoTwo();
//delay(1000);
demoOne();
Serial.println("Demo One done...");
delay(100);
}