I don't have the materials to test my code out.
Materials needed to test this are:
= 2x LEDs
= 1x Thermister
= 2x Buttons
= 1x Breadboards
= 2x 220Ohm Resistance(for the LEDs)
= 3x 10KOhm Resistance(for the Buttons and Thermister)
= Cables
= 1x Arduino UNO
And here is my code layout for this task: -
const int ThermPin = A0;
const int rows = 10;
const int cols = 2;
const int ButtonPin = 6;
const int ButtonPin1 = 7;
int ButtonState = 0;
int ButtonState1 = 0;
const int LEDPin1 = 2;
const int LEDPin2 = 3;
int Table[rows][cols] ={ //col 0||col 1
{ 25, 4470 }, //row 0
{ 26, 4250 }, //row 1
{ 27, 4030 }, //row 2
{ 28, 3800 }, //row 3
{ 29, 3530 }, //row 4
{ 30, 3270 }, //row 5
{ 31, 3200 }, //row 6
{ 32, 3170 }, //row 7
{ 33, 3100 }, //row 8
{ 34, 3070 } //row 9
};
void setup(){
Serial.begin(9600);
pinMode(ButtonPin, INPUT);
pinMode(ButtonPin1, INPUT);
pinMode(LEDPin1, OUTPUT);
pinMode(LEDPin2, OUTPUT);}
//Displays the Lookup of the System(incl. The Value, Volt, & Resistance)
int getTempLookUp(int ThermPin){
//Declares the variables
float Vin = 5.0;
float ThermResist = 0.0;
float R2 = 10000.0;
float SensorValue = 0.0;
float Vout = 0.0;
//Declares the variables of the ThermPin & prints out the results based on the Thermister
SensorValue = analogRead(ThermPin);
Serial.println();
Serial.print("LookupValue = ");
Serial.print(SensorValue);
Vout = (((SensorValue+1)*Vin)/1024.0);
Serial.print("\t");
Serial.print("\t Voltage = ");
Serial.print(Vout);
Serial.print(" V");
ThermResist =((R2*Vin)/Vout)-R2;
Serial.print("\t");
Serial.print("\t Resistance = ");
Serial.print(ThermResist);
Serial.print(" Ohm");}
//Displays the Celcius based on the Array of the ThermResistance
int getTempCelc(int ThermPin){
//Declares the variables
float Vin = 5.0;
float ThermResist = 0.0;
float R2 = 10000.0;
float SensorValue = 0.0;
float Vout = 0.0;
//Calculates the voltage from the Sensorvalue of the Themister
SensorValue = analogRead(ThermPin);
Vout = (((SensorValue+1)*Vin)/1024.0);
ThermResist =((R2*Vin)/Vout)-R2;
//Call out the Table Array from the index
//And goes calls out the temperature values based on the ThermResistance
//Came out from the Thermister and prints out the results based on Celcius
for(int i; i<rows; i++){
if(ThermResist >= Table[i+1][1] && ThermResist <= Table[i][1] ){
Serial.println();
Serial.print("Array_Celcius = ");
Serial.print(Table[i][0]);
Serial.print(" C");
Serial.print("\t");}}}
//Displays the Kelvins based on the Array of the ThermResistance
int getTempKelv(int ThermPin){
//Declares the variables
float Vin = 5.0;
float ThermResist = 0.0;
float R2 = 10000.0;
float SensorValue = 0.0;
float Vout = 0.0;
//Calculates the voltage from the Sensorvalue of the Themister
SensorValue = analogRead(ThermPin);
Vout = (((SensorValue+1)*Vin)/1024.0);
ThermResist =((R2*Vin)/Vout)-R2;
//Call out the Table Array from the index
//And goes calls out the temperature values based on the ThermResistance
//Came out from the Thermister and prints out the results based on Kelvins
for(int i; i<rows; i++){
if(ThermResist >= Table[i+1][1] && ThermResist <= Table[i][1] ){
Serial.print("\t Array_Kelvins = ");
Serial.print(Table[i][0] + 273.15);
Serial.print(" K");
Serial.print("\t");}}}
int getTempFare(int ThermPin){
//Declares the variables
float Vin = 5.0;
float ThermResist = 0.0;
float R2 = 10000.0;
float SensorValue = 0.0;
float Vout = 0.0;
//Calculates the voltage from the Sensorvalue of the Themister
SensorValue = analogRead(ThermPin);
Vout = (((SensorValue+1)*Vin)/1024.0);
ThermResist =((R2*Vin)/Vout)-R2;
//Call out the Table Array from the index
//And goes calls out the temperature values based on the ThermResistance
//Came out from the Thermister and prints out the results based on Farenheit
for(int i; i<rows; i++){
if(ThermResist >= Table[i+1][1] && ThermResist <= Table[i][1] ){
Serial.print(" Array_Farenheit = ");
Serial.print( (Table[i][0] *9.0)/ 5.0 +32.0);
Serial.print(" F");}}}
//---------------------------------------------------------------------
//SteinHart's Style!
//Calculates the value from the Thermisters, converts it to Kelvins, and prints it out
int SteinHart_Kelvs(int ThermPin){
//Declares the variables
int SensorValue = analogRead(ThermPin);
float C1 = 1.346e-03;
float C2 = 2.309e-04;
float C3 = 9.815e-08;
float Rt = 10000.0;
float logRt = log(((10240000/SensorValue) - Rt));
float Temp = (1.0/(C1 + C2*logRt + C3*logRt*logRt*logRt));}
//Calculates the values called out from the previous function, converts it to Celcius, and prints it out
int SteinHart_Celcs_1(int ThermPin){
//Declares the variables
float Temp = SteinHart_Kelvs(ThermPin);
float Celcius = Temp - 273.15;}
//Calculates the values called out from the previous function, converts it to Farenheits, and prints it out
int SteinHart_Faren(int ThermPin){
//Declares the variables
float Temp = SteinHart_Celcs_1(ThermPin);
float Farenheit = ((Temp *9.0) /5.0 +32.0);}
int SH_Printout(int ThermPin){
float Temp = SteinHart_Kelvs(ThermPin);
float Temp_1 = SteinHart_Celcs_1(ThermPin);
float Temp_2 = SteinHart_Faren(ThermPin);
//Prints out the results
Serial.println();
Serial.print("SH_Kelvin = ");
Serial.print(Temp);
Serial.print(" K");
Serial.print("\t");
Serial.print("\t SH_Celcius = ");
Serial.print(Temp_1);
Serial.print(" C");
Serial.print("\t");
Serial.print("\t SH_Farenheit = ");
Serial.print(Temp_2);
Serial.println(" F");}
void loop()
{
ButtonState = digitalRead(ButtonPin);
ButtonState1 = digitalRead(ButtonPin1);
if(ButtonState == HIGH)
{
SH_Printout(ThermPin);
digitalWrite(LEDPin1, HIGH);
delay(100);
}
else
if(ButtonState == LOW)
{
digitalWrite(LEDPin1, LOW);
}
if(ButtonState1 == HIGH)
{
digitalWrite(LEDPin2, HIGH);
getTempLookUp(ThermPin);
getTempCelc(ThermPin);
getTempKelv(ThermPin);
getTempFare(ThermPin);
}
else
if(ButtonState1 == LOW)
{
digitalWrite(LEDPin2, LOW);
}
}
Thank you :).