0

I just don't know how to describe this. It was working, but then I changed the value of distance = duration*0.034/2;. I then changed it back but it still gave me these errors. Is it the Arduino? (Bluno nano) Is it the code?

const int trigPin = 9;
const int echoPin = 10;
int duration;
int distance;

void setup(){
  Serial.begin(9600);

  pinMode(echoPin, INPUT);
  pinMode(trigPin, OUTPUT);
}

void loop(){
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  duration = pulseIn(echoPin, HIGH);
  distance = duration*0.034/2;

  Serial.print("Distance: " + distance);
  delay(500);
}

gre_gor
  • 6,669
  • 9
  • 47
  • 52
mudbed
  • 11
  • 2

1 Answers1

0

You can't concatenate c-strings with a + operator.

You should print each part separately.

Serial.print("Distance: ");
Serial.println(distance);
gre_gor
  • 6,669
  • 9
  • 47
  • 52