Program error "stray '\' in program"

I try to build ohmmeter, but have an error in program, what I do wrong?

This is my source code:

float r1= 10000.0; 

void setup()
{
Serial.begin(9600);
} 
void loop()
{
float Uwyj = (5.0/1024.0) * float(analogRead(0));
float R=r1*((5.0/Uwyj) – 1);
Serial.print("Napiecie wyj: "); Serial.println(Uwyj);  
Serial.print("Wartosc rezystora: "); Serial.println(R);
delay(3000);
}

This is error message I get:

sketch_mar15a:10: error: stray '\' in program
sketch_mar15a.ino: In function 'void loop()':
sketch_mar15a:10: error: expected `)' before 'u2013'

There is something wrong with your - sign here:

float R=r1*((5.0/Uwyj) – 1);

Deleting it, and replacing it with a regular minus sign allows the code to compile;.

thx

A few tips:

  • proper indenting and adding spaces makes code more readable
  • too much parenthesis can obfuscate code - (OK too few will corrupt code)
  • use of constants for 'magic' numbers helps readability
  • a header to document the code helps
  • a startup message too
//    FILE: Ohmmeter.ino
//  AUTHOR: XnIcRaM
// VERSION: 0.1.01
// PURPOSE: Ohmmeter
//    DATE: 2014-xx-xx
//
// <short description of HW here>
//

const int measurePin = 0;
float r1= 10000.0; 

void setup()
{
  Serial.begin(9600);
  Serial.println("Ohmmeter 0.1");
} 

void loop()
{
  // MEASUREMENT
  int raw = analogRead(measurePin);

  // PROCESS
  float Uwyj = 5.0/1024.0 * raw;
  float R = r1 * ( 5.0/Uwyj) – 1;

  // DISPLAY
  Serial.print("Napiecie wyj: "); Serial.println(Uwyj);  
  Serial.print("Wartosc rezystora: "); Serial.println(R);
  delay(3000);
}

Note the 'process' formulas can be merged, reducing rounding errors.

finally if the raw measurement == 0 you have a problem. (divide by zero)

I found the solving methode about this "Program error "stray '' in program"

Just replace all minus sign with the minus on the number pad or (if you are using laptop) use the Fn+":" button to type the minus sign.

below is mine as a sample:
const int ledPin = 13; // the number of the LED pin

int ledState = LOW; // ledState used to set the LED

long previousMillis = 0; // will store last time LED was updated

long interval = 1000; // interval at which to blink (milliseconds)

void setup() {

pinMode(ledPin, OUTPUT);

}

void loop() {

unsigned long currentMillis = millis();

if (currentMillis- previousMillis>interval){ // ERROR when copy-paste from web, but well done when i replace the minus sign by number pad

previousMillis = currentMillis;

if (ledState == LOW){

ledState = HIGH;

}else{

ledState = LOW;

}

digitalWrite(ledPin, ledState);

}

}

I just copied the code from your post into an IDE window, hit "verify", and got this error message Binary sketch size: 1,028 bytes (of a 30,720 byte maximum)