error

#define TRIG_PIN 10
#define ECHO_PIN 9
#define BUZZ_PIN 8

void setup() {
Serial.begin(9600);
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
digitalWrite(TRIG_PIN, LOW);
}

void loop() {
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(20);
digitalWrite(TRIG_PIN, LOW);

unsigned long tempo = pulseIn(ECHO_PIN, HIGH);
float distanza = 0.03438 * tempo / 2;

Serial.println("distanza: " + String(distanza) + "cm");
delay(20);

;if(String‹(30)+"cm")
;else digitalWrite(BUZZ_PIN, HIGH)
;if(String›(30)+"cm")
;else digitalWrite(BUZZ_PIN, LOW)

;}

/home/builder/opt/arduino-builder/arduino-builder -compile -core-api-version 10611 -hardware /home/builder/opt/arduino-builder/hardware -hardware /home/builder/.arduino15/packages -tools /home/builder/opt/arduino-builder/tools -tools /home/builder/.arduino15/packages -built-in-libraries /home/builder/opt/libraries/latest -logger humantags -fqbn arduino:avr:uno -build-cache /tmp -build-path /tmp/366925234/build -verbose -prefs runtime.tools.arduino101load.path=/home/builder/.arduino15/packages/Intel/tools/arduino101load/2.0.1 -prefs runtime.tools.dfu-util.path=/home/builder/.arduino15/packages/arduino/tools/dfu-util/0.9.0-arduino1 -prefs runtime.tools.avrdude.path=/home/builder/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino14 -prefs runtime.tools.sketchUploader.path=/home/builder/.arduino15/packages/Intel/tools/sketchUploader/1.6.2+1.0 -prefs runtime.tools.arc-elf32.path=/home/builder/.arduino15/packages/Intel/tools/arc-elf32/1.6.9+1.0.1 -prefs runtime.tools.linuxuploader.path=/home/builder/.arduino15/packages/arduino/tools/linuxuploader/1.5.1 -prefs runtime.tools.arm-linux-gcc.path=/home/builder/.arduino15/packages/arduino/tools/arm-linux-gcc/4.9.3 -prefs runtime.tools.x86-linux-gcc.path=/home/builder/.arduino15/packages/arduino/tools/x86-linux-gcc/7.2.0 -prefs runtime.tools.avr-gcc.path=/home/builder/.arduino15/packages/arduino/tools/avr-gcc/5.4.0-atmel3.6.1-arduino2 -prefs runtime.tools.openocd.path=/home/builder/.arduino15/packages/arduino/tools/openocd/0.10.0-arduino7 -prefs runtime.tools.arm-none-eabi-gcc.path=/home/builder/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4 -prefs runtime.tools.bossac.path=/home/builder/.arduino15/packages/arduino/tools/bossac/1.7.0 -prefs runtime.tools.arduinoOTA.path=/home/builder/.arduino15/packages/arduino/tools/arduinoOTA/1.2.1 -prefs runtime.tools.flashpack.path=/home/builder/.arduino15/packages/Intel/tools/flashpack/2.0.0 -prefs runtime.tools.mkspiffs.path=/home/builder/.arduino15/packages/esp8266/tools/mkspiffs/2.5.0-3-20ed2b9 -prefs runtime.tools.esptool.path=/home/builder/.arduino15/packages/esp8266/tools/esptool/2.5.0-3-20ed2b9 -prefs runtime.tools.xtensa-lx106-elf-gcc.path=/home/builder/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-3-20ed2b9 -prefs runtime.tools.CMSIS.path=/home/builder/.arduino15/packages/arduino/tools/CMSIS/4.5.0 -prefs runtime.tools.nrf5x-cl-tools.path=/home/builder/.arduino15/packages/arduino/tools/nrf5x-cl-tools/9.3.1 -prefs runtime.tools.CMSIS-Atmel.path=/home/builder/.arduino15/packages/arduino/tools/CMSIS-Atmel/1.2.0 -prefs runtime.tools.i586-poky-linux-uclibc.path=/home/builder/.arduino15/packages/Intel/tools/i586-poky-linux-uclibc/1.6.2+1.0 -prefs runtime.tools.core2-32-poky-linux.path=/home/builder/.arduino15/packages/Intel/tools/core2-32-poky-linux/1.6.2+1.0 -libraries /tmp/366925234/custom -libraries /tmp/366925234/pinned /tmp/366925234/sketch_jan26a

