Error code 357 273 277

My code is not working and gives me the error message 357,273,277 i looked at other post but didn't understand. I copied it from some website. Here is my code :

const int trigPin = 9;
const int echoPin = 10;
const int Motor = 11;
const int buzzer = 13;
long duration;
int distance;
int safetyDistance;

void setup()
{
    pinMode(buzzer, OUTPUT);
    pinMode(Motor, OUTPUT);
    pinMode(trigPin, OUTPUT);
    pinMode(echoPin, INPUT);
    Serial.begin(9600);
}

void loop()
{
dos();
}
void dos()
{
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);

    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);

    duration = pulseIn(echoPin, HIGH);

    distance = duration * 0.034 / 2;

    safetyDistance = distance;
    if (safetyDistance <= 5)
    {
        digitalWrite(buzzer, HIGH);
        digitalWrite(Motor, HIGH);
    }
    else
    {
        digitalWrite(buzzer, LOW);
        digitalWrite(Motor, LOW);
    }

    Serial.print("Distance: ");
    Serial.println(distance);
}

here is the error message:

#########_02_btnAndLed01_02_btnAndLed01.ino:1:1: error: stray '\357' in program
const int trigPin = 9;
^
#########_02_btnAndLed01_02_btnAndLed01.ino:1:2: error: stray '\273' in program
const int trigPin = 9;
^
#########_02_btnAndLed01_02_btnAndLed01.ino:1:3: error: stray '\277' in program
const int trigPin = 9;
^

exit status 1

Compilation error: stray '\357' in program

Such error is a result of incorrect copying the code from the website. There are HTML codes in the program text.
Try to copy it as text or using a "copy code" button, if available

Two tiny icons appear in the top left of a <CODE/> section when the mouse is over it; the one on the left does Copy All. If you click it, it switches briefly to say copied!

I then created a new sketch in the IDE and replaced the empty setup and loop by pasting. Your code compiled fine.

As explained earlier in the thread, somehow a Byte Order Mark got tacked onto the beginning of the file. The question is why. How did you start that sketch? Did you copy the code from somewhere? What OS are you using? Which browser?

The BOM is lost when copying the text from the file, which I'm guessing you did to paste it here (instead of hand-typing it manually).

Hi, @coder_man_125

If you do a copy and paste from your posting of your code, I think you will find it compiles.
Doing the posting into code tags appears to have washed all the extraneous code away.
Use the copy tab to copy from your post.

Tom.. :smiley: :+1: :coffee: :australia:

1 Like

ok it is working again now . i understood the propblem and edit the code a little bit and it started working. thanks :smile: