if(distance<500)
{
int motor_speed=255*0; // must be >0 and <= 255
analogWrite( motorpin1, motor_speed);
}
else if(distance>=500)
{
int motor_speed=100; // must be >0 and <= 255
analogWrite( motorpin1, motor_speed);
}
else
{
delay(5000);
}
Crappy indentation aside, under what circumstances will the else block ever be executed?
I don't understand leaving lots of white space between lines and then jamming everything together on the lines you do have. Spaces before and after the = sign, for instance, make the code a lot easier to read.
The Tools + Auto Format menu item will fix the crappy indenting, too.