invalid library and stray # in program

hi guys.i am new to arduino.. i uploaded a program to make arduino radar from mechatronics but i often got an error that invalid library is found and stray # in program or token { before or something like that i think . This is my program 1. // Includes the Servo library 2. #include . 3. 4. // Defines Tirg and Echo pins of the Ultrasonic Sensor 5. const int trigPin = 10; 6. const int echoPin = 11; 7. // Variables for the duration and the distance 8. long duration; 9. int distance; 10. 11. Servo myServo; // Creates a servo object for controlling the servo motor 12. 13. void setup() { 14. pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output 15. pinMode(echoPin, INPUT); // Sets the echoPin as an Input 16. Serial.begin(9600); 17. myServo.attach(12); // Defines on which pin is the servo motor attached 18. } 19. void loop() { 20. // rotates the servo motor from 15 to 165 degrees 21. for(int i=15;i<=165;i++){ 22. myServo.write(i); 23. delay(30); 24. distance = calculateDistance();// Calls a function for calculating the distance measured by the Ultrasonic sensor for each degree 25. 26. Serial.print(i); // Sends the current degree into the Serial Port 27. Serial.print(","); // Sends addition character right next to the previous value needed later in the Processing IDE for indexing 28. Serial.print(distance); // Sends the distance value into the Serial Port 29. Serial.print("."); // Sends addition character right next to the previous value needed later in the Processing IDE for indexing 30. } 31. // Repeats the previous lines from 165 to 15 degrees 32. for(int i=165;i>15;i--){ 33. myServo.write(i); 34. delay(30); 35. distance = calculateDistance(); 36. Serial.print(i); 37. Serial.print(","); 38. Serial.print(distance); 39. Serial.print("."); 40. } 41. } 42. // Function for calculating the distance measured by the Ultrasonic sensor 43. int calculateDistance(){ 44. 45. digitalWrite(trigPin, LOW); 46. delayMicroseconds(2); 47. // Sets the trigPin on HIGH state for 10 micro seconds 48. digitalWrite(trigPin, HIGH); 49. delayMicroseconds(10); 50. digitalWrite(trigPin, LOW); 51. duration = pulseIn(echoPin, HIGH); // Reads the echoPin, returns the sound wave travel time in microseconds 52. distance= duration*0.034/2; 53. return distance; 54. }

pls help me with my second project

Did you try to compile the code with the line numbers in the code. Remove all of the line numbers and try again.

Please read the "how to use the forum" stickies to see how to format and post code and error mrssages.

Post the code in code tags without the line numbers. Post the entire and exact text of the error messages in code tags.

The problem was, indeed, the line numbers. Here is your code in code tags, with the line numbers removed, properly indented (with ctrl-t, Tools, Autoformat) and all curly brackets on their own line. It compiles fine on 1.6.5, but has not been tested.

// Includes the Servo library
#include 

// Defines Tirg and Echo pins of the Ultrasonic Sensor
const int trigPin = 10;
const int echoPin = 11;
// Variables for the duration and the distance
long duration;
int distance;

Servo myServo; // Creates a servo object for controlling the servo motor

void setup()
{
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); // Sets the echoPin as an Input
  Serial.begin(9600);
  myServo.attach(12); // Defines on which pin is the servo motor attached
}
void loop()
{
  // rotates the servo motor from 15 to 165 degrees
  for (int i = 15; i <= 165; i++)
  {
    myServo.write(i);
    delay(30);
    distance = calculateDistance();// Calls a function for calculating the distance measured by the Ultrasonic sensor for each degree

    Serial.print(i); // Sends the current degree into the Serial Port
    Serial.print(","); // Sends addition character right next to the previous value needed later in the Processing IDE for indexing
    Serial.print(distance); // Sends the distance value into the Serial Port
    Serial.print("."); // Sends addition character right next to the previous value needed later in the Processing IDE for indexing
  }
  // Repeats the previous lines from 165 to 15 degrees
  for (int i = 165; i > 15; i--)
  {
    myServo.write(i);
    delay(30);
    distance = calculateDistance();
    Serial.print(i);
    Serial.print(",");
    Serial.print(distance);
    Serial.print(".");
  }
}
// Function for calculating the distance measured by the Ultrasonic sensor
int calculateDistance()
{

  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH); // Reads the echoPin, returns the sound wave travel time in microseconds
  distance = duration * 0.034 / 2;
  return distance;
}

