Can't find file

Hello,
I’m a beginner with Arduino and I have designed a program using ultrasonic sensors.
I have included the program <NewPing.h> at the beginning of my sketch, although when I press “Compile”, it says :

“NewPing.h” contains unrecognized characters.If this code was created with an older version of Processing,you may need to use Tools → Fix Encoding & Reload to updatethe sketch to use UTF-8 encoding. If not, you may need todelete the bad characters to get rid of this warning.

My main program was running well before but I think I might have moved <NewPing.h> somewhere it can’t be seen or I don’t know what :frowning:

Help pleeease

Hi Bartyshow

Please post your program. Use the code tags (the '#' button above the row of smileys) when you post it.

My main program was running well before ...

Did the program include Newping, or has the problem only happened since you added Newping?

Thanks

Ray

#include <Servo.h> //inclure un programme qui gere l'objet servo
#include <NewPing.h> //inclure un programme qui gere le ping

#define ECHO_PIN 2         //dire sur quel pin de la breadboard les output du ping sont relies
#define TRIGGER_PIN 4     // idem
#define MAX_DISTANCE 200    //distance au dela de laquelle le ping ne detecte plus rien

Servo myservo;  // creer l'objet servo pour le controler avec <servo.h>
 
int pos = 0;    // position de deaprt du servo
int DEL = 13;   //dire sur quel pin de la bread la del est
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); //definir l'ensemble des variables du ping

void setup() 
{ 
  myservo.attach(5);  // dire sur quel pin le servo est branche
  pinMode(DEL, OUTPUT); //initialiser la del comme une output
  Serial.begin(115200);  //debit en bytes par seconde a transferer sur le moniteur (longueur des pings)
 } 
 
 
void loop() 
{ 
  for(pos = 0; pos < 90; pos += 1)  //aller de 0° a 90°
  {                                  
    myservo.write(pos);              //initialiser ca comme position
    digitalWrite(DEL, HIGH);   //alumer del
    delay(250);
    unsigned int uS = sonar.ping();   //un coup de ping
    Serial.print("Bart est le plus beau et Jacquie, son cher robot est a ");   //inscription sur le moniteur
    Serial.print(uS / US_ROUNDTRIP_CM);                                        //idem
    Serial.println(" cm d'un obstacle");  //idem
    
  } 
  for(pos = 90; pos < 180; pos+=1)      //aller de 90° a 180°
  {                                
    myservo.write(pos);
    digitalWrite(DEL, LOW);
    delay(250);
    unsigned int uS = sonar.ping();
    Serial.print("Bart est le plus beau et Jacquie, son cher robot est a");
    Serial.print(uS/US_ROUNDTRIP_CM);
    Serial.println("cm d'un obstacle.");
    
  } 
  for(pos = 180; pos > 90; pos-=1)
  {
    myservo.write(pos);
    digitalWrite(DEL, HIGH);
    delay(250);
    unsigned int uS = sonar.ping();
    Serial.print("Bart est le plus beau et Jacquie, son cher robot est a");
    Serial.print(uS/US_ROUNDTRIP_CM);
    Serial.println("cm d'un obstacle.");
  }  
  for(pos = 90; pos > 0; pos-=1)
  {
    myservo.write(pos);
    digitalWrite(DEL, LOW);
    delay(250);
    unsigned int uS = sonar.ping();
    Serial.print("Bart est le plus beau et Jacquie, son cher robot est a");
    Serial.print(uS/US_ROUNDTRIP_CM);
    Serial.println("cm d'un obstacle.");
   }
}

Thank you for your quick answer Ray,
The Programm already included NewPing and worked
And for the comments, excuse my french :wink:

Thanks for that.

Can you post (by copy and paste) the errors you get when you compile?

Also, how did you install the NewPing library originally? Did you use the Sketch - Import Library - Add Library option in the IDE?

Errors when compiled :
SweepServoBart:14: error: 'NewPing' does not name a type
SweepServoBart.ino: In function 'void loop()':
SweepServoBart:31: error: 'sonar' was not declared in this scope
SweepServoBart:33: error: 'US_ROUNDTRIP_CM' was not declared in this scope
SweepServoBart:42: error: 'sonar' was not declared in this scope
SweepServoBart:44: error: 'US_ROUNDTRIP_CM' was not declared in this scope
SweepServoBart:53: error: 'sonar' was not declared in this scope
SweepServoBart:55: error: 'US_ROUNDTRIP_CM' was not declared in this scope
SweepServoBart:63: error: 'sonar' was not declared in this scope
SweepServoBart:65: error: 'US_ROUNDTRIP_CM' was not declared in this scope

As for your second question I really have no idea. Someone did it for me in fact.
Thank you again for your time

OK, those are different errors from the one you posted originally. And it looks like the library has gone missing.

Try this ...

Download the library zip file from the link on this page: http://playground.arduino.cc/Code/NewPing

From the zip file, extract the NewPing folder and put it somewhere temporarily, like your desktop.

In the IDE, click Sketch - Import Library - Add Library. Then select the NewPing folder on your desktop and hit OK.

Check that the IDE gives a success message.

Then try compiling your program.

THANK YOU !!!! :slight_smile: :slight_smile: :slight_smile:

That did work :slight_smile:

Now my last question and I'll stop disturbing you, how do I give you a Karma ?

Good news :slight_smile:

On the left of this post, there should be a + sign under “Karma”.

Thank you!