Paul my good man, you are a champ haha. Let me explain - Running one program as a tester in which i change the code and see if it works or not, and then if it works, put it back into my main code. The code i last posted was the testing one in which i was attempting to display the status of the relay pin. Regardless After a bit more research I see the error in how I was trying to do it.
I also understand Global and Local scope better altho one question as a side not - you said
All the others are used only in loop() or functions called by loop(). Therefore, they should not be global in scope.
so does that mean that i can even move my " float temperatureC into the void loop? In other words even though temperatureC is called in the subroutine, it only needs to be declared locally?
Back to the problems that I am having - I measured the output voltage from the Digital I/O pin and it is 5 volts, and I rebuilt the circuit again, so there is no problem with the freezer. Ive gone over the code and over it and still don't understand what I am doing wrong. I changed the DAYHIGH, DAYLOW ect. to floating variable to give them decimal places like the temperature but even still it doesnt follow the routine. It just outputs a HIGH and doesn't change. Also when I change any of those parameters to a positive temperature (eg DAYHIGH 15.0 ) the arduino will not output anything at all. Could the delay be an issue?
Once again, thanks for your help - and here is the code
#include <Wire.h>
#include "RTClib.h"
#define NIGHTHIGH -19.0
#define NIGHTLOW -21.0
#define DAYHIGH 3.0
#define DAYLOW 2.0
#define aref_voltage 3.3
RTC_DS1307 RTC;
int relayPin = 6;
float temperatureC;
void setup()
{
Serial.begin(9600);
Wire.begin();
pinMode(relayPin, OUTPUT); // sets relay pin as output
analogReference(EXTERNAL);
}
void loop()
{
int tempReading;
int tempPin = 1;
int photocellReading;
int photocellPin = 2;
photocellReading = analogRead(photocellPin);
if (photocellReading < 10)
{
Serial.println("Dark");
}
else if (photocellReading < 200)
{
Serial.println("Dim");
}
else if (photocellReading < 500)
{
Serial.println("Light");
}
else if (photocellReading < 800)
{
Serial.println("Bright");
}
else
{
Serial.println("Very bright");
}
tempReading = analogRead(tempPin);
// converting that reading to voltage, which is based off the reference voltage
float voltage = tempReading * aref_voltage / 1024;
// now print out the temperature
float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset
//to degrees ((volatge - 500mV) times 100)
Serial.print(temperatureC);
Serial.println(" degrees C");
DateTime now = RTC.now(); // Get time from the RTC chip
Serial.print("Time:");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
delay(1000);
if (now.hour() >= 7 && now.hour() <= 18) //If time is between 7am and 7pm print Day time setting)
{
Daytime();
Serial.println("Temp set to -5'C"); // Display what Setting we are currently in
}
else //Else set to Night time setting
{
Nighttime();
Serial.println("Temp set to -20'C"); // Display what Setting we are currently in
}
}
void Nighttime()
{
if (temperatureC > (float)NIGHTHIGH) //Check temp and compare with setting and set the output accordingly
{
digitalWrite(relayPin, HIGH);
}
else if (temperatureC < (float)NIGHTLOW)
{
digitalWrite(relayPin, LOW);
}
}
void Daytime()
{
if (temperatureC > (float)DAYHIGH) //Check temp and compare with setting and set the output accordingly
{
digitalWrite(relayPin, HIGH);
}
else if (temperatureC < (float)DAYLOW)
{
digitalWrite(relayPin, LOW);
}
}