Control LED with arduino and chronodot

Hi,

I have a very basic and stupid question.
I have connected my arduino uno to chronodot. I can read and set the time and date on COM3.

Now I need to schedule a photoperiod in the LED connected to pin 9 for example.
I was looking for example but I am a little bit confused.

Do you have suggestions where to find a good tutorial or some example for this program.

Thank you

Valerio

If you can read the time, check periodically if the time is >= the time you want to start, and turn on the LED. Then check to see if the time is >= the time you want to start, and turn off the LED.

Thank you for the reply,

do you have an example of the sketch or a link to have more information?

Valerio

Search for time alarm library.

I search for timealarm library but I think in my case could be better to use a script as the following one.

In the future I need to modify light on /off in different manners that are not satisfied by timealarms.

I compiled the following script that work. I used very close timing for light on and off just to do some test.

at the first light on it works well, but then the light off is not respected and LEDs start to fade without a clear control.

could you help me to know what's wrong?

thank you

#include <Wire.h>
#include "Chronodot.h"

Chronodot RTC;

void setup () {
Serial.begin(9600);
Serial.println("Initializing Chronodot.");

Wire.begin();
RTC.begin();

RTC.adjust(DateTime(2013,10,21,10,30,00)); // IMPORTANT ADJUST YOUR TIME BEFORE STARTING!!!!

}

void loop () {

DateTime now = RTC.now();
int ledPin = 9;

Serial.print(now.year(), DEC);
Serial.print('/');
if(now.month() < 10) Serial.print("0");
Serial.print(now.month(), DEC);
Serial.print('/');
if(now.day() < 10) Serial.print("0");
Serial.print(now.day(), DEC);
Serial.print(' ');
if(now.hour() < 10) Serial.print("0");
Serial.print(now.hour(), DEC);
Serial.print(':');
if(now.minute() < 10) Serial.print("0");
Serial.print(now.minute(), DEC);
Serial.print(':');
if(now.second() < 10) Serial.print("0");
Serial.print(now.second(), DEC);
Serial.println();

Serial.print(now.tempC(), 1);
Serial.println(" degrees Celcius");
Serial.print(now.tempF(), DEC);
Serial.println(" degrees Farenheit");

Serial.println();
delay(5000); //the time and temperature is writed on serial port every 5 seconds

if ((now.hour() >= 10 && now.minute() >= 31 && now.second() >= 0)) {

for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {

analogWrite(ledPin, fadeValue);

delay(500); // just for example

}
}

if ((now.hour() >= 10 && now.minute() >= 35 && now.second() >= 0)) {

for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {

analogWrite(ledPin, fadeValue);

delay(500); // just for example

}
}

}

thank you for the help, I solved the problem!

this is the code I am using

#include <Time.h>
#include <TimeAlarms.h>

void setup()
{
Serial.begin(9600);
setTime(8,29,0,1,1,11);

Alarm.alarmRepeat(8,30,0, MorningAlarm);
Alarm.alarmRepeat(8,31,0, EveningAlarm);
}

void loop(){
digitalClockDisplay();
Alarm.delay(1000);
}

void MorningAlarm(){

int ledPin = 9;

for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {

analogWrite(ledPin, fadeValue);

delay(300);

Serial.println("LIGHT ON");
}
}

void EveningAlarm(){

int ledPin = 9;
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {

analogWrite(ledPin, fadeValue);

delay(300);

Serial.println("LIGHT OFF");
}
}

void digitalClockDisplay()
{

Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.println();
}

void printDigits(int digits)
{
Serial.print(":");
if(digits < 10)
Serial.print('0');
Serial.print(digits);
}