I Have No Idea How To Fix This Error, Please Help

I'm new to arduino so I don't know how to deal with every error. I use Arduino Uno.

The Error:

/tmp/644737659/Ultrasound_Sensor_mar9a/Ultrasound_Sensor_mar9a.ino:6:20: error: expected initializer before 'setup'

const int Echo = 9;

^

/tmp/644737659/Ultrasound_Sensor_mar9a/Ultrasound_Sensor_mar9a.ino:9:1: error: expected initializer before 'void'

void setup() {

^~~~

/tmp/644737659/Ultrasound_Sensor_mar9a/Ultrasound_Sensor_mar9a.ino: In function 'void loop()':

/tmp/644737659/Ultrasound_Sensor_mar9a/Ultrasound_Sensor_mar9a.ino:25:5: error: 'distance' was not declared in this scope

distance = pulseIn(Echo, HIGH) / 58.00;

^~~~~~~~

/tmp/644737659/Ultrasound_Sensor_mar9a/Ultrasound_Sensor_mar9a.ino:25:5: note: suggested alternative: 'isSpace'

distance = pulseIn(Echo, HIGH) / 58.00;

^~~~~~~~

isSpace

Error during build: exit status 1

my code:

const int Trig = 8;
const int Echo = 9;
float distance

void setup() {
    Serial.begin(9600);
    pinMode(Trig, OUTPUT);
    pinMode(Echo, INPUT);
    Serial.println("Ultrasound Sensor:");
}

void loop() {
    digitalWrite(Trig, LOW);
    delayMicroseconds(2);
    digitalWrite(Trig, HIGH);
    delayMicroseconds(10);
    digitalWrite(Trig, LOW);
    distance = pulseIn(Echo, HIGH) / 58.00;
    Serial.print(distance);
    Serial.print("cm");
    Serial.println();
    delay(1000);
}

Start off by posting your code in code tags.

Read the forum guidelines to see how to properly post code and some information on how to get the most from this forum.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

If you are new to this Forum (and you are), you'll find that doing what @groundFungus suggested can make the difference between getting quickly the help you need and taking too long to get it ...or not getting it at all

Do you have the word "setup" between line 6 and line 9?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.