I'm new to arduino programming. I'm working on a project of Ultrasonic Distance Meter Using Arduino Uno. I got the program is :
#include <Ultrasonic.h> #include <LiquidCrystal.h> //Setup connection with LCD and HC-SR04 LiquidCrystal lcd(12, 11, 5, 4, 3, 2); Ultrasonic ultrasonic(A0,A1); void setup() { //Lcd init lcd.begin(16, 2); //16 rows, 2 columns } void loop() { lcd.clear(); lcd.print(" Distance Meter "); // You can change this message. lcd.setCursor(0, 1); //Change line... lcd.print("Distance: "); lcd.print(ultrasonic.Ranging(CM)); lcd.print("cm"); delay(1000); // 1sec delay }
But when i try to verify it, it gives me following error :
D:\Desktop\F6QO2RSI5F7GFJL\sketch_feb25a\sketch_feb25a.ino: In function 'void loop()': sketch_feb25a:15: error: 'class Ultrasonic' has no member named 'Ranging' lcd.print(ultrasonic.Ranging(CM));
** ^** exit status 1 'class Ultrasonic' has no member named 'Ranging'
You can't expect everyone to have used, or have installed, the library Ultrasonic.h so best post a link to that.
(edit: I did a search and downloaded one, but the IDE library manager told me it wasn't a valid library. So back to you to provide link to a known-good one.)
Guys, thank you for your response, but i am really new to this . I dont even understand what you are saying. and i think I do have ultrasonic.h library installed. Check the attachment.
manor_royal:
You can't expect everyone to have used, or have installed, the library Ultrasonic.h so best post a link to that.
(edit: I did a search and downloaded one, but the IDE library manager told me it wasn't a valid library. So back to you to provide link to a known-good one.)
You might have a very old, incompatible, Ultrasonic library installed. Github version is confirmed working. Download and replace your current files. I found another Ultrasonic library in Arduino library manager. ultrasonic.Ranging(CM) corresponds to the first, but as you get an error on it, it might be you are using a function from another library than you have installed. Find ultrasonic.h and open it with notepad and copy it all here. In windows you will most likely find it in C:\Users\Your name\Documents\Arduino\libraries\Ultrasonic\src
You should have a look at the readme for the library you are using.
Gabriel_swe: You might have a very old, incompatible, Ultrasonic library installed. Github version is confirmed working. Download and replace your current files. I found another Ultrasonic library in Arduino library manager. ultrasonic.Ranging(CM) corresponds to the first, but as you get an error on it, it might be you are using a function from another library than you have installed. Find ultrasonic.h and open it with notepad and copy it all here. In windows you will most likely find it in C:\Users\Your name\Documents\Arduino\libraries\Ultrasonic\src
It will not work as he tried the library you you used code for, which isn't working for you as you have another library installed.
BUT, with your library comes an example you can look at. I would connect sensor to digital pins as in the example. File > Examples > Ultrasonic > UltrasonicSimple
Libraries usually comes with examples if you look for them.
ketan2702:
i really don't understand.
Two different libraries with same name. You have one library installed but used the syntax from the other. That doesn't work as every library has its own syntax.
I would say it is quite rare a library is released with the same name as an already existing name, but in this case it exists.
To see the manual for your installed Ultrasonic library, see this readme file
Thank you guys for your support. I've figured it out that the library i was using was having ultrasonick.h spelling and in program there was ultrasonic.h.
So imade some changes and instead of ultrasonic.ranging i've declared a variable and then stored the distance in it using ultrasonick.distanceRead().
Now the program is been verified and successfully written on board.