0
#include <LiquidCrystal.h>

int trigPin = 13;  //sensor's trigger pin connected to pin 13
int echoPin = 7;  //sensor's echo pin connected to pin 11
float pingTime;  //time for the ping to hit the target and back
float ss;  //we will calculate the speed of sound
float td = 13; //target distance.



void setup() {
  // put your setup code here, to run once:

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

  Serial.begin(9600);
  pinMode(trigPin,OUTPUT);  //TRIG AS OUTPUT
  pinMode(echoPin,INPUT);  //EHO AS AN INPUT


  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.println(ss);

}

void loop() {
  // put your main code here, to run repeatedly:

  digitalWrite(trigPin,LOW);  //set trig pin low.
  delayMicroseconds(2000);
  digitalWrite(trigPin,HIGH);
  delayMicroseconds(100);
  digitalWrite(trigPin,LOW);
  pingTime = pulseIn(echoPin,HIGH);  //measure ping time traveltime in microseconds.
  ss= 2*td / pingTime;  //gives us speed in inches per microseconds.
  ss=ss/63360*1000000*3600;  //gives us speed in miles per hour.
  Serial.print("The speed of sound is ");
  Serial.print(ss);
  Serial.println(" miles per hour"); 

  // Turn off the blinking cursor:
  lcd.noBlink();
  delay(3000);
  // Turn on the blinking cursor:
  lcd.blink(0);
  delay(3000);

}
4
  • 2
    Your program doesn't even begin to compile. Maybe you should worry more about where you are defining things first?
    – Majenko
    Commented Dec 24, 2016 at 19:39
  • 1
    And I see no \302 in that program. Are you actually showing us the right program here?
    – Majenko
    Commented Dec 24, 2016 at 19:41
  • The variable lcd will be out of scope in loop.
    – Nick Gammon
    Commented Dec 24, 2016 at 23:07
  • Please add more details. What have you tried? What was the result.
    – sa_leinad
    Commented Dec 26, 2016 at 4:01

3 Answers 3

2

The culprits are the no-break spaces (U+00A0) you sometimes use in your indentation. Each of them, when encoded in UTF-8, is represented by the pair of bytes 0xc2 0xa0 (or 0302 0240 in octal). You should indent with regular spaces (U+0020) instead.

Specifically, you have no-break spaces as the first characters of each of the following 8 lines:

lcd.begin(16, 2);
// Print a message to the LCD.
lcd.println(ss);
[...]
lcd.noBlink();
delay(3000);
// Turn on the blinking cursor:
lcd.blink(0);
delay(3000);
1

Beware when you copy code from sites which have formatead fonts in their content. As you copy and paste these font-formatead codes, chances are that you copy the font's formats as well. Once you paste these formatead fonts on your code, the text editor from the Arduino IDE will not recognize the special characters used on the font's formatting; thus, it will not show them on your screen. However, the compiler will read them and will strive to compile them as if they were part of your code. Since the compiler does not "understand" these special characters, it will warn you about their existence by identifying them as "stray" pieces of code. This is why some code-related sites, such as GitHub, gives you the opportunity of copying RAW CODE, so you do not copy the formatead fonts that some developers use to showcase their much appreciated contributions. I sincerely hope this works for you. Best regards.

1

Just try to removes extra spaces that are outside the scopes (curly braces { and }) and it'll work fine.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.