expected primary-expression before ' ' token arduino

Hi, I’m a high school student who’s working on a project with Ultrasound, the purpose of the project is to make the buzzer sound when the Ultrasound emitter detects an object, also a green LED will flash when there’s no obstruction and a red one when there’s an obstacle, I get the problem mentioned above like 3 times in the error message, I’ll show it to you now (SOME EXPLANATIONS ARE IN SPANISH, LIKE PIN VERDE WITH STANDS FOR GREEN PIN):

#include <Ultrasonic.h>

/Opiron Electronics by A.Girod
Programación de un sensor de aparcamiento con alarma visual y acústica
Mediante la libreria Ultrasonic
by Anton Girod (girodanton@gmail.com)
bajo licencia Creative Commons Attribution-ShareAlike 3.0
/
#include “Ultrasonic.h”

Ultrasonic ultrasonic(12,13); // En lugar de declarar los Pin echo y Pin trig, puedo hacerlo directamente con esta función

int Pinrojo=6;
int Pinverde=5;
int buzzer=4;

void setup() {
Serial.begin (9600);
pinMode(Pinverde,OUTPUT); //Definimos los pines, notar que ya no definimos los pines del sensor
pinMode(Pinrojo, OUTPUT);
pinMode(buzzer,OUTPUT);
}

void loop() {
int cm;
Serial.print(“Duración del pulso de recepción:”);
Serial.print(Ultrasonic.Timing(" us")); //Aqui obtenemos el tiempo del pulso de eco en high
Serial.println(" us");
cm=Ultrasonic.Ranging(cm); //Aqui hacemos la conversión a cm
Serial.print(“Distancia: “);
Serial.print(Ultrasonic.Ranging(” cm”));
Serial.println(" cm");

if (cm>20) //20 cm es la distancia de emergencia
{
digitalWrite(Pinverde, HIGH); //En caso que un objeto esté lejos, pintamos el LED verde
digitalWrite(Pinrojo, LOW);
digitalWrite(buzzer, LOW);
}
else if (cm<20)
{
digitalWrite(Pinverde, LOW); //Si el objeto está muy cerca, hacemos sonar la alarma buzzer y el LED rojo
digitalWrite(Pinrojo, HIGH);
digitalWrite(buzzer, HIGH);
}
delay(500);
}

AND NOW THE ERROR MESSAGES:

Arduino: 1.5.5-r2 (Windows 8), Placa:“Arduino Uno”

BASTON_ARDUINO.ino: In function ‘void loop()’:
BASTON_ARDUINO:30: error: expected primary-expression before ‘.’ token
BASTON_ARDUINO:32: error: expected primary-expression before ‘.’ token
BASTON_ARDUINO:34: error: expected primary-expression before ‘.’ token

This report would have more information with
“Show verbose output during compilation”
enabled in File > Preferences.

Serial.print(Ultrasonic.Timing(" us"));   //Aqui obtenemos el tiempo del pulso de eco en high

So, what is an Ultrasonic? You have an instance of the class called ultrasonic. It is the instance name, not the class name, that you should be using here (and the other two places).

what do you suggest?

what do you suggest?

Serial.print(ultrasonic.Timing(" us")); //Aqui obtenemos el tiempo del pulso de eco en high

By doing that I get these errors:

Arduino: 1.5.5-r2 (Windows 8), Placa:"Arduino Uno"

BASTON_ARDUINO.ino: In function 'void loop()': BASTON_ARDUINO:30: error: 'class Ultrasonic' has no member named 'Timing' BASTON_ARDUINO:32: error: expected primary-expression before '.' token BASTON_ARDUINO:34: error: 'class Ultrasonic' has no member named 'Ranging'

This report would have more information with "Show verbose output during compilation" enabled in File > Preferences.

Arduino: 1.5.5-r2 (Windows smiley-cool, Placa:"Arduino Uno"

Post in code tag the # it makes sure we can read your code smiileys never compile!

Mark

You’ve got this
#include <Ultrasonic.h>
and this
#include “Ultrasonic.h”

probably just want 1 of them.
Also make sure the Ultrasonic library is your Arduino File:Preferences/your_path/libraries folder.

BASTON_ARDUINO:30: error: 'class Ultrasonic' has no member named 'Timing'

Then why are you trying to call it?

Post a link to the library. You are clearly doing something wrong.

Names /identifiers are case sensitive FRED is not the same as fred is not the same as Fred........

Mark

May I be using the wrong library? I took it from here: http://www.ardublog.com/library-for-arduino-ultrasonic-ranging-hc-sr04/

This code compiles for me:

#include <Ultrasonic.h>


/*Opiron Electronics by A.Girod
Programación de un sensor de aparcamiento con alarma visual y acústica
Mediante la libreria Ultrasonic
by Anton Girod (girodanton@gmail.com)
bajo licencia Creative Commons Attribution-ShareAlike 3.0*/
#include "Ultrasonic.h"

 
Ultrasonic ultrasonic(12,13); // En lugar de declarar los Pin echo y Pin trig, puedo hacerlo directamente con esta función
 
int Pinrojo=6;
int Pinverde=5;
int buzzer=4;
 
void setup() {
  Serial.begin (9600);
  pinMode(Pinverde,OUTPUT);   //Definimos los pines, notar que ya no definimos los pines del sensor
  pinMode(Pinrojo, OUTPUT);   
  pinMode(buzzer,OUTPUT);
}
 
void loop() {
  int cm;
  Serial.print("Duración del pulso de recepción:");
  Serial.print(ultrasonic.Timing());   //Aqui obtenemos el tiempo del pulso de eco en high
  Serial.println(" us");
  cm=ultrasonic.Ranging(cm);          //Aqui hacemos la conversión a cm
  Serial.print("Distancia: ");
  Serial.print(ultrasonic.Ranging(CM));
  Serial.println(" cm");
 
 if (cm>20)                           //20 cm es la distancia de emergencia
{
    digitalWrite(Pinverde, HIGH);    //En caso que un objeto esté lejos, pintamos el LED verde
    digitalWrite(Pinrojo, LOW);
    digitalWrite(buzzer, LOW);
}
else if (cm<20)
{
   digitalWrite(Pinverde, LOW);   //Si el objeto está muy cerca, hacemos sonar la alarma buzzer y el LED rojo
   digitalWrite(Pinrojo, HIGH);
   digitalWrite(buzzer, HIGH);
}
  delay(500);
}

Can you send me the library you're using? I think my library is the problem because it's not compiling...