Go Down

Topic: Time/Temperature controlled Freezer help! (Read 1 time) previous topic - next topic

draythomp

Controlling power usage during the day has been a part-time project of mine for over a year now.  I had the problems with keeping track of time and approached it differently.  I created a clock to service all the devices in the house and hooked it to an XBee.  This little device provides time to all the other devices and gets the time from the GPS satellite system.  The devices themselves use the TimeAlarm library to set various alarms and timers for the particular appliance they control.  I started with my two heat pumps.  They use a huge amount of power during the cold winter (relatively) and hot summers (absolutely) and were sending me to the poor house.

I don't use a real time clock, simply because I didn't want to put one of them in every device in the house and then deal with checking on them all the time.  The TimeAlarm library is perfect (from my point of view) for this kind of thing.  Simply setting an alarm for when the power rates go up and then another for when the rates go down did the job very nicely.  You're welcome to steal any idea or piece of code from my site that discusses this desert-home.com

My particular implementation may not be what you need or want, but maybe it could provide some ideas you can use.
Trying to keep my house under control http://www.desert-home.com/

njsmith1

Hey guys, thanks for the replies, I did end up ordering the data logger shield and have it up and running. I have it getting temperature, the time, and also have the photo-resistor hooked up as it will let me know when someone has opened the door of the freezer. I'm down to writing the code to jump to the two functions that will set my temperature for Day and Night. This is what I have so far:

Code: [Select]
#include <Wire.h>
#include "RTClib.h"
#define aref_voltage 3.3

RTC_DS1307 RTC;

int tempReading;
int tempPin = 1;
int photocellReading;
int photocellPin = 2;

void setup () {
    Serial.begin(9600);
    Wire.begin();
    analogReference(EXTERNAL);
  }

void loop () {
   
    analogRead(photocellPin);
  delay(10);
  photocellReading = analogRead(photocellPin); 
 
  Serial.print("Light reading = ");
  Serial.print(photocellReading);     // the raw analog reading
 
  // We'll have a few threshholds, qualitatively determined
  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");
  }
 
  analogRead(tempPin);
  delay(10);
  tempReading = analogRead(tempPin); 
 
  Serial.print("Temp reading = ");
  Serial.print(tempReading);     // the raw analog reading
 
  // converting that reading to voltage, which is based off the reference voltage
  float voltage = tempReading * aref_voltage / 1024;

  // print out the voltage
  Serial.print(" - ");
  Serial.print(voltage); Serial.println(" volts");

  // 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");

  // now convert to Fahrenheight
  float temperatureF = (temperatureC * 9 / 5) + 32;
  Serial.print(temperatureF); Serial.println(" degrees F");

  DateTime now = RTC.now();
   
    Serial.print("The time is:");
    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 <= 19);   //If time is between 7am and 7pm print day time setting)
    {                                       //It will later call a function to check if the temp is between a value
      Serial.print("Day time setting");     // and then turn a relay on for the freezer if not the correct setting
    }
    else                                    // if it is not set to day time - set to night time. Which will call a function
    {                                       // that turns on the freezer if not the correct "Night time" temp.
      Serial.print("Night time setting");
    }
  }
}


I'm having problems with the if/else statement at the end of the code. I have it just printing what setting its at and then once this is working I will have it jump to that function which will then check what temperature it is at and set the relay of the freezer accordingly. When I compile, I get an error saying:

Complex_TempLight_Clock_pde:75: error: invalid use of member (did you forget the '&' ?)
Complex_TempLight_Clock_pde:79: error: 'else' without a previous 'if'

I know its just my code writing that's the error but I cant figure out how I should rewrite it.
Thanks alot for your help

draythomp

Quote

    if (now.hour >= 7 && now.hour <= 19);   //If time is between 7am and 7pm print day time setting)


try getting rid of the semicolon at the end of the if on this line.
Trying to keep my house under control http://www.desert-home.com/

njsmith1

I tried taking it out, and that is the line that is producing the error (highlighted yellow when I compile)

It still returned this error:
Complex_TempLight_Clock_pde:75: error: invalid use of member (did you forget the '&' ?)

draythomp

Original line:
Quote
if (now.hour >= 7 && now.hour <= 19);   //If time is between 7am and 7pm print day time setting)


I think it should look like this:


    if (now.hour() >= 7 && now.hour() <= 19)   //If time is between 7am and 7pm print day time setting)

Notice that new.hour() is a function that returns the hour, and the semicolon would have terminated the 'if' statement.
Trying to keep my house under control http://www.desert-home.com/

Go Up