I am using an ATtiny84 to read a thermistor and print to a lcd. But, the temperature jumps around a lot. How can i get a more precise reading?
//THE THERMISTOR IS A 10K THERMISTOR
// DIAGRAM
// GROUND-----------10K RESISTOR-----------INPUT A0-----------10K THERMISTOR-----------5V
#include <LiquidCrystal.h>
LiquidCrystal lcd(0, 1, 2, 3, 4, 5);
int ValBL = 85; //Value for BackLight Brightness
int BackLight = 6; //BackLight PWM Output
int Thermostat = A7;
float ThermostatReading = 0;
float Res = 0;
float TempK = 0; //Tempature in K
float TempC = 0; //Tempature in C
float TempF = 0; //Tempature in F
float L1 = 0;
float L2 = 0;
float L3 = 0;
float L4 = 0;
float L5 = 0;
float AvgK = 0;
int Avg = 1; //Average the temp
void setup()
{
pinMode(BackLight, OUTPUT);
lcd.begin(16, 2);
analogWrite(BackLight, ValBL);
}
void loop()
{
Calibration();
Resistance();
Temperature();
Average();
Avg = Avg + 1;
delay(200);
}
//Averages the tempatures
void Average()
{
if (Avg == 1)
{
L1 = TempK;
}
if (Avg == 2)
{
L2 = TempK;
}
if (Avg == 3)
{
L3 = TempK;
}
if (Avg == 4)
{
L4 = TempK;
}
if (Avg == 5)
{
L5 = TempK;
AvgK = (L1 + L2 + L3 + L4 + L5);
AvgK = (AvgK / 5);
TempConver();
Avg = 1;
PrintTemp();
}
if (Avg <= 0 || Avg >= 6)
{
Avg = 1;
}
}
//Converts the reading to a resistance value
void Resistance()
{
Res = analogRead(Thermostat);
Res = 1023 / Res - 1;
Res = 10000 / Res;
}
//Calculate Tempatuere
void Temperature()
{
ThermostatReading = analogRead(Thermostat);
TempK = log(10000.0 * (1024.0 / ThermostatReading - 1));
TempK = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * TempK * TempK)) * TempK);
}
void TempConver()
{
TempC = AvgK - 273.15;
TempF = TempC * 1.8 + 32;
}
//Prints the Tempature and Resistance Output
void PrintTemp()
{
lcd.clear();
lcd.setCursor(2, 0);
lcd.print(Res);
lcd.print(" Ohm");
lcd.setCursor(0, 1);
lcd.print(TempC);
lcd.print("C");
lcd.setCursor(9, 1);
lcd.print(TempF);
lcd.print("F");
}
void Calibration()
{
if (AvgK == 0)
{
lcd.clear();
lcd.setCursor(2, 0);
lcd.print("CALIBRATING");
lcd.setCursor(2, 1);
lcd.print("CALIBRATING");
}
}