So I've posted about a similar project before, but have moved on and need a bit of advice. I have an arduino UNO, a DS18B20 probe, an LCD and an MDFLY 4CH Relay Control Board - Optical-Coupler Isolated. I have the programming now so the device will read which relay is on or off, the temp set so the the corresponding relay will turn ON or OFF at above or below a certain temp, but I cannot get them turn off in the middle ground.
Basically, I want the heater (relay2) to turn ON at 77 and turn OFF at 78 and the fan (relay1)to turn ON at 80 and OFF at 79. Right now the heater stays on until the fan turns on at 80.
Here is the code:
Basically, I want the heater (relay2) to turn ON at 77 and turn OFF at 78 and the fan (relay1)to turn ON at 80 and OFF at 79. Right now the heater stays on until the fan turns on at 80.
Here is the code:
Code:
#include <OneWire.h>
#include <Wire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>
//RGBLED
int bluePin1 = 10; //Digital Pin for blue LED1 in RGB-LED
int redPin1 = 12; //Digital Pin for red LED1 in RGB-LED
int redIn1 = 0;
int blueIn1 = 2;
int redVal1;
int blueVal1;
//Relays
int relPin1 = 2; //Digital Pin Relay1
int relPin2 = 3; //Digital Pin Relay2
//Heating Status
int heat1Val;
#define BACKLIGHT_PIN 13
#define ONE_WIRE_BUS 7
LiquidCrystal_I2C lcd(0x20,20,4); // set the LCD address to 0x20 for a 20 chars and 4 line display
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void setup() {
Serial.begin(9600);
sensors.begin();
lcd.init(); // initialize the lcd
lcd.backlight();
pinMode(relPin1, OUTPUT); //Output Mode for Relay1
pinMode(relPin2, OUTPUT); //Output Mode for Relay2
}
void loop() {
sensors.requestTemperatures();
float temperature1 = sensors.getTempFByIndex(0);
lcd.setCursor(0, 0);
lcd.print("Johnson's Reef");
lcd.setCursor(0, 1);
lcd.print("Aquarium: ");
lcd.print(sensors.getTempFByIndex(0));
lcd.print(" F ");
//HEATER
if(temperature1 < 77)
{
redVal1 = 0;
blueVal1 = 5;
digitalWrite(relPin1, LOW); //FAN
digitalWrite(relPin2, HIGH); //HEATER
lcd.setCursor(0, 2);
lcd.print("Heater: ON ");
lcd.setCursor(0, 3);
lcd.print("Fan: OFF ");
}
//FAN
else if(temperature1 > 80)
{
redVal1 = 150;
blueVal1 = 0;
digitalWrite(relPin1, HIGH); //FAN
digitalWrite(relPin2, LOW); //HEATER
lcd.setCursor(0, 2);
lcd.print("Heater: OFF ");
lcd.setCursor(0, 3);
lcd.print("Fan: ON ");
}
{
analogWrite(redPin1, redVal1);
analogWrite(bluePin1, blueVal1);
}
}