Skip to content

Instantly share code, notes, and snippets.

@markterrill
Created May 5, 2015 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markterrill/30e4e32192862addd47b to your computer and use it in GitHub Desktop.
Save markterrill/30e4e32192862addd47b to your computer and use it in GitHub Desktop.
Spark core Maverick ET73 probe
#include "math.h"
#define PROBE1 A7
#define DEBUG TRUE
#define SMOOTH TRUE
// Measure actual board voltage, from 3v3* to GND with voltage multimeter, it's rarely exactly 3.3
const float VREF = 3.3200;
// What resistor did you use from 3v3* to between the analog pin and positive pin of thermistor?
// Measure it with multimeter
const int RESISTOR = 19800;
// ADC chip cycles is 4096 - 1
const int ADC = 4095;
// Global vars in case we want to set them on the fly
double A, B, C;
void setup() {
// Start serial at 9600 baud
Serial.begin(9600);
// Forgot who
A = -2.20911E-06;
B = 7.02421E-04;
C = 1.99476E-05;
// 732 constants
A = 2.3067434E-4;
B = 2.3696596E-4;
C = 1.2636414E-7;
// Maverick ET-72/73 from heatermeter
A = 2.4723753e-4;
B = 2.3402251e-4;
C = 1.3879768e-7;
// From smartbbq
A = 0.00023067431;
B = 0.00023696594;
C = 1.2636415e-7;
// Coefficient calculator at http://www.rusefi.com/Steinhart-Hart.html
A = 4.97E-02;
B = -8.38E-03;
C = 3.87E-05;
}
void loop() {
double bbqTemp;
//Input = thermistor_temp(analogRead(PROBE1));
bbqTemp = thermistor_temp(PROBE1);
Serial.print("Temperature (C): ");
Serial.println(bbqTemp, 2);
delay(5000);
}
double thermistor_temp(int pin) { //Function to do theristor calculations
int aval;
double R, T;
if(DEBUG) {
Serial.println("============");
Serial.println();
Serial.print("aval (Pin ");
Serial.print(pin);
Serial.print("): ");
}
// read in smoothly
//TODO change to 90% median
if(SMOOTH) {
int total = 0;
for(int i=0; i<100; i++) {
total += analogRead(pin);
delay(1);
}
aval = total/100;
if(DEBUG) {
Serial.print(aval);
Serial.println(" (smooth)");
}
} else {
aval = analogRead(pin);
if(DEBUG) {
Serial.println(aval);
}
}
delay(500);
// What was the voltage that the pin saw?
// Calculate based on known ADC value and multimeter measured voltage from 3v3* to GND
// float casting is required as aval divided by ADC may result in a fraction
float Vout = (float) aval / (float) ADC * VREF;
if(DEBUG) {
Serial.print("/ ADC: ");
Serial.println(ADC);
Serial.print("* VREF ");
Serial.println(VREF, 3);
Serial.print("= Vout ");
Serial.println(Vout, 3);
}
delay(500);
// Calculate the original resistance
R = (RESISTOR * VREF / Vout) - RESISTOR;
if(DEBUG) {
Serial.println("--");
Serial.println("R = (RESISTOR * VREF / Vout) - RESISTOR");
Serial.print("RESISTOR: ");
Serial.println(RESISTOR);
Serial.print("R: (new) ");
Serial.println(R, 2);
}
delay(500);
// calculate log10(R)
R = log(R);
// Show it
if (DEBUG) {
Serial.print("log(R): ");
Serial.println(R);
}
delay(500);
if (DEBUG) {
Serial.println("--");
Serial.print("A: ");
Serial.println(A,14);
Serial.print("B: ");
Serial.println(B,14);
Serial.print("C: ");
Serial.println(C,14);
}
// Calculate temperature in Celsius
T = (1 / (A + B * R + C * R * R * R)) - 273.15;
// return degrees Celcius
return (T);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment