I am using a uLCD32-PTu on an Arduino Nano with 3 Dallas Temperature DS18B20 sensors and a 2 Channel Sainsmart relay board.
Everything about my project works just fine, however, upon start-up and after the setup portion of my Arduino code has completed it's cycle, my relays both turn on and stay on until otherwise commanded to turn off through manual slider value adjustment, thereby activating the if statements. I have not added any statements to my code that would command the relays to go HIGH until the corresponding Slider reported it's first message.
How can I keep both relays off until the temperature reaches the preset slider temperature without any interaction with the device after start-up?
As you can tell from my code, I am setting my preset value from the Arduino itself upon start-up. All the controls on the LCD are for user adjustment IF preferred, but I want it to be a plug and play kind of thing.
Here is my Arduino code, let me know if you need any more than this to help me fix this issue... Thanks in advance!
#define CHANNEL1 8 //fan
#define CHANNEL2 9 //Valve
#include <genieArduino.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 3
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
DeviceAddress basementTemp = { 0x28, 0xB6, 0x58, 0x66, 0x04, 0x00, 0x00, 0x07}; //BLUE wire Dallas
DeviceAddress furnaceWater = { 0x28, 0xCB, 0x4F, 0x66, 0x04, 0x00, 0x00, 0xF8}; //GREEN wire Dallas Temperature Sensor address
DeviceAddress houseWater = { 0x28, 0xDE, 0x57, 0x66, 0x04, 0x00, 0x00, 0x0A}; //GREEN wire Dallas
//int tempLeeway = 5; //Temperature buffer for relay so it won't flip on and off all the time
float sliderPreset1 = 80;//Preset slider values so you don't have to set values manually upon start-up and relays stay off until temp sensor reaches this number
float sliderPreset2 = 81;//Ditto
int slider0_val;//Set point
int slider1_val;//Set point
int t, temp;//for celcius to fehrenheit conversion
void setup()
{
pinMode(CHANNEL1, OUTPUT); //Low Speed Fan RELAY
pinMode(CHANNEL2, OUTPUT); //High Speed Fan RELAY
genieBegin (GENIE_SERIAL, 56000); //Serial1
genieAttachEventHandler(myGenieEventHandler);
//genieSetup(9600); //Make sure this is the same baud rate of the LCD and the genieBegin command.
sensors.begin();
sensors.setResolution(basementTemp, 10);
sensors.setResolution(furnaceWater, 10);
sensors.setResolution(houseWater, 10);
//Reset the Display (change D4 to D2 if you have original 4D Arduino Adaptor)
pinMode(4, OUTPUT); // Set D4 on Arduino to Output (4D Arduino Adaptor V2 - Display Reset)
digitalWrite(4, 1); // Reset the Display via D4
delay(100);
digitalWrite(4, 0); // unReset the Display via D4
delay (3500); //let the display start up
genieWriteObject(GENIE_OBJ_LED_DIGITS, 6, sliderPreset1);//TEST
genieWriteObject(GENIE_OBJ_SLIDER, 0, sliderPreset1);//TEST
genieWriteObject(GENIE_OBJ_LED_DIGITS, 5, sliderPreset2);
genieWriteObject(GENIE_OBJ_SLIDER, 1, sliderPreset2);//TEST
}
void loop()
{
//digitalWrite(CHANNEL1, LOW); //Test to see if this will keep relay off until temps reach preset point... FAIL....
static long waitPeriod = millis();
genieDoEvents();
//Read from sensor every 100ms and write to the display
if (millis() >= waitPeriod)
{
temp = (t * 1.8) + 32; //Convert *C to *F.
float basement = sensors.getTempF(basementTemp);
float furnace = sensors.getTempF(furnaceWater);
float waterHeater = sensors.getTempF(houseWater);
//float tempC = sensors.getTempC(insideThermometer);
float tempF;
sensors.requestTemperatures();
//genieWriteObject(GENIE_OBJ_LED_DIGITS, 1, basement);//The first line of code in the section gets ignored for some reason...?? copy and paste
genieWriteObject(GENIE_OBJ_LED_DIGITS, 1, basement);/
genieWriteObject(GENIE_OBJ_LED_DIGITS, 0, waterHeater);
genieWriteObject(GENIE_OBJ_LED_DIGITS, 2, basement);
genieWriteObject(GENIE_OBJ_LED_DIGITS, 3, furnace);
genieWriteObject(GENIE_OBJ_LED_DIGITS, 7, waterHeater);
waitPeriod = millis() + 10; // rerun this code in another 100ms time.
if (slider0_val > basement)//For some reason it's responding in polar opposites of the command?
{
digitalWrite(CHANNEL1, HIGH);
}
else
{
digitalWrite(CHANNEL1, LOW);
}
/////////////////////////////////////////////////////
if (slider1_val > waterHeater)
{
digitalWrite(CHANNEL2, HIGH);
}
else
{
digitalWrite(CHANNEL2, LOW);
}
}//Closes Millis
}//Closes Loop
void myGenieEventHandler(void)
{
genieFrame Event;
genieDequeueEvent(&Event);
//If the cmd received is from a Reported Event
if (Event.reportObject.cmd == GENIE_REPORT_EVENT)
{
if (Event.reportObject.object == GENIE_OBJ_SLIDER) // If the Reported Message was from a Slider
{
if (Event.reportObject.index == 0) // If Slider0
{
slider0_val = genieGetEventData(&Event); // Receive the event data from the Slider0
}
}
}
//If the cmd received is from a Reported Event
if (Event.reportObject.cmd == GENIE_REPORT_EVENT)
{
if (Event.reportObject.object == GENIE_OBJ_SLIDER) // If the Reported Message was from a Slider
{
if (Event.reportObject.index == 1) // If Slider1
{
slider1_val = genieGetEventData(&Event); // Receive the event data from the Slider1
}
}
}
//If the cmd received is from a Reported Object, which occurs if a Read Object is requested in the main code, reply processed here.
if (Event.reportObject.cmd == GENIE_REPORT_OBJ)
{
//Put code in here, like the above, if you want to process data when you have used a genieReadObject in your main loop
//Currently there are none, so this section has no code.
//Filter out the Object and the Index like above, and then same the data into a variable as required.
}
}