Arduino Cloud and Grove Ultrasonic Ranger library

I am developing a project with a Grove Ultrasonic Ranger sensor by SeeedStudio. Using the Arduino IDE, I could install the Grove Ultrasonic Ranger library and get it working with the following code:

#include "Ultrasonic.h"
Ultrasonic ultrasonic(0);
void setup()
void loop()
  long RangeInCentimeters;
  RangeInCentimeters = ultrasonic.MeasureInCentimeters(); // two measurements should keep an interval
  Serial.println(" cm");

Moving this to the Arduino Cloud, get me this error:

error: 'class Ultrasonic' has no member named 'MeasureInCentimeters'

Is the Arduino Cloud loading a different version of the library? How do I check this?

If you look in Ultrasonic.h, you should be able to find the correct spelling.
(I think it should be "centimetres")

No, this is not what I see. And in any case, it does not explain why it works when uploaded with the IDE and not when the same code is used in the Sketch tab of the Arduino Cloud…

Code extracted from Ultrasonic.h

#ifndef Ultrasonic_H
#define Ultrasonic_H

#include "Arduino.h"

class Ultrasonic {
    Ultrasonic(int pin);
    long MeasureInCentimeters(void);
    long MeasureInMillimeters(void);
    long MeasureInInches(void);
    int _pin;//pin number of Arduino that is connected with SIG pin of Ultrasonic Ranger.
    long duration();


Hi @tomasgf. I'm going to ask you to post some additional information that might help us to identify the problem.
Please do this:

  1. Preferences > Always show output panel (check)
  2. Preferences > Console: Show verbose output (check)
  3. Click the verify button (looks like a checkmark).
  4. After the compilation fails, click the icon in the top right corner of the black console window at the bottom of the Arduino Web Editor window that looks like two pieces of paper.
  5. In a forum reply here, click on the reply field.
  6. Click the </> button on the forum toolbar. This will add the forum's code tags markup to your reply.
  7. Press Ctrl+V. This will paste the compilation output between the code tags.
  8. Move the cursor outside of the code tags before you add any additional text to your reply.

If the length of the output exceeds the forum's 9000 character limit, save it in a txt file and post it here as an attachment. If you click the "Reply" button you'll see the "Attachments and other options" link that will allow you to make the attachment.

Hi @pert. I modified your instructions to run on the Web Editor (not the Cloud Sketch editor as I don't think these options are there). I found the problem:

Multiple libraries were found for "Ultrasonic.h"

Used: /home/builder/opt/libraries/latest/ultrasonic_3_0_0

Not used: /home/builder/opt/libraries/latest/grove_ultrasonic_ranger_1_0_1

Not used: /tmp/755843854/pinned/grove_ultrasonic_ranger_1_0_1

Not used: /home/builder/opt/libraries/latest/ultrasonic_hc_sr04_0_5_0

It is using the wrong library. My sketch needs to use the grove_ultrasonic_ranger_1_0_1.

I saw another post from you (Web Editor bug…) where you listed three methods to solve this.

  • to include another header file | not possible, the library has only one
  • to use the Arduino Web Editor’s sketch metadata system | tried that, it did not work
  • to import the library you want to use | I tried that, it did not work

They are for me:

Great work digging that up!

In the case where an import of the library as-is doesn't work, there is one additional thing that can be done to influence which library the web editor uses. Please try this:

  1. Download the latest version of the "Grove Ultrasonic Ranger" library:
  2. Unzip the downloaded file.
  3. Delete the downloaded file.
  4. From the unzipped library folder, open the file named in a text editor.
  5. Change this line:
    name=Grove Ultrasonic Ranger
    to this:
  6. Save the file.
  7. Zip the library folder.
  8. Import the zipped folder in Arduino Web Editor

The Arduino Web Editor imports libraries to a folder named after the value of the name property in This means that the imported library will have both a folder name and a library name matching perfectly to the filename in your sketch's #include directive, which causes the imported library to get priority over the pre-installed library that is causing you the problem. So you should now be able to compile your sketch and see that the correct library is used:

Multiple libraries were found for "Ultrasonic.h"
Used: /tmp/725767685/custom/Ultrasonic
Not used: /home/builder/opt/libraries/latest/ultrasonic_hc_sr04_0_5_0
Not used: /home/builder/opt/libraries/latest/ultrasonic_3_0_0
Not used: /home/builder/opt/libraries/latest/grove_ultrasonic_ranger_1_0_1
Using library Ultrasonic at version 1.0.1 in folder: /tmp/725767685/custom/Ultrasonic

If you're interested in all the boring details, you can find them here:

I am sorry, you are right. I was thinking on the Arduino Cloud, not on the Arduino Web Editor.

That worked. Thank you.

It kind of solved the problem for me, but not the bigger picture situation that I am targeting. I explain this further:

In the context of a research project, I am testing IoT projects with non-expert users. My assumption is that the Arduino Cloud – a development that I think goes in the right direction – will allow them to make their own projects, easing the entry point. This experience is proving me wrong!

I cannot ask a non-expert user to jump over all these hurdles (open the full editor, identify the correct library, download it, unzip it, throw away the .zip, modify a file, zip it again, upload it…).

I recognise the problem of having multiple libraries available, sometimes with the same names. But… there must be a better way of indicating which one do you want to use.

Any suggestion?

1 Like

I actually didn't know they had added a minimal editor to Arduino IoT Cloud. I'll start prefacing my instructions with the directive to go to the "full editor" from now on.

This is the downside to the Arduino Cloud's having every one of the ~4000 libraries of the Arduino Library Manager pre-installed. It is usually convenient, but not so much when you have a name collision. This becomes statistically more likely as more and more libraries are created and added constantly.

Not that I'm aware of. Perhaps something will be developed eventually.

If you have a fixed set of libraries, as would be the case when writing tutorials or a structured course, you could provided the participants with a collection of libraries pre-packaged for import. If you are able to provide an environment where every library you want to use is in the "custom" location provided by the import, with a name value exactly matching the primary header filename, and with architecture compatibility with the boards in use, then you are guaranteed that those libraries will always be chosen by the build system.

I actually found it useful in the context of my research with non-experts, as it hides the complexity away (it is still available if you are an expert user).

Clearly, dealing with libraries is a bit too complex to completely hide it.

I know what you say about providing participants with a pre-structured collection. And you are right. But somehow defeats the purpose of my research, which aims at understanding if non-experts can make their own projects without recurring to the help of an expert.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.