Code not compiling

So for my project in class I am attempting to make a self driving car. It's very simple and I have the whole car built with all the wires and circuits all hooked up but when I try uploading the code from I got from this instuctable, I get the error message "Error compiling code for Arduino/Genuino Uno" with this message in the black space below, I think its the serial monitor
"exit status 1
Error compiling for board Arduino/Genuino Uno."

These are the instructions I have been Following;

There is no obvious problem with the code that you have not posted.

Post your actual code rather than a link to the code that you may or may not be using. Can you please post the whole error message as well as I suspect that there is more to it than what you have currently told us.

NOTE : Please use code tags (</> top/left of the forum editor) when you post the code and the error message. This avoids any part of the code being interpreted as HTML commands and is described in read this before posting a programming question which I assume that you have not read.

Instructables are normally crap.
Did you do this bit?

Note: you need to find the "Ultrasonic.h" online.

And install it in your library folder?

Grumpy_Mike:
Instructables are normally crap.
Did you do this bit?And install it in your library folder?

Yes I get the same error message with that. And I guess one thing I am confused about since there are three files of code, do I need to put them all inn the same place? I am a newbie for robotics, sorry.

UKHeliBob:
There is no obvious problem with the code that you have not posted.

Post your actual code rather than a link to the code that you may or may not be using. Can you please post the whole error message as well as I suspect that there is more to it than what you have currently told us.

NOTE : Please use code tags (</> top/left of the forum editor) when you post the code and the error message. This avoids any part of the code being interpreted as HTML commands and is described in read this before posting a programming question which I assume that you have not read.

UKHeliBob:
There is no obvious problem with the code that you have not posted.

Post your actual code rather than a link to the code that you may or may not be using. Can you please post the whole error message as well as I suspect that there is more to it than what you have currently told us.

NOTE : Please use code tags (</> top/left of the forum editor) when you post the code and the error message. This avoids any part of the code being interpreted as HTML commands and is described in read this before posting a programming question which I assume that you have not read.

I have read that actually, I just didn't want to post the hundreds of lines of code because I think this is a newbie mistake. If it is needed however I am more than happy to post it I just dont know what code is broken due to my inexpierince with robotics... I have attatched the whole error message though through a screenshot.

Where is the rest of the message?

Ah sorry, guess that picture wasnt all of it it didnt know I could expand the window here is the rest.

Where is the file Ultrasonic.h ? What is the file really called? Perhaps ultrasonic.h ? The capital U may be significant.

By the way, it is better to copy and paste complete error messages in code tags instead of using pictures.

I just didn't want to post the hundreds of lines of code because I think this is a newbie mistake.

You are in no position to know what is or isn't important so better to post it all, or if too large to post then to attach it to a post.

I too will be anxious to see the resolve for this since I got the same error when I tried to compile code for one of my custom boards with what I saw as the only relevant option in the board selections, "Arduino/Genuino Uno," within the new IDE. I finally just went and got MCUdude's package for the atmega328 here, and birds started singing, butterflies flying about, flowers blooming. . . in otherwords all was just fine after that with the new minicore board option now within my new IDE. :slight_smile:

As I said way back in reply #2, you have not installed the Ultrasonic.h in the libiary.

You might think you have but the compiler thinks you haven't. You know what, the compiler is right, it always is, even when it is wrong.

Grumpy_Mike:
As I said way back in reply #2, you have not installed the Ultrasonic.h in the libiary.

You might think you have but the compiler thinks you haven't. You know what, the compiler is right, it always is, even when it is wrong.

How do I install this to the library?

UKHeliBob:
You are in no position to know what is or isn't important so better to post it all, or if too large to post then to attach it to a post.

Here is the code

FPYWXUBHZI8QHTY.ino (5.06 KB)

FPYWXUBHZI8QHTY.ino (5.06 KB)

UltrasonicSimple.ino (1.71 KB)

How do I install this to the library?

Create a folder in the Arduino sketch directory libraries folder named Ultrasonic. Copy Ultrasonic.h, Ultrasonic.cpp and any other files or folders from the library into that folder.

UKHeliBob:
Create a folder in the Arduino sketch directory libraries folder named Ultrasonic. Copy Ultrasonic.h, Ultrasonic.cpp and any other files or folders from the library into that folder.

