#include <Wire.h>
#include <LiquidCrystal_I2C.h>
//float SteinhartHart_rFood, SteinhartHart_rDome;
float Steinhart_rFood, Steinhart_rDome;
LiquidCrystal_I2C lcd(0x27, 16, 2);
int adcFood;
int adcDome;
int rFood;
int rDome;
// Measured values of the "bb-22" temp probe
const float measured_T[] =
{0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 105, 110, 115, 120, 125, 130, 135, 140, 145, 150, 155, 160, 165, 170, 175, 180, 185, 190, 195, 200, 205, 210, 215, 220, 225, 230, 235, 240, 245, 250};
const float measured_R[] =
{270E+3, 205E+3, 165E+3, 134E+3, 105E+3, 84E+3, 67.7E+3, 53E+3, 43E+3, 36.8E+3, 31.1E+3, 25.4E+3, 19, 7E+3, 16.2E+3, 12.7E+3, 11.2E+3, 10.2E+3, 9E+3, 8E+3, 7.2E+03, 6.7E+03, 4.55E+03, 4.2E+03, 3.6E+03, 3.15E+03, 2.75E+3, 2.41E+3, 2.12E+3, 1.85E+3, 1.62E+3, 1.43E+3, 1.26E+3, 1.1E+3, 980, 880, 780, 700, 615, 550, 495, 450, 405, 370, 330, 300, 275, 250, 230, 215, 200, 185};
// Using: http://www.thinksrs.com/downloads/programs/Therm%20Calc/NTCCalibrator/NTCcalculator.htm
const float A = 0.9382E-3;
const float B = 1.804E-4;
const float C = 2.2348E-7;
const float beta = 3874.89; // This is the 'beta', not the 'B'.
// The resistance at 25 degrees is also taken from that thinksrs page.
const float ntc_nominal_T = 25.0;
const float ntc_nominal_R = 91312.23; // It is probably a 210k NTC resistor
// Pins
const int probeFoodPin = 33;
const int probeDomePin = 34;
// Values for the series resistor to 5V
const float series_resistor = 22E+3; // 22k
void setup()
{
Serial.begin(115200);
lcd.begin();
lcd.setCursor(5, 0);
lcd.print("Hello");
Serial.println("Hello" );
delay(2000);
lcd.setCursor(5, 1);
lcd.print("World");
Serial.println("World" );
delay(3000);
lcd.clear();
for (int i = 0; i < sizeof(measured_T) / sizeof(float); i++)
{
// Calculate what the ADC value would be with this resistor value.
// Simulate the ADC, by rounding to lower integer with floor().
float adc = floor(measured_R[i] / (measured_R[i] + series_resistor) * 4095.0);
// Calculate the resistance value of the NTC thermistor
float r = series_resistor / ((4096.0 / (adc + 0.5)) - 1.0);
}
}
void loop()
{
// Calculate the resistance value of the NTC thermistor
float adcFood = getADC(probeFoodPin);
float adcDome = getADC(probeDomePin);
rFood = series_resistor / ((4096.0 / (adcFood + 0.5)) - 1.0);
rDome = series_resistor / ((4096.0 / (adcDome + 0.5)) - 1.0);
delay(75);
lcd.setCursor(4, 0);
lcd.print(" ");
lcd.setCursor(5, 0);
lcd.print("\337C");
lcd.setCursor(14, 0);
lcd.print("\337C");
lcd.setCursor(4, 1);
lcd.print(" ");
lcd.setCursor(5, 1);
lcd.print("\337C");
lcd.setCursor(15, 1);
lcd.print("%");
lcd.setCursor(0, 1);
lcd.print("23");
lcd.print(" ");
Serial.print("Food: ");
Serial.println(adcFood);
Serial.print("Dome: ");
Serial.println(adcDome);
if (adcFood < 10.0 || adcFood > 3900.0)
{ //4021
lcd.setCursor(9, 0);
lcd.print("---");
lcd.print(" ");
}
else
{
lcd.setCursor(9, 0);
lcd.print(SteinhartHart(rFood), 1);
lcd.print(" ");
}
if (adcDome < 10.0 || adcDome > 3900.0)
{ //4021
lcd.setCursor(0, 0);
lcd.print("---");
lcd.print(" ");
}
else
{
lcd.setCursor(0, 0);
lcd.print(SteinhartHart(rDome), 0);
lcd.print(" ");
}
}
float getADC(int pin)
{
// About 60 samples fit into a unsigned int.
// Therefor the 'n' should be not above 60.
int n = 20; // maximum 60
unsigned int total = 0;
for (int i = 0; i < n; i++)
{
total += analogRead(pin);
}
float adc = (float)total / (float)n;
return (adc);
}
float SteinhartHart(float r)
{
float t1 = log(r);
float t2 = C * t1 * t1 * t1;
float t3 = A + (B * log(r)) + t2;
return ((1.0 / t3) - 273.15) - 4.0;
}