Apologies if this post is in the wrong section. this is m first project.
So I am working on a basic aquarium controller using an Arduino Uno to control LEDs via PWM according to time of day defined by RTC
I have started on the code with the help of the RTC Library, this prints to serial monitor the time each second as desired, i now wish to add an if statement.
eg;
IF [Time] = [Defined Time]
Turn LEDs On
So my first try was:
if (rtc.getTime()) == 12:00:00)
Serial.print("***LED ON***");
Serial.print('\n');
Note I will replace Serial.print once i get i working
It seems that whatever format i write the time it doesn't work. so I tried Unix time:
if (rtc.getUnixTime(rtc.getTime()) == 1459255200)
Serial.print("***LED ON***");
Serial.print('\n');
This worked but Unix time includes date too, which isn't very helpful as i want this to run at the same time every day.
Is there a way to use unix and ignore date? or a better way achieve this?
Thanks
See below my code so far:
// Aquarium Control // Dean Cohen //
// v0.1 Testing PWM control of LED Driver
// v0.2 Adding DS3231 RTC, Configuring date/time, Show in serial monitor
//Connect 'Dim' wire from LED Driver to pin 10
//Conect GND to Driver input GND
//Connect (RTC-Arduino): GND-GND, VCC-3.3v, SDA-A4, SCL-A5
#include <DS3231.h>
// Init the DS3231 using the hardware interface
DS3231 rtc(A4, A5);
int led = 10;
void setup() {
pinMode(led, OUTPUT);
Serial.begin(9600);
rtc.begin();
// The following lines can be uncommented to set the date and time
//rtc.setDOW(TUESDAY); // Set Day-of-Week to SUNDAY
//rtc.setTime(11, 47, 0); // Set the time to 12:00:00 (24hr format)
//rtc.setDate(29, 03, 2016); // Set the date to January 1st, 2014
}
void loop()
{
// Send Day-of-Week
Serial.print(rtc.getDOWStr());
Serial.print(" ");
// Send date
Serial.print(rtc.getDateStr());
Serial.print(" -- ");
// Send time
Serial.println(rtc.getTimeStr());
// Send Unix Time
Serial.print(rtc.getUnixTime(rtc.getTime()));
Serial.print('\n');
// Wait one second before repeating
delay (1000);
if (rtc.getUnixTime(rtc.getTime()) == 1459255200)
Serial.print("***LED ON***");
Serial.print('\n');
//PWM LED code ignored for now
//analogWrite(led, 64);
//delay(1000);
//analogWrite(led, 127);
//delay(1000);
//analogWrite(led, 191);
//delay(1000);
//analogWrite(led, 255);
//delay(1000);
}