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
#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
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