Hello,
I am trying to replace some #define that I found in an example code.
However, if I do so, I get the wrong or no reading from the NTC that I am addressing.
This version with the #define works perfectly fine
#define ntc_pin A15 // Pin,to which the voltage divider is connected
//#define vd_power_pin 2 // 5V for the voltage divider
#define nominal_resistance 50000 //Nominal resistance at 25⁰C
#define nominal_temeprature 25 // temperature for nominal resistance (almost always 25⁰ C)
#define samplingrate 5 // Number of samples
#define beta 3970 // The beta coefficient or the B value of the thermistor (usually 3000-4000) check the datasheet for the accurate value.
#define Rref 12000 //Value of resistor used for the voltage divider
int samples = 0; //array to store the samples
void setup(void) {
//pinMode(vd_power_pin, OUTPUT);
Serial.begin(115200); //initialize serial communication at a baud rate of 9600
}
// Working with single read Temperature seems off
void loop(void) {
float value;
value = analogRead(ntc_pin);
Serial.print("Analog Read: ");
Serial.println(analogRead(ntc_pin));
delay(10);
// Calculate NTC resistance
value = 1023 / value - 1;
value = Rref / value;
Serial.print("Thermistor resistance ");
Serial.println(value);
float temperature;
temperature = value / nominal_resistance; // (R/Ro)
temperature = log(temperature); // ln(R/Ro)
temperature /= beta; // 1/B * ln(R/Ro)
temperature += 1.0 / (nominal_temeprature + 273.15); // + (1/To)
temperature = 1.0 / temperature; // Invert
temperature -= 273.15; // convert absolute temp to C
Serial.print("Temperature ");
Serial.print(temperature);
Serial.println(" *C");
delay(2000);
}
The following version gives me no readings.
I want to change it to something like this:
#define ntc_pin A15 // Pin,to which the voltage divider is connected
//#define vd_power_pin 2 // 5V for the voltage divider
const int nominal_resistance = 50000; //Nominal resistance at 25⁰C
const int nominal_temeprature = 25; // temperature for nominal resistance (almost always 25⁰ C)
const int samplingrate = 5; // Number of samples
const int beta = 3970; // The beta coefficient or the B value of the thermistor (usually 3000-4000) check the datasheet for the accurate value.
const int Rref = 12000; //Value of resistor used for the voltage divider
int samples = 0; //array to store the samples
void setup(void) {
//pinMode(vd_power_pin, OUTPUT);
Serial.begin(115200); //initialize serial communication at a baud rate of 9600
}
// Working with single read Temperature seems off
void loop(void) {
float value;
value = analogRead(ntc_pin);
Serial.print("Analog Read: ");
Serial.println(analogRead(ntc_pin));
delay(10);
// Calculate NTC resistance
value = 1023 / value - 1;
value = Rref / value;
Serial.print("Thermistor resistance ");
Serial.println(value);
float temperature;
temperature = value / nominal_resistance; // (R/Ro)
temperature = log(temperature); // ln(R/Ro)
temperature /= beta; // 1/B * ln(R/Ro)
temperature += 1.0 / (nominal_temeprature + 273.15); // + (1/To)
temperature = 1.0 / temperature; // Invert
temperature -= 273.15; // convert absolute temp to C
Serial.print("Temperature ");
Serial.print(temperature);
Serial.println(" *C");
delay(2000);
}
any suggestions?