Hi, this a refrigeration control using an arduino mega, and lcd , and 8relay board and a power source.
We use the arduino to control a refrigeration chiller… so, the temperature range is between 3 and 5C… the problem is the arduino freeze on some point during the refrigeration cycle making the temperature drops even as low as -9C…
I installl the control and was working fine until past yesterday, wen the chiller star to frezee…
I have some problems earlier with the contacts opening and generating an spark and frezing the arduino, but after install some snubbers everything works fine, until know…
I add a reset each 5 refrigeration cycles, using something like this;
http://weblog.jos.ph/development/arduino-reset-hack/
I know isnt the best solution, but I was consider the sotware doing domething wrong… But even after this, The program frezees at a random point. So …
I enable the relay configuration for opto/coupled like is described here
https://arduino-info.wikispaces.com/RelayIsolation
Know I have leave the system for a test run today and tomorrow… Searching there it was some troubles with IC2 screens and the add a transistor to activate the relay, unfortunately there is no diagram,there was a mention to a small transistor and a small capacitor. I dont know if its necesary, or only the optocuplers o the relay board will do the trick.
Know for a more robust control Im thinking on add a arduino promini and a separate temperature probe to some sort of “hardware reset”… if the pro-mini sees the temperature going low or high than
the pre-programed, will set the reset the pin of the control board, this will have the advantage of
have an added safety, never the least i leave my current code in here, to see if there is anything I may doing wrong.
Is there a more robust way to enable the relays, to avoid the HV peaks freexing the arduino?
In
//=====================================LIBRERIAS==================================================//
#include <Wire.h>
#include <OneWire.h>
#include <dht.h> //Libreria para DTH
#include <DallasTemperature.h> //Libreria Ds1820
#include <LiquidCrystal_I2C.h> //Libreria IC2
//#define WDT0_8S 8
//=====================================COSNTRUCTORES =============================================//
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
#define ONE_WIRE_BUS 2 //Pin Sensor temperatura
OneWire oneWire(ONE_WIRE_BUS); //define un bus para comunicarse con cualquier sensor
DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature.
DeviceAddress insideThermometer; // arrays to hold device address
//=====================================VARIABLES GLOBALES=========================================//
const byte resetPin = 12;
const byte solenoid = 4;
const byte compressor = 5;
const byte dif1 = 6;
const byte dif2 = 7;
const byte ledSol = 8;
const byte ledcomp = 9;
const byte ledDif1 = 10;
const byte ledDif2 = 11;
float tempC = 0; //lectura del termometro
float newTemp = 1; //lectura para revisar si hay cambio y reimprimir la temperatura
byte resetVar = 0;
unsigned long compDelay = 5000;
unsigned long compTime = 0;
unsigned long compPastTime = 0;
boolean wasOn = true;
//variables to startCompressor soubrotine------------------
byte ofcomp = 0; // rool over from 0 to 4
boolean compressorBegin = true;
unsigned long compSMtime = 0;
unsigned long compSMdelay = 1500;
//variables de pantalla de bienvenida ---------------------
unsigned long bienvenidaT = 0;
unsigned long bienvenidaDelay = 3000;
unsigned long bienvenidaStart = 0;
byte bienvenidaVar= 0;
byte pasBievenida = 0;
boolean prueba = false;
//variables to OffCompressor soubrotine------------------
byte offSystem = 0;
boolean compressorStop = true;
unsigned long compOfftime = 0;
unsigned long compOffdelay = 00;
unsigned long OFFScreenTime =2000;
byte OFFcomp = 0;
byte pastOFFcomp = 0;
byte var = 1;
//=====================================VOID SET UP ==================================================//
void setup(void)
{
digitalWrite(resetPin, HIGH);
delay(250);
Serial.begin(9600);
lcd.begin(20,4);
pinMode(resetPin, OUTPUT);
pinMode(solenoid, INPUT_PULLUP);
pinMode(compressor, INPUT_PULLUP);
pinMode(dif1, INPUT_PULLUP);
pinMode(dif2, INPUT_PULLUP);
pinMode(ledSol, INPUT_PULLUP);
pinMode(ledcomp , INPUT_PULLUP);
pinMode(ledDif1 , INPUT_PULLUP);
pinMode(ledDif2 , INPUT_PULLUP);
pinMode(ledSol,OUTPUT);
pinMode(ledcomp,OUTPUT);
pinMode(ledDif1,OUTPUT);
pinMode(ledDif2,OUTPUT);
pinMode(solenoid, OUTPUT);
pinMode(compressor, OUTPUT);
pinMode(dif1, OUTPUT);
pinMode(dif2, OUTPUT);
digitalWrite(solenoid, HIGH);
digitalWrite(compressor, HIGH);
digitalWrite(dif1, HIGH);
digitalWrite(dif2, HIGH);
digitalWrite(ledSol, HIGH);
digitalWrite(ledcomp, HIGH);
digitalWrite(ledDif1, HIGH);
digitalWrite(ledDif2, HIGH);
//-----------------------------------SENSOR DS1820-------------------------------------------------//
// locate devices on the bus
sensors.begin();
Serial.print(sensors.getDeviceCount(), DEC);
//Linea para debug
if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0");
Serial.print("Device 0 Address: ");
//Funcion para imprimir la direccion del dispositivo --printAddress(insideThermometer);
// set the resolution to 9 bit (Each Dallas/Maxim device is capable of several different resolutions)
sensors.setResolution(insideThermometer, 10);
bienvenida();
//wdt_enable(WDT0_8S);
}
void loop (){
if(resetVar >= 5) DoReset(); //this will reset the micro each x times
Serial.print("The program has run "); Serial.print(resetVar); Serial.println(" Times");
if(tempC <= 3.5) turnOffCompressor();
Serial.println("Safe is on");
sensors.requestTemperatures(); // Comando para obtener temperatura
printTemperature(insideThermometer); // print the data on var tempC
if(tempC != newTemp ) //just print the temperature if has changue
{
tempScreen();
Serial.print("nueva temperatura ");
newTemp = tempC;
}
// if(tempC >= 6.5 && tempC >= 7.00)
if(tempC >= 4.5 && tempC >= 5.00)
{
turnOnCompressor();
}
// if(tempC <= 3.00 && tempC <= 3.5)
if(tempC <= 3.50 && tempC <= 4.50)
{
turnOffCompressor();
}
compTime = millis(); //keep ticking the clokc
}
//-------------- function to print the temperature for a device
void printTemperature(DeviceAddress deviceAddress)
{
tempC = sensors.getTempC(deviceAddress);
}
void tempScreen()
{
lcd.clear();
lcd.setCursor(0,0); lcd.print(" CAMARA 5");
lcd.setCursor(0,1); lcd.print(" Temperatura");
lcd.setCursor(7,2); lcd.print(tempC);
Serial.print("Temp C: "); Serial.print(tempC); Serial.println(" ");
}
void DoReset(){
digitalWrite(resetPin, LOW);
}
Thanks ins advance.
-Alex.
PD… there is a lot of unsigned long variables to handle the screen changes and in the last time they were eliminated for some simple.