Compiling sketch...

/tmp/366925234/sketch_jan26a/sketch_jan26a.ino:24:3: error: stray '\342' in program

/tmp/366925234/sketch_jan26a/sketch_jan26a.ino:24:3: error: stray '\200' in program

/tmp/366925234/sketch_jan26a/sketch_jan26a.ino:24:3: error: stray '\271' in program

/tmp/366925234/sketch_jan26a/sketch_jan26a.ino:26:3: error: stray '\342' in program

/tmp/366925234/sketch_jan26a/sketch_jan26a.ino:26:3: error: stray '\200' in program

/tmp/366925234/sketch_jan26a/sketch_jan26a.ino:26:3: error: stray '\272' in program

exit status 1

i want to do a sketch to do an alarm with the distnce sensor "HC-SR04" and un buzzer...but what are all this errors?i'm new on arduino.

Hi, welcome to the forum. Please add code tags to your post (to both the code and the error. See "How to use the forum".

Multiple things wrong with your code.

  ;if(String‹(30)+"cm")

Why do you all of a sudden thing you need to add the ; in front?

And what is "String‹(30)+"cm"" suppose to mean? If you want to check the distance, that is stored in 'distanza'.

And you have an if without code. It's like saying to you "If the coffee is fresh, otherwise throw it out." What should I do with the fresh coffee?

Also a tip, drop the use of String completely! No need for it.

This type of problem

stray '\342' in program

is usually caused by copy-and-paste which has included strange characters into the code. Perhaps you have copied from a word-processor document?

Copy the code into a simple text editor - such as Notepad or Geany - and save it from there and that should get rid of the wrong characters. Otherwise, type the program into the Arduino editor yourself.

...R

i have used a sketch recupered on internet (until "delay(20)") and i have write the other part alone...i have write ;if beacause on the arduino web editor said:"/tmp/303062896/sketch_jan26a/sketch_jan26a.ino:26:3: error: expected ';' before 'if'"...i have write "distanza" but i have another error:"/tmp/126961661/sketch_jan26a/sketch_jan26a.ino:24:23: error: expression cannot be used as a function

/tmp/126961661/sketch_jan26a/sketch_jan26a.ino:26:23: error: expression cannot be used as a function

"
I have copied all on TextEdit but I have the sames errors...what i have to do?

You do need a ; only after a command.

And use 'distanza', not 'distanza()' :wink:

Maybe this might be close to what you are looking for?

#define TRIG_PIN 10
#define ECHO_PIN 9
#define BUZZ_PIN 8

void setup() {
  Serial.begin(9600);
  pinMode(TRIG_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
  digitalWrite(TRIG_PIN, LOW);
}

void loop() {
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(20);
  digitalWrite(TRIG_PIN, LOW);

  unsigned long tempo = pulseIn(ECHO_PIN, HIGH);
  float distanza = 0.03438 * tempo / 2;

  Serial.print("distanza: ");
  Serial.print(distanza);
  Serial.println("cm");
  delay(20);
 
  if(distanza <= 30)
  {
    digitalWrite(BUZZ_PIN, HIGH);
  }
  else
  {
    digitalWrite(BUZZ_PIN, LOW);
  }
 }

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html .
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you tell us your electronics, programming, arduino, hardware experience?
What model Arduino are you using?
What version IDE?

Is there a reason you are not using the NewPing library to communicate with your ultrasonic unit?

Thanks.. Tom.... :slight_smile:

i don't have any experince of electronics ,proggraming ,arduino or hrdware and i use a Quimat UNO R3

What's worse than debugging OPC? Debugging lifted OPC!