This should be a walk in the park for the experienced Arduino programmer. I am still relatively new to the C++ language and I'm getting confused... Though I am probably still regarded as a "noob", I am experienced enough to know that I have all my libraries, sensors, and sensor addresses correctly applied and I will explain my situation further..
My project is simple enough. If the INSIDE temperature is less than the OUTSIDE temperature(or vice verses depending on the weather or your personal preference..) then flip a single relay, or multiple relays, either on or off, according to your preference. Easy right? My serial monitor works perfectly showing real time data from each sensor and I can even throw in some commands for the relays if I want.
The problem I am running into is this: My program looks straight forward enough, however, the "if" command portion at the end of the chain is completely ignored by my arduino.
This portion is my problem...
if (inside >= outside) //<-- The inside of the parentheses is my problem
{
digitalWrite(CHANNEL1, LOW);
delay(4000);
digitalWrite(CHANNEL1, HIGH);
}
I am assuming this has something to do with a lack of "int" or "float" line for each individual sensor in order for the controller to be able to function the way I want it too, but like I said, I'm new to this and I don't know the proper way to set up this kind of sensor as an int or float. Yes, I have tried replacing:
if (inside >= outside) with if (int(inside) >= int(outside))
yet the problem still persists.
If someone who has done this before could show me how to complete this code I would really appreciate it!!!
XD
FULL CODE...
#define CHANNEL1 13//RelayIN1
#define CHANNEL2 12//RelayIN2
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into pin 3 on the Arduino
#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 inside = { 0x28, 0xB3, 0x58, 0x66, 0x04, 0x00, 0x00, 0xEC };
DeviceAddress outside = { 0x28, 0x12, 0x31, 0x66, 0x04, 0x00, 0x00, 0x65 };
void setup()
{
// start serial port
Serial.begin(9600);
// Start up the library
sensors.begin();
// set the resolution to 10 bit (good enough?)
sensors.setResolution(inside, 10);
sensors.setResolution(outside, 10);
Serial.begin(9600);
pinMode(CHANNEL1, OUTPUT);
pinMode(CHANNEL2, OUTPUT);
Serial.println("Ready. Type 0 to reset all relays, 1 - 4 to activate a relay.");
}
void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00) {
Serial.print("Error getting temperature");
} else {
Serial.print("C: ");
Serial.print(tempC);
Serial.print(" F: ");
Serial.print(DallasTemperature::toFahrenheit(tempC));
}
}
void loop() {
delay(2000);
//Serial.print("Getting temperatures...\n\r");
sensors.requestTemperatures();
Serial.print("Inside: ");
Serial.print(int(inside));
printTemperature(inside);
Serial.print("\n\r");
Serial.print("Furnace: ");
Serial.print(int(outside));
printTemperature(outside);
Serial.print("\n\r");
if (inside >= outside)
{
digitalWrite(CHANNEL1, LOW);
delay(4000);
digitalWrite(CHANNEL1, HIGH);
}
}