Hi all. I am building a control for a freezer. I need to start the freezer at the specified temp and shut off when that is satisfied. (I have that) What I'm having trouble with is, I need to have the compressor stay off for 3 minutes before starting again. This is a single stage freezer getting down to -50 F. It gets above the specified temp before 3 minutes and causes the compressor to attempt to come on and lock up. What I need, I think, is a way to override the if statement reading the probe, so the loop will not run until the 3 minutes have elapsed, without stopping the display from reading the temp. Thanks for any help.
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 3
#define ct 5
// Setup a oneWire instance to communicate with any OneWire devices
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
int offtime=1500;
void setup(void)
{ pinMode(ct, OUTPUT);
// start serial port
Serial.begin(9600);
Serial.println(" ColdTrap");
elapsedMillis elapsedTime; // used by elapsedmilis example
// Globally scoped - see comment above
unsigned long off = millis(); // used by millis() example...
unsigned int interval = 1000;
// Start up the library
sensors.begin();
}
void loop(void)
{ delay (offtime);
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
Serial.print(" ");
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.println(" ");
Serial.print(" ");
Serial.print(sensors.getTempFByIndex(0)); // Why "byIndex"?
// You can have more than one IC on the same bus.
// 0 refers to the first IC on the wire
{
{ if(sensors.getTempFByIndex(0) >= -50)
digitalWrite (ct, HIGH);
else
digitalWrite (ct, LOW);
I have tried delay but the code continues to run the if statment
Thanks again for any help
The blink without delay (in the IDE Files, Examples, Digital) and several things at a time examples will let you do timing without blocking.
When you shut the pump down, record the value of millis() [start time]. Then, where you decide to turn the pump back on, check that the current value of millis() minus the vaule of millis() when the pump was turned off [millis() - start time] is more than 3 minutes. If so, turn the pump on else don't.
Thanks groungfungus.
I took your advice and got this to work kind off. My first issue was that I was losing 10 seconds on the timing. I resolved that by adding 10 seconds to the interval. (is that normal, that the sketch takes that long to run)
My issue now is, no matter how long my freezer stays off, (over 3 min) the timer does not start until the probe calls for the freezer to start and waits another 3 mins.
The code says 1 min, but will be 3.
#include <elapsedMillis.h>
#include <DHT.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <OneWire.h>
#include <DallasTemperature.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
// Data wire is plugged into pin A4+A5 on the Arduino
#define ONE_WIRE_BUS 3
#define ct 5
#define DHTPIN 2 // what digital pin we're connected to
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
// Setup a oneWire instance to communicate with any OneWire devices
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
int offtime=1500;
unsigned long previousMillis = 0;
const long interval = 30000;
DHT dht(DHTPIN, DHTTYPE);
void setup(){
pinMode(ct, OUTPUT);
// start serial port
unsigned long currentMillis =millis();
unsigned long previousMillis = 0;
// Start up the library
sensors.begin();
lcd.init(); //initialize the lcd
lcd.backlight(); //open the backlight
}
void loop() { delay (offtime);
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius
float f = dht.readTemperature(true);
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
Serial.print(" ");
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.println(" ");
lcd.setCursor(0, 0); // set the cursor to column 3, line 0
lcd.print("ColdTrap"); // Why "byIndex"?
lcd.setCursor(14, 0); // set the cursor to column 3, line 0
lcd.print(sensors.getTempFByIndex(0)); // Why "byIndex"?
lcd.setCursor(0, 2); // set the cursor to column 3, line 0
lcd.print("Temp"); // Why "byIndex"?
lcd.setCursor(14, 2); // set the cursor to column 3, line 0
lcd.print(f); // Why "byIndex"?
lcd.setCursor(0, 3); // set the cursor to column 3, line 0
lcd.print("Humidity"); // Why "byIndex"?
lcd.setCursor(14, 3); // set the cursor to column 3, line 0
lcd.print(h); // Why "byIndex"?
{
unsigned long currentMillis =millis();
unsigned long interval = 70000;
if (sensors.getTempFByIndex (0) <=70.50)
digitalWrite(ct,LOW);
if (currentMillis - previousMillis >= interval) {
if (sensors.getTempFByIndex (0) >=70.50)
digitalWrite (ct,HIGH);
(previousMillis = currentMillis);
}}}
Thanks for any help