int ThermistorPin = 0; // Pin A0 is acting as Analog voltage input from Breadboard
int Vo;
float R1 = 10000; // 10 k-Ohm resistor
float logR2, R2, T, Tc, Tf; // defining variables
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;
const int Aled=8; // Aqua LED is connected to digital pin 8 on the Arduino
const int Rled=9; // Red LED is connected to digital pin 9 on the Arduino
void setup()
{
Serial.begin(9600); //communication speed btn PC and Microcontroller
pinMode(Rled, OUTPUT); //digital pin-9, Microcontroller (MC) is sending command out
pinMode(Aled, OUTPUT);//digital pin-8, Microcontroller (MC) is sending command out
}
void loop() {
Vo = analogRead(ThermistorPin); // Voltage stores as digital number in 'Vo'
R2 = R1 * (1023.0 / Vo - 1.0); // Voltage is converted to Resistance
logR2 = log(R2);// converts Resistance (R2) to Log (R2)
T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));// Resistance to Temp.(K) conversion
Tc = T - 273.15; // K to C conversion
Tf = (Tc * 9.0)/ 5.0 + 32.0; // C to F conversion
if (Tf>= 118) // means when T is >= 118 F
{
digitalWrite(Rled, HIGH); // command to turn RED LED ON
digitalWrite(Aled, LOW); // command to turn AQUA LED OFF
Serial.print(" RED LED IS ON; "); // command to print in the display
}
else // means when T is < 118 F
{
digitalWrite(Rled, LOW);
digitalWrite(Aled, HIGH);
Serial.print(" AQUA LED is ON; ");
}
Serial.print(" Temp.--> ");
Serial.print(Tf);
Serial.print(" F --> ");
Serial.print(Tc);
Serial.println(" C");
delay(200); // 200 miliseconds waits for the next loop
}