//*****************************Led Grow light Cree CXA3070 Diagnostic Circuit Breaker *********************************
//
//
//
//LIB
#include <LiquidCrystal.h>
#include <MAX31855.h>
//
//DEFs
#define SENSOR_SAMPLING_TIME 500 // 2 samples per sec
// DEG SYMB FOR LCD *****
unsigned char degree[8] = {
140,146,146,140,128,128,128,128};
//PINs
int relayPin = 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;
//VAR
double input;
unsigned long nextCheck;
unsigned long nextRead;
// Specify LCD interface
LiquidCrystal lcd(lcdRsPin, lcdEPin, lcdD4Pin, lcdD5Pin, lcdD6Pin, lcdD7Pin);
//TH.Couple Interface
MAX31855 thermocouple(thermocoupleSOPin, thermocoupleCSPin,thermocoupleCLKPin);
//SET-UP
void setup()
{
// Buzzer pin init / off
digitalWrite(buzzerPin, LOW);
pinMode(buzzerPin, OUTPUT);
// LED pins init/ on (active low)
digitalWrite(ledRedPin, LOW);
pinMode(ledRedPin, OUTPUT);
//relay pin
digitalWrite(relayPin,HIGH);
pinMode(relayPin, OUTPUT);
// Start-up splash
digitalWrite(buzzerPin, HIGH);
lcd.begin(8, 2);
lcd.createChar(0, degree);
lcd.clear();
lcd.print("CXA Diag");
lcd.setCursor(0, 1);
lcd.print("Loading");
digitalWrite(buzzerPin, LOW);
delay(2500);
lcd.clear();
// Turn off LED (active low)
digitalWrite(ledRedPin, HIGH);
// Initialize time keeping variable
nextCheck = millis();
// Initialize thermocouple reading variable
nextRead = millis();
}
//LOOP
void loop()
{
// Current time
unsigned long now;
// Time to read thermocouple
if (millis() > nextRead)
{
// Read thermocouple next sampling period
nextRead += SENSOR_SAMPLING_TIME;
input = thermocouple.readThermocouple(CELSIUS);
// If thermocouple problem detected
if((input == FAULT_OPEN) || (input == FAULT_SHORT_GND) ||
(input == FAULT_SHORT_VCC))
{ lcd.setCursor(1, 0);
lcd.print("! Sensor");
lcd.setCursor(0, 1);
lcd.print("Error !");
digitalWrite(buzzerPin, HIGH);
delay(500);
digitalWrite(buzzerPin, LOW);
}
else
if (millis() > nextCheck)
{
// Check input in the next500milsec
nextCheck += 500;
if ((input) <= 85 )
{
digitalWrite(relayPin,HIGH);
// Turn off LED (active low)
digitalWrite(ledRedPin,HIGH);
// Print current temperature
digitalWrite(buzzerPin, LOW);
lcd.clear();
lcd.setCursor(1, 0);
lcd.print("CXA Tc:");
lcd.setCursor(0, 1);
lcd.print(input);
// Print degree Celsius symbol
lcd.print(0,(uint8_t)0);
lcd.print("C ");
}
else
if ((input) >= 95 )
{
digitalWrite(relayPin, LOW);
lcd.clear();
lcd.setCursor(1, 0);
lcd.print("CAUTION:");
lcd.setCursor(0, 1);
lcd.print("CXA HOT!");
delay (1000);
lcd.clear();
lcd.setCursor(1, 0);
lcd.print("PWR OFF");
lcd.setCursor(0, 1);
lcd.print("PROTECT!");
delay (1000);
// Turn on LED (active low)
digitalWrite(ledRedPin,LOW);
digitalWrite(buzzerPin, HIGH);
delay(250);
digitalWrite(buzzerPin, LOW);
delay(2500);
}
}
}
}