@UKHeliBob
Not only that, but look at his microsecondsToCentimeters function.
Something in here is not right either.
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();
What does this do?
for(int i = 0; i < avgrange ; i++)
{
anVolt = analogRead(maxsonar)/2;
sum += anVolt;
delay(10);
}inches = sum/avgrange;
cm2 = inches * 2.54;sum = 0;
Im guessing this is his attempt at PWM.
if (cm2>30,cm>30 )
{
digitalWrite(moteur,HIGH);
delay(1000);
digitalWrite(moteur,LOW);
delay(500);
digitalWrite(moteur,HIGH);
delay(1000);
digitalWrite(moteur,LOW);
delay(500);
digitalWrite(moteur,HIGH);
delay(1000);
digitalWrite(moteur,LOW);
delay(500);
}
Right now, this code is not going to work at all, at least not the way he wants it to.