Done, now i get an error message that states
"Arduino: 1.8.5 (Windows 10), Board: "Arduino/Genuino Uno"

F3E7GSUHZI8QI9Q:39: error: 'class Ultrasonic' has no member named 'Ranging'

int distance = (ultrasonic.Ranging(CM));

^

C:\Users\ryanf\Downloads\F3E7GSUHZI8QI9Q\F3E7GSUHZI8QI9Q.ino: In function 'void loop()':

F3E7GSUHZI8QI9Q:69: error: 'class Ultrasonic' has no member named 'Ranging'

distance = (ultrasonic.Ranging(CM));

^

F3E7GSUHZI8QI9Q:88: error: 'class Ultrasonic' has no member named 'Ranging'

distance = (ultrasonic.Ranging(CM));

^

F3E7GSUHZI8QI9Q:99: error: 'class Ultrasonic' has no member named 'Ranging'

distance = (ultrasonic.Ranging(CM));

^

F3E7GSUHZI8QI9Q:105: error: 'class Ultrasonic' has no member named 'Ranging'

distance = (ultrasonic.Ranging(CM));

^

F3E7GSUHZI8QI9Q:110: error: 'class Ultrasonic' has no member named 'Ranging'

distance = (ultrasonic.Ranging(CM));

^

F3E7GSUHZI8QI9Q:126: error: 'class Ultrasonic' has no member named 'Ranging'

distance = (ultrasonic.Ranging(CM));

^

F3E7GSUHZI8QI9Q:142: error: 'class Ultrasonic' has no member named 'Ranging'

distance = (ultrasonic.Ranging(CM));

^

F3E7GSUHZI8QI9Q:148: error: 'class Ultrasonic' has no member named 'Ranging'

distance = (ultrasonic.Ranging(CM));

^

F3E7GSUHZI8QI9Q:155: error: 'class Ultrasonic' has no member named 'Ranging'

distance = (ultrasonic.Ranging(CM));

^

F3E7GSUHZI8QI9Q:161: error: 'class Ultrasonic' has no member named 'Ranging'

distance = (ultrasonic.Ranging(CM));

^

exit status 1
'class Ultrasonic' has no member named 'Ranging'

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

I'm guessing this has to do with the Ultrasonic.h code not being the correct one

I'm guessing this has to do with the Ultrasonic.h code not being the correct one

That sounds likely. However, the Ultrasonic library in step 5 of the Instructables page you linked to does have Ranging function

long Ultrasonic::Ranging(int sys)
{
  Timing();
  distacne_cm = duration /29 / 2 ;
  distance_inc = duration / 74 / 2;
  if (sys)
  return distacne_cm;
  else
  return distance_inc;
}

Note the spelling mistake

Frankly you do not need a library to drive the sensor

I noticed this too, could it be the code was written too long ago to be supported by the newer Arduino IDE? And you say I don't need a library to run the Sensor, so could I program it straight into my code? Also Since there are two main pages of code, do I link them or upload one then upload the other? (Assuming my code eventually works)

Here is the entire Ultrasonic.cpp file

/*
  Ultrasonic.cpp - Library for HC-SR04 Ultrasonic Ranging Module.library

  Created by ITead studio. Apr 20, 2010.
  iteadstudio.com
*/

#include "Arduino.h"
#include "Ultrasonic.h"

Ultrasonic::Ultrasonic(int TP, int EP)
{
   pinMode(TP,OUTPUT);
   pinMode(EP,INPUT);
   Trig_pin=TP;
   Echo_pin=EP;
}

long Ultrasonic::Timing()
{
  digitalWrite(Trig_pin, LOW);
  delayMicroseconds(2);
  digitalWrite(Trig_pin, HIGH);
  delayMicroseconds(10);
  digitalWrite(Trig_pin, LOW);
  duration = pulseIn(Echo_pin,HIGH);
  return duration;
}

long Ultrasonic::Ranging(int sys)
{
  Timing();
  distacne_cm = duration /29 / 2 ;
  distance_inc = duration / 74 / 2;
  if (sys)
  return distacne_cm;
  else
  return distance_inc;
}

All it does is to wrap the driving of the pins in a library but you could do it in the main code if you wanted.

As to the code, I am not clear what you are asking. You would probably be better off writing it yourself rather than doing copy/paste and not understanding how or why it works (or doesn't)

That code is AWFUL! :o