So I'm breaking down my new program into chunks and am currently writing the chunk that will:
set RTC time
read RTC time and serial print (soon to be lcd print when my new lcd comes in the mail)
activate relay based on "minutes" data
The program works in that it will set time and print time but I am getting an error whenever I try to write code to activate the relay. Perhaps somebody can look at the code so far and enlighten me on the error that I keep getting.
#include <Time.h>
#include <Wire.h>
#include <DS3231RTC.h> // A simple DS3231 Library meant for use with Time.h also implements temp readings
const int RELAY1 = 22;
const int RELAY2 = 23;
const int RELAY3 = 24;
const int RELAY4 = 25;
void setup() {
Serial.begin(9600);
setTime(10,1,0,9,14,16);
}
void loop()
{
digitalClockDisplay();
delay(1000);
}
void digitalClockDisplay(){
// digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.print(" ");
Serial.print(day());
Serial.print(" ");
Serial.print(month());
Serial.print(" ");
Serial.print(year());
Serial.print(" ");
Serial.print(RTC.getTemp()); //These last few lines are the only other change to the the Time.h example!
Serial.print((char)223);
Serial.print('C');
Serial.println();
}
void printDigits(int digits){
// utility function for digital clock display: prints preceding colon and leading 0
Serial.print(":");
if(digits < 10)
Serial.print('0');
Serial.print(digits);
}
void fanTimer(){
if ( minute >= 0 && minute < 5)
{
digitalWrite ( RELAY2, HIGH );
}
else
{
digitalWrite ( RELAY2, LOW );
}
}
ERROR:
sketch_sep14c.ino: In function 'void fanTimer()':
sketch_sep14c.ino:49:22: error: invalid operands of types '' and 'int' to binary 'operator>='
sketch_sep14c.ino:49:36: error: invalid operands of types '' and 'int' to binary 'operator<'
Error compiling.
I dont get the errors you do when compiling for a UNO or an MKR but do get an error listed below.
"
D:\Sketches\T Sketches\Tester\sketch_sep14a\sketch_sep14a.ino:4:106: fatal error: DS3231RTC.h: No such file or directory
#include <DS3231RTC.h> // A simple DS3231 Library meant for use with Time.h also implements temp readings"
I compiled under IDE 1.6.11 and had installed the only two DS3231 libs available so in my case these dont match the lib you used otherwise things may be different.
Can you post the link to where you got the lib and the IDE you are using along with your OS version etc.
Thanks for the reply!
I am running this on a Mega2560 using Arduino 1.6.0 on OS 10.6.8
I'm not positive but I think this is the link to the library I'm using.
I am pretty limited to that IDE just because of how old my computer is.
Ballscrewbob:
I dont get the errors you do when compiling for a UNO or an MKR but do get an error listed below.
"
D:\Sketches\T Sketches\Tester\sketch_sep14a\sketch_sep14a.ino:4:106: fatal error: DS3231RTC.h: No such file or directory
#include <DS3231RTC.h> // A simple DS3231 Library meant for use with Time.h also implements temp readings"
I compiled under IDE 1.6.11 and had installed the only two DS3231 libs available so in my case these dont match the lib you used otherwise things may be different.
Can you post the link to where you got the lib and the IDE you are using along with your OS version etc.
Oh and well done for using tags
Thanks for the reply!
I am running this on a Mega2560 using Arduino 1.6.0 on OS 10.6.8
I'm not positive but I think this is the link to the library I'm using.
I am pretty limited to that IDE just because of how old my computer is.
Yup that lib throws up a lot of errors even compiled for a mega and it is a pretty old lib too.
Almost certain the issue is library related.
Using win 7 x64 here so we are not quite on the same page.
Maybe look for some other examples along with both the code and lib to match.
I also don't have 1.6.0 here so I cant reference what the lib manager is capable of.
Well I downloaded a much newer lib and made a small adjustment to the void fanTimer() section. Now I'm not getting any compiling errors but I am not getting any reaction on the hardware end. My serial is reading time correctly but I'm not getting any output the the relay.
Right now my setup is just a mockup with leds instead of getting the relays out but no fire.
#include <DS3232RTC.h>
#include <Time.h>
#include <Wire.h>
const int RELAY1 = 22;
const int RELAY2 = 23;
const int RELAY3 = 24;
const int RELAY4 = 25;
void setup() {
Serial.begin(9600);
setTime(10,1,0,9,14,16);
}
void loop()
{
digitalClockDisplay();
delay(1000);
}
void digitalClockDisplay(){
// digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.print(" ");
Serial.print(day());
Serial.print(" ");
Serial.print(month());
Serial.print(" ");
Serial.print(year());
Serial.print(" ");
Serial.print((char)223);
Serial.print('C');
Serial.println();
}
void printDigits(int digits){
// utility function for digital clock display: prints preceding colon and leading 0
Serial.print(":");
if(digits < 10)
Serial.print('0');
Serial.print(digits);
}
void fanTimer()
{
time_t t = now();
hour(t);
minute(t);
second(t);
if ( minute(t) >= 0 && minute(t) < 5)
{
digitalWrite ( RELAY2, HIGH );
}
else
{
digitalWrite ( RELAY2, LOW );
}
}
Your original problem with the "DS3231RTC" library was that this:-if ( minute >= 0 && minute < 5)should have been this:-if ( minute() >= 0 && minute() < 5)and also you didn't set up your relay output pin as an output with:-pinMode(RELAY2, OUTPUT);
In the more recent version of your code that you just posted, using the "DS3232RTC" library, you still don't make 'RELAY2' an output in 'setup()'. That won't be helping.
A last point. I see that you're currently using IDE V1.6.0, so you're getting away with this:-#include <Time.h>
If you upgrade to a recent version of the IDE, it will no longer work, and you'll need to change it to:-#include <TimeLib.h>and also download the latest version of the "Time" library.
(While using your current IDE version, you can still update the "Time" library then use either of the include lines). Then you're all set for when you do eventually upgrade.
After an IDE upgrade, you'll just need to change that include line and your code will work without problems.
@Cameronmw, (AKA cmwilliams), looks like you're cheating to me, using two different forum accounts to cross-post the same subject, once in "Programming Questions" then again here in "Project Guidance". That's just not on.
Why didn't you just stick to your first account and the one thread? All you're doing is confusing people.
Had I known this a few minutes ago, I wouldn't have wasted my time trying to help.