Hi. I am new to arduinos and I have a problem in programming.
My code read ohms from a sensor and after a calculation gives me temperature.. the problem is that tje calculation contains lots of numbers and it gives an error...If I change the calculation to an easier one the compile is ok but now I have theese problems.I have tried double instead of long double but the same.
My code:
double analogPin = 0; // potentiometer wiper (middle terminal) connected to analog pin 3
// outside leads to ground and +5V
long double raw = 0; // variable to store the raw input value
long double Vin = 5; // variable to store the input voltage
long double Vout = 0; // variable to store the output voltage
long double R1 = 3500; // variable to store the R1 value
long double x = 3000; // variable to store the R2 value
long double buffer = 0; // buffer variable for calculation
void setup()
{
Serial.begin(9600); // Setup serial
digitalWrite(13, HIGH); // Indicates that the program has intialized
}
void loop()
{
raw = analogRead(analogPin); // Reads the Input PIN
Vout = (5.0 / 1023.0) * raw; // Calculates the Voltage on th Input PIN
buffer = (Vin / Vout) - 1;
x = R1 / buffer;
long double temp = 1.0e+02*(0.000000000273515*(x^12)-0.000000062093732*(x^11)+0.000005093376596*(x^10)-0.000199786452006*(x^9)+0.004204191550653*(x^8)-0.050618844995940*(x^7)+0.363003300573527*(x^6)-1.586431667336761*(x^5)+4.250693805645307*(x^4)-6.897469709323302*(x^3)+6.590042917782492*(x^2)-3.680492145670033*x+1.539556457792295));
Serial.print("temp: ");
Serial.println(x);
delay(500);
and the errors:
sketch_oct16a.ino: In function 'void loop()':
sketch_oct16a:21: error: invalid operands of types 'long double' and 'int' to binary 'operator^'
sketch_oct16a:21: error: invalid operands of types 'long double' and 'int' to binary 'operator^'
sketch_oct16a:21: error: invalid operands of types 'long double' and 'int' to binary 'operator^'
sketch_oct16a:21: error: invalid operands of types 'long double' and 'int' to binary 'operator^'
sketch_oct16a:21: error: invalid operands of types 'long double' and 'int' to binary 'operator^'
sketch_oct16a:21: error: invalid operands of types 'long double' and 'int' to binary 'operator^'
sketch_oct16a:21: error: invalid operands of types 'long double' and 'int' to binary 'operator^'
sketch_oct16a:21: error: invalid operands of types 'long double' and 'int' to binary 'operator^'
sketch_oct16a:21: error: invalid operands of types 'long double' and 'int' to binary 'operator^'
sketch_oct16a:21: error: invalid operands of types 'long double' and 'int' to binary 'operator^'
sketch_oct16a:21: error: invalid operands of types 'long double' and 'int' to binary 'operator^'
sketch_oct16a:24: error: call of overloaded 'println(long double&)' is ambiguous
sketch_oct16a.ino:24:18: note: candidates are:
In file included from C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/Stream.h:26:0,
from C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial.h:29,
from C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:224,
from sketch_oct16a.ino:1:
C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/Print.h:73:12: note: size_t Print::println(char)
size_t println(char);
^
C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/Print.h:74:12: note: size_t Print::println(unsigned char, int)
size_t println(unsigned char, int = DEC);
^
C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/Print.h:75:12: note: size_t Print::println(int, int)
size_t println(int, int = DEC);
^
C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/Print.h:76:12: note: size_t Print::println(unsigned int, int)
size_t println(unsigned int, int = DEC);
^
C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/Print.h:77:12: note: size_t Print::println(long int, int)
size_t println(long, int = DEC);
^
C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/Print.h:78:12: note: size_t Print::println(long unsigned int, int)
size_t println(unsigned long, int = DEC);
^
C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/Print.h:79:12: note: size_t Print::println(double, int)
size_t println(double, int = 2);
^
invalid operands of types 'long double' and 'int' to binary 'operator^'
Can anyone help me please?