Hello,
i am beginer...
can someone help me with code?
I need measure a temperature with thermistor
.............
// Measure value of thermistor and data send to PC
//
// + (5V) ... 1Ok ... ... 1k... 0V (GND)
// + (5V) ... 10k ... ... thermistor ... 0V(GND)
//
float value = 0;
int referencePin = 0; // thermistor pin 0.
int measurePin = 1; // reference pin 1.
int reference = 0;
int measure = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
// read the value from the refernce:
reference = analogRead(referencePin);
measure = analogRead(measurePin);
Your code actually looks more-or-less well-arranged to work with integer math. However:
int measure = 0;
:
value = (measure * 10000)/(reference - measure);
All of the variables in here are "ints", which have a maximum value of 32767 on Arduino. So unless "measure" is consistently less than 4 (which isn't very interesting), that first multiply is likely to overflow the range of "int"-based math. If you're expecting the result to be a relatively small number, you might get away with changing the constant to a "long" (which will cause the intermediate math to be done with longs):
int measure = 0;
:
value = (measure * 10000L)/(reference - measure);
Or you could make all of your variables be "long" (or floating point, as someone else suggested, though that may be more than you need.)