faraday now after i compiled it the eArduino: 1.8.0 (Windows 8.1), Board: "Arduino/Genuino Uno"

C:\Users\dell\Documents\Arduino\libraries\ur1\ur1.ino: In function 'void setup()':

ur1:15: error: a function-definition is not allowed here before '{' token

{

^

ur1:22: error: a function-definition is not allowed here before '{' token

{

^

ur1:68: error: expected '}' at end of input

}

^

exit status 1 a function-definition is not allowed here before '{' token

Invalid library found in C:\Users\dell\Documents\Arduino\libraries\multiple_blink: C:\Users\dell\Documents\Arduino\libraries\multiple_blink Invalid library found in C:\Users\dell\Documents\Arduino\libraries\ur1: C:\Users\dell\Documents\Arduino\libraries\ur1 Invalid library found in C:\Users\dell\Documents\Arduino\libraries\multiple_blink: C:\Users\dell\Documents\Arduino\libraries\multiple_blink Invalid library found in C:\Users\dell\Documents\Arduino\libraries\ur1: C:\Users\dell\Documents\Arduino\libraries\ur1

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

i tried it in arduino ide 1.6.5...it shows Arduino: 1.6.5 (Windows 8.1), Board: "Arduino/Genuino Uno"

ur1.ino:4: error: stray '#' in program ur1.ino.ino: In function 'void setup()': ur1.ino:4: error: expected ';' before numeric constant ur1.ino:8: error: expected ';' before 'const' ur1.ino:10: error: expected ';' before numeric constant ur1.ino:11: error: expected ';' before 'int' ur1.ino:13: error: expected ';' before numeric constant ur1.ino:15: error: expected ';' before numeric constant ur1.ino:21: error: expected ';' before 'void' ur1.ino:64: error: expected '}' at end of input stray '#' in program

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

faraday now after i compiled it

I just copied the code that I posted and compiled it under 1.6.5, it compiles fine. The trouble is on your end.

ur1.ino:4: error: stray '#' in program
ur1.ino.ino: In function 'void setup()':
ur1.ino:4: error: expected ';' before numeric constant
ur1.ino:8: error: expected ';' before 'const'
ur1.ino:10: error: expected ';' before numeric constant
ur1.ino:11: error: expected ';' before 'int'
ur1.ino:13: error: expected ';' before numeric constant
ur1.ino:15: error: expected ';' before numeric constant
ur1.ino:21: error: expected ';' before 'void'
ur1.ino:64: error: expected '}' at end of input
stray '#' in program

It looks like your original error (stray # in program or token), doesn't it? Remove the line numbers then try again. The source code can't have line numbers in it. The line numbers only show in the IDE. If that is not the problem, post the exact code that you tried.

this is the original program i copied from mechatronics
#include <Servo.h>.
// Defines Tirg and Echo pins of the Ultrasonic Sensor
const int trigPin = 10;
const int echoPin = 11;
// Variables for the duration and the distance
long duration;
int distance;
Servo myServo; // Creates a servo object for controlling the servo motor
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600);
myServo.attach(12); // Defines on which pin is the servo motor attached
}
void loop() {
// rotates the servo motor from 15 to 165 degrees
for(int i=15;i<=165;i++){
myServo.write(i);
delay(30);
distance = calculateDistance();// Calls a function for calculating the distance measured by the Ultrasonic sensor for each degree

Serial.print(i); // Sends the current degree into the Serial Port
Serial.print(","); // Sends addition character right next to the previous value needed later in the Processing IDE for indexing
Serial.print(distance); // Sends the distance value into the Serial Port
Serial.print("."); // Sends addition character right next to the previous value needed later in the Processing IDE for indexing
}
// Repeats the previous lines from 165 to 15 degrees
for(int i=165;i>15;i–){
myServo.write(i);
delay(30);
distance = calculateDistance();
Serial.print(i);
Serial.print(",");
Serial.print(distance);
Serial.print(".");
}
}
// Function for calculating the distance measured by the Ultrasonic sensor
int calculateDistance(){

digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH); // Reads the echoPin, returns the sound wave travel time in microseconds
distance= duration*0.034/2;
return distance;
}
pls help me …

I copied that and tried to compile it. There is a spurious period - ‘.’ at the end of this line:

#include <Servo.h>.

With that removed it compiles.