0
#include "Ultrasonic.h"
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() {
  // put your setup code here, to run once:
  lcd.begin();
  Serial.begin(9600);
}
Ultrasonic ultrasonic(11, 12); //Ultrasonic ultrasonic(Trig,Echo);
void loop()
{
  int a = (Ultrasonic.Ranging(CM));
  if (a >= 15 && a < 20)
  { Serial.println("guvenli");
    lcd.print("guvenli");
    delay(500);
    lcd.clear();
    tone(3, 2000, 100);
    delay(500);
    noTone(3);
  }
  if (a >= 10 && a < 15) {
    Serial.println("guvenli dikkat");
    lcd.print("guvenli dikkat");
    delay(500);
    lcd.clear();
    tone(3, 2000, 50);
    delay(250);
    noTone(3);
  }
  if (a < 5)
  {
    Serial.println("vurdun");
    lcd.print("vurdun");
    delay(500);
    lcd.clear();**uıhhf
    tone(3, 2000, 50);
    delay(50);
    noTone(3);
  }
}

In this code i'm getting an error like this:

   C:\Users\*\AppData\Local\Temp\arduino_modified_sketch_113625\sketch_apr29a.ino: In function 'void loop()':

sketch_apr29a:19:22: error: expected primary-expression before '.' token

   int a = (Ultrasonic.Ranging(CM)); 

                      ^

exit status 1
expected primary-expression before '.' token
12
  • Please show as a full working example of your code, that shows the problem. This cannot be your full code. Also please provide a link to the library, that you use for Ultrasonic.
    – chrisl
    Apr 29, 2019 at 7:33
  • pasted.co/172df900
    – Ruby AK
    Apr 29, 2019 at 7:39
  • 1
    I guess you used the following libraries: LiquidCrystal-I2C and Ultrasonic-HC-SR04
    – chrisl
    Apr 29, 2019 at 7:50
  • And please copy your full code into the question, so that it does not rely on a link, that may become invalid over time. I did that for you now.
    – chrisl
    Apr 29, 2019 at 7:53
  • If I remove the **uıhhf in line 40 (which does seem like a typo), your sketch compiles fine for me. I don't receive the shown error. I'm using Arduino IDE 1.8.5 and Arduino Uno as target board.
    – chrisl
    Apr 29, 2019 at 7:56

1 Answer 1

2

Ultrasonic is a class name. Why are you trying to use it before a . in an expression?

Judging by the declaration, you need ultrasonic. That is your object name. ultrasonic, not Ultrasonic.

3
  • Comparing the provided code with the error text, I would bet that one or the other is a typo, notice the case of 'ultrasonic' in the code does not match the corresponding line in the error. Apr 30, 2019 at 15:40
  • 2
    @Kelly S. French: Well, if you look through the editing history, you'll see that the code in the original post did match the error text. Meanwhile, the pastebin version linked by the author in the comments is slightly different - the Ultrasonic error is already fixed. Later the code here was replaced with pastebin version. So the question became inconsistent with itself. Apr 30, 2019 at 16:39
  • Good point, I had not considered looking through the edit history. My misgivings were more around my surprise at the error text given that a problem with strict case-matching wouldn't typically be related to a missing 'primary expression' as usually there needs to be a named identifier before the '.' and to expect an expression there would make me wonder if the cause were elsewhere, for instance the snippet ' **uıhhf in line 40 ' mentioned by chrisl, which definitely look like a syntax error but I can't see how it would generate that error either. Did the OP not include the whole error log? Apr 30, 2019 at 17:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.