I am totally new to programming and have been learning plenty just by playing with the kit. I am trying to control two digital outputs one for frost heat and one for main heater. I have two thermistor inputs and a four line lcd display unit. Line one is totally fine it shows the temperaure reading of the thermistor and the set point of the analogue input , the digital output switches when the temperaure is lower than the set point, however line two just isn't working, it is as if the loop stops as soon as it finishes the code for the main heater, it is probaly something really silly I am doing but I have tried loads to get it to work and no luck.
Any help would be greatly appreciated.
#define THERMISTOR_PIN A0
#define SET_POINT_PIN A1
#define DIGITAL_OUTPUT_PIN 13
#define THERMISTOR2_PIN A2
#define SET_POINT2_PIN A3
#define DIGITAL_OUTPUT2_PIN 6
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
void setup() {
lcd.begin(20, 4);
pinMode(DIGITAL_OUTPUT_PIN, OUTPUT);
pinMode(DIGITAL_OUTPUT2_PIN, OUTPUT);
Serial.begin(9600);
}
void loop() {
int thermistorReading = analogRead(THERMISTOR_PIN);
int setPointReading = analogRead(SET_POINT_PIN);
float temperature = calculateTemperature(thermistorReading);
float setPoint = calculateSetPoint(setPointReading);
double tempK = log(10000.0 * ((1024.0 / thermistorReading - 1)));
tempK = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * tempK * tempK )) * tempK ); // Temp Kelvin
float tempC = tempK - 273.15; // Convert Kelvin to Celcius
float tempF = (tempC * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
/* replaced
float tempVolts = tempReading * 5.0 / 1024.0;
float tempC = (tempVolts - 0.5) * 10.0;
float tempF = tempC * 9.0 / 5.0 + 32.0;
*/
// Display Temperature in C
float setPointdisplay = (setPoint);
lcd.setCursor(0, 0);
lcd.print("Temp: C ");
// Display Temperature in F
//lcd.print("Temp F ");
lcd.setCursor(5, 0);
// Display Temperature in C
lcd.print(tempC, 1);
// Display Temperature in F
//lcd.print(tempF);
// Display setpoint in C
lcd.setCursor(12, 0);
delay(500);
lcd.print("SP: C");
// Display Temperature in F
//lcd.print("Set F ");
lcd.setCursor(15, 0);
// Display Temperature in C
lcd.print(setPointdisplay, 0);
// Display Temperature in F
//lcd.print(tempF);
delay(500);
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.print(" Set point: ");
Serial.println(setPoint);
if (tempC < setPoint) {
digitalWrite(DIGITAL_OUTPUT_PIN, HIGH);
} else {
digitalWrite(DIGITAL_OUTPUT_PIN, LOW);
}
}
float calculateTemperature(int reading) {
float resistance = 10000.0 / ((1023.0 / reading) - 1.0);
float temperature = log(resistance / 10000.0) / 3950.0;
temperature = temperature + (1.0 / (25.0 + 273.15));
temperature = 1.0 / temperature;
temperature = temperature - 273.15;
return temperature;
}
float calculateSetPoint(int reading) {
float setPoint = map(reading, 0, 1023, 0, 50);
return setPoint;
{
{
int thermistorReading = analogRead(THERMISTOR2_PIN);
int setPointReading = analogRead(SET_POINT2_PIN);
float temperature = calculateTemperature(thermistorReading);
float setPoint2 = calculateSetPoint(setPointReading);
double tempK = log(10000.0 * ((1024.0 / thermistorReading - 1)));
tempK = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * tempK * tempK )) * tempK ); // Temp Kelvin
float tempC = tempK - 273.15; // Convert Kelvin to Celcius
float tempF = (tempC * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
/* replaced
float tempVolts = tempReading * 5.0 / 1024.0;
float tempC = (tempVolts - 0.5) * 10.0;
float tempF = tempC * 9.0 / 5.0 + 32.0;
*/
// Display Temperature in C
float setPointdisplay2 = (setPoint2);
lcd.setCursor(0, 1);
lcd.print("Temp: C ");
// Display Temperature in F
//lcd.print("Temp F ");
lcd.setCursor(5, 1);
// Display Temperature in C
lcd.print(tempC, 1);
// Display Temperature in F
//lcd.print(tempF);
// Display setpoint in C
lcd.setCursor(12, 1);
delay(500);
lcd.print("SP: C");
// Display Temperature in F
//lcd.print("Set F ");
lcd.setCursor(15, 1);
// Display Temperature in C
lcd.print(setPointdisplay2, 0);
// Display Temperature in F
//lcd.print(tempF);
delay(500);
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.print(" Set point: ");
Serial.println(setPoint);
if (tempC < setPoint) {
digitalWrite(DIGITAL_OUTPUT2_PIN, HIGH);
} else {
digitalWrite(DIGITAL_OUTPUT2_PIN, LOW);
}
}
float calculateTemperature2(int reading);
float resistance = 10000.0 / ((1023.0 / reading) - 1.0);
float temperature = log(resistance / 10000.0) / 3950.0;
temperature = temperature + (1.0 / (25.0 + 273.15));
temperature = 1.0 / temperature;
temperature = temperature - 273.15;
return temperature;
}
float calculateSetPoint(int reading);
float setPoint2 = map(reading, 0, 1023, 0, 50);
return setPoint2;
}