Sketch :
//
//Thermocouple Type K Temperature Check & SSR Control
//2015 by SDS
//
//**LIBR**
#include <LiquidCrystal.h>
#include <MAX31855.h>
// ***** DEGREE SYMBOL FOR LCD *****
unsigned char degree[8] = {
140,146,146,140,128,128,128,128};
// ** PIN ASSIGNMENT **
int ssrPin = 5;
int thermocoupleSOPin = A3;
int thermocoupleCSPin = A2;
int thermocoupleCLKPin = A1;
int lcdRsPin = 7;
int lcdEPin = 8;
int lcdD4Pin = 9;
int lcdD5Pin = 10;
int lcdD6Pin = 11;
int lcdD7Pin = 12;
int ledRedPin = 4;
int buzzerPin = 6;
int switchPin = A0;
//**Variables-Constants**
unsigned long nextCheck;
unsigned long nextRead;
double input;
#define SENSOR_SAMPLING_TIME 250
//**INTERFACE**
LiquidCrystal lcd(lcdRsPin, lcdEPin, lcdD4Pin, lcdD5Pin, lcdD6Pin, lcdD7Pin);
MAX31855 thermocouple(thermocoupleSOPin, thermocoupleCSPin,thermocoupleCLKPin);
//
//**SET-UP**
void setup()
{
// SSR pin initialization
digitalWrite(ssrPin, LOW);
pinMode(ssrPin, OUTPUT);
// Buzzer pin initialization - buzzer off
digitalWrite(buzzerPin, LOW);
pinMode(buzzerPin, OUTPUT);
// LED pins initialization -turn on upon start-up (active low)
digitalWrite(ledRedPin, LOW);
pinMode(ledRedPin, OUTPUT);
// Start-up splash screen
digitalWrite(buzzerPin, HIGH);
lcd.begin(8, 2);
lcd.createChar(0, degree);
lcd.clear();
lcd.print("Type_Ktc");
lcd.setCursor(0, 1);
lcd.print("SDS_2015");
digitalWrite(buzzerPin, LOW);
delay(2500);
lcd.clear();
// Turn off LED (active low)
digitalWrite(ledRedPin, HIGH);
// **Initialize time keeping**
nextCheck = millis();
// **Initialize thermocouple reading **
nextRead = millis();
}
//
//**Loop**
//
void loop()
{
//** Current time**
unsigned long now;
// ** read thermocouple**
if (millis() > nextRead)
{
// ** next sample**
nextRead += SENSOR_SAMPLING_TIME;
// **Read current temperature**
input = thermocouple.readThermocouple(CELSIUS);
}
if (millis() > nextCheck)
{
// **Check input **
nextCheck += 250;
// **LCD**
lcd.clear();
lcd.print("Reading:");
lcd.setCursor(0, 1);
// **Show current temperature**
lcd.print(input);
#if ARDUINO >= 100
lcd.write((uint8_t)0);
#else
lcd.print(0, BYTE);
#endif
lcd.print("C ");
// **If thermocouple problem is detected**
if((input == FAULT_OPEN) || (input == FAULT_SHORT_GND) || (input == FAULT_SHORT_VCC))
{
lcd.clear();
lcd.print("Caution:");
lcd.setCursor(0, 1);
lcd.print("Error!");
digitalWrite(buzzerPin, HIGH);
delay (500);
digitalWrite(buzzerPin, LOW);
delay(2000);
}
}
//**SSR directive**(65°C Threshold)
if (input >=65)
{
digitalWrite(ssrPin, HIGH);
digitalWrite(buzzerPin, HIGH);
digitalWrite(ledRedPin, LOW);
delay (500);
digitalWrite(buzzerPin, LOW);
delay(500);
}
else
if (input < 65)
{
digitalWrite(ssrPin,LOW);
digitalWrite(buzzerPin,LOW);
digitalWrite(ledRedPin,HIGH);
}
//**Loop end**
}
//End