The distance is not working

i programed this : int trigPin = 9;
int echoPin = 8;

float duration_us, distance_cm;

void setup() {

Serial.begin (9600);

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);
}

void loop() {

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

pulseIn(echoPin, HIGH);

Serial.print("distance: ");
Serial.print(distance_cm);
Serial.println(" cm");

delay(200);
}
And is working but the serial monitos tells me the distance is 0.00 cm
HELP

  1. Read the forum guide in the sticky post at the top of the forum section to find out how to post code correctly.
  2. Go back to the example sketch and figure out what you missed out in your code.

Where are you setting distance_cm ?

The posting is not working.

(Read about code tags).

i dont have time for code tags im in school project in com lab

That's ok, we can wait.

2 Likes

It took you longer to post this reply than it would have to add the code tags.

I hope you've got plenty of time, because without those and with this attitude you're going to be waiting a while.

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