// Thermistor readout to serial code: thermistor.ino #include "pins_EINSY_RAMBO.h" // Include the pin definitions for the Einsy Rambo board, sourced from the Marlin firmware // For a 100k NTC thermistor with 4.7k pull-up resistor: const float CELSIUS_TO_KELVIN = 273.15; // Absolute zero in Celsius const float PULLUP_RES = 4700; // the value of the resistor in series with the thermistor (usually 4.7k) const float V_REF = 5.0; // Reference voltage for the ADC (usually 5V) // For Beta thermistor calculations from Marlin: const float MARLIN_NOMINAL_RES = 100000; // Resistance at 25 degrees C const float MARLIN_NOMINAL_TEMP_C = 25; // Nominal temperature in Celsius const float MARLIN_BETA_K = 4092; // The beta coefficient of the thermistor from Marlin // For Beta thermistor calculation using my own values: const float NOMINAL_RES = 98000; // Resistance at 25 degrees C const float NOMINAL_TEMP_C = 25; // Nominal temperature in Celsius const float BETA_K = 3950; // The beta coefficient of the thermistor // For Steinhart-Hart calculations: const float A = 0.0006608622952; // Coefficient A for Steinhart-Hart equation const float B = 0.0002266935852; // Coefficient B for Steinhart-Hart equation const float C = 0.00000005819722188; // Coefficient C for Steinhart-Hart equation void setup() { Serial.begin(115200); // Start the serial communication at 115200 baud rate Serial.println("Thermistor Test"); pinMode(TEMP_0_PIN, INPUT); // Set the thermistor pin as input } void loop() { // Read the thermistor value from the analog pin int voltage = analogRead(TEMP_0_PIN); // Read the voltage from the thermistor float measuredVoltage = voltage * V_REF / 1023.0; // Convert ADC reading to actual voltage float resistance = (PULLUP_RES * measuredVoltage) / (V_REF - measuredVoltage); // Calculate the resistance of the thermistor // Calculate the temperature using the Steinhart-Hart equation float steinhart = 1.0 / (A + B * log(resistance) + C * pow(log(resistance), 3)); steinhart -= CELSIUS_TO_KELVIN; // Convert to Celsius Serial.print("Temperature from SH-H (C): "); Serial.println(steinhart); // Calculate the temperature using the Beta equations float tempK = 1.0 / (1.0 / (NOMINAL_TEMP_C + CELSIUS_TO_KELVIN) + (1.0 / BETA_K) * log(resistance / NOMINAL_RES)); tempK -= CELSIUS_TO_KELVIN; // Convert to Celsius Serial.print("Temperature from Beta (C): "); Serial.println(tempK); // Calculate the temperature using the Marlin beta equations float tempKMarlin = 1.0 / (1.0 / (MARLIN_NOMINAL_TEMP_C + CELSIUS_TO_KELVIN) + (1.0 / MARLIN_BETA_K) * log(resistance / MARLIN_NOMINAL_RES)); tempKMarlin -= CELSIUS_TO_KELVIN; // Convert to Celsius Serial.print("Temperature from Marlin Beta (C): "); Serial.println(tempKMarlin); delay(1000); }