DesignInstinct
Member
Total noob here. It's ok if you groan, I can't hear you over the internet 
But seriously....I appreciate all comments on the following post..
I may want to move this project over from Arduino to Teensy.
Seems cooler. Also much smaller footprint.
It's a sunrise/sunset + 'night' simulator for 'light therapy' that controlls LED lighting strips with a cheap COTS RGB Amplifier/controller:
www.amazon.com/TaoTronics-Repeater-Amplifier-Strips-Connectors/dp/B0081CZJGO
This is a slick way to power the LED strips and Arduino off one box.
I use a small UPS battery to power it all right now.
I'm using the Sain Smart Arduino MEGA R3 and their RTC board (just because I have them):
www.amazon.com/SainSmart-DS1307-AT24C32-memory-Arduino/dp/B00E37VTWY
Using these libraries:
http://playground.arduino.cc/uploads/Code/Time.zip
http://www.pjrc.com/teensy/arduino_libraries/DS1307RTC.zip
http://swfltek.com/arduino/timelord.html
TimeLord is outdated, but the code I got from another astro timer project using it works:
http://paulorenato.com/joomla/index...matic-light-control&catid=4:projects&Itemid=4
I took out all his code related to 7 segment displays and buttons....with a noob machete.
He was using digitalWrite to switch a relay (LED 13 in his publicly shared code).
His only line of code that seemed to "control" the LED was:
I rewrote that line to control the RGB amplifier/controller with analogWrite.
The RGB controller works 'backwards' (0 is 'on', 255 is 'off')
Explanation here:
http://www.instructables.com/id/LED-Strip-Controller-w-LED-Amp-Arduino/
My LED strips control perfectly with any existing code.
I can pulse them, on/off...strobe them really fast etc.
Works perfect.
I set the RTC board with current time, then load my DawnDusk sketch.
The serial monitor shows everything working fine. Time is correct.
I can only get the sunset trigger to work. LED strip clicks on perfect.
LED does *not* turn off at dawn.
Yes, I have no idea about coding. Just working from the seat of my pants.
Any hints would be appreciated. I'm pretty sure it's a *really* noob mistake.
My other question, can the TimeAlarms library do some of this more precisely?
Eventually I want to do this 'scripted performance':
30 min before dawn...long ramp up brightness (analogWrite 255-0 / linear fade code etc.)
Fade lights quick 30-60 mins after dawn.
Wait till 30 mins before sunset, begin long ramp up brightness
At sunset ramp down to match sun setting for 60-90 mins (civil-nautical-astronomical twilight)
Turn RGB LED strip at that point to 'night color' simulating 'campfire' till user selected 'sleep time'
Fade to black
Do it all again the next day...etc etc.
I'm willing to pay something to get this finished. Any good coders for hire are welcome.
Want to open source this whole thing afterwards so anybody can build this base unit cheaply.
It's important for people living in Northern climates.
NASA has just done this on the ISS. They have standalone light fixtures controlled by code:
http://www.gizmag.com/nasa-led-lights-iss/25541/
Even getting just the plain sunrise on/off event working for now would be great.
At least it will act like a dawn/dusk store bought light timer with astro functions.
If Teensy can do it with this code...I'll gladly buy one and have it running this week.
Next step is to use GPS with Teensy to set the time and lat/long for the user automatically.
Hell, I'd love that even before code for the light fades.
PS - Here is a great iOS app that shows you the real sun times using astro calcs:
http://www.juggleware.com/iphone/sol/
The Time Lord code closely follows that app. Like 1 minute off.
This is a perfect real world showcase project for the Teensy website.
Something that can actually help quality of life.
Will help your indoor plants too. Greenhouse/growroom applications.
If you set the lat/long to say, the tropics, your bedroom lights will simulate the better daylight hours precisely.
Ditch the short winter days in let's say, Minnesota.
You can also alter settings if you want to mess with your Circadian wakeup.
That's for biohackers and clinical settings mainly.
I just want to mimic what's going on outside my window.
Let me know your thoughts. Thanks!
}
But seriously....I appreciate all comments on the following post..
I may want to move this project over from Arduino to Teensy.
Seems cooler. Also much smaller footprint.
It's a sunrise/sunset + 'night' simulator for 'light therapy' that controlls LED lighting strips with a cheap COTS RGB Amplifier/controller:
www.amazon.com/TaoTronics-Repeater-Amplifier-Strips-Connectors/dp/B0081CZJGO
This is a slick way to power the LED strips and Arduino off one box.
I use a small UPS battery to power it all right now.
I'm using the Sain Smart Arduino MEGA R3 and their RTC board (just because I have them):
www.amazon.com/SainSmart-DS1307-AT24C32-memory-Arduino/dp/B00E37VTWY
Using these libraries:
http://playground.arduino.cc/uploads/Code/Time.zip
http://www.pjrc.com/teensy/arduino_libraries/DS1307RTC.zip
http://swfltek.com/arduino/timelord.html
TimeLord is outdated, but the code I got from another astro timer project using it works:
http://paulorenato.com/joomla/index...matic-light-control&catid=4:projects&Itemid=4
I took out all his code related to 7 segment displays and buttons....with a noob machete.
He was using digitalWrite to switch a relay (LED 13 in his publicly shared code).
His only line of code that seemed to "control" the LED was:
Code:
digitalWrite(LED, minOfDay < mSunrise || minOfDay >= mSunset);
I rewrote that line to control the RGB amplifier/controller with analogWrite.
The RGB controller works 'backwards' (0 is 'on', 255 is 'off')
Explanation here:
http://www.instructables.com/id/LED-Strip-Controller-w-LED-Amp-Arduino/
My LED strips control perfectly with any existing code.
I can pulse them, on/off...strobe them really fast etc.
Works perfect.
I set the RTC board with current time, then load my DawnDusk sketch.
The serial monitor shows everything working fine. Time is correct.
I can only get the sunset trigger to work. LED strip clicks on perfect.
LED does *not* turn off at dawn.
Yes, I have no idea about coding. Just working from the seat of my pants.
Any hints would be appreciated. I'm pretty sure it's a *really* noob mistake.
My other question, can the TimeAlarms library do some of this more precisely?
Eventually I want to do this 'scripted performance':
30 min before dawn...long ramp up brightness (analogWrite 255-0 / linear fade code etc.)
Fade lights quick 30-60 mins after dawn.
Wait till 30 mins before sunset, begin long ramp up brightness
At sunset ramp down to match sun setting for 60-90 mins (civil-nautical-astronomical twilight)
Turn RGB LED strip at that point to 'night color' simulating 'campfire' till user selected 'sleep time'
Fade to black
Do it all again the next day...etc etc.
I'm willing to pay something to get this finished. Any good coders for hire are welcome.
Want to open source this whole thing afterwards so anybody can build this base unit cheaply.
It's important for people living in Northern climates.
NASA has just done this on the ISS. They have standalone light fixtures controlled by code:
http://www.gizmag.com/nasa-led-lights-iss/25541/
Even getting just the plain sunrise on/off event working for now would be great.
At least it will act like a dawn/dusk store bought light timer with astro functions.
If Teensy can do it with this code...I'll gladly buy one and have it running this week.
Next step is to use GPS with Teensy to set the time and lat/long for the user automatically.
Hell, I'd love that even before code for the light fades.
PS - Here is a great iOS app that shows you the real sun times using astro calcs:
http://www.juggleware.com/iphone/sol/
The Time Lord code closely follows that app. Like 1 minute off.
This is a perfect real world showcase project for the Teensy website.
Something that can actually help quality of life.
Will help your indoor plants too. Greenhouse/growroom applications.
If you set the lat/long to say, the tropics, your bedroom lights will simulate the better daylight hours precisely.
Ditch the short winter days in let's say, Minnesota.
You can also alter settings if you want to mess with your Circadian wakeup.
That's for biohackers and clinical settings mainly.
I just want to mimic what's going on outside my window.
Let me know your thoughts. Thanks!
Code:
/*Dawn Dusk Simulator
*TimeLord astronomical library by Michael Rice http://swfltek.com/
*Original Astronomical Night Lamp project code by Paulo Oliveira. http://www.paulorenato.com
*
*/
/******************* CONSTANTS AND VARIABLES *******************
****************************************************************/
#include <Time.h>
#include <TimeLord.h>
#include <Wire.h> // Needed for I2C communication
#include <DS1307RTC.h> // a basic DS1307 library that returns time as a time_t
#define DS1307_ADDRESS 0x68
#define REDLED 5 //R channel on 12v RGB amplifier
//#define GREENLED 6 //G channel on 12v RGB amplifier
#define BLUELED 7 //B channel on 12v RGB amplifier
#define DEBUG 1 //Set to 1 to enable debug messages through serial port monitor
const int TIMEZONE = -7; //MST
const float LATITUDE = 33.3, LONGITUDE = -104.4; // set your position here
TimeLord myLord; // TimeLord Object, Global variable
byte sunTime[] = {0, 0, 0, 1, 1, 13}; // 17 Oct 2013
int minNow, minLast = -1, hourNow, hourLast = -1, minOfDay; //time parts to trigger various actions. // -1 init so hour/min last inequality is triggered the first time around
int mSunrise, mSunset; //sunrise and sunset expressed as minute of day (0-1439)
/************************ ARDUINO SETUP ***********************
****************************************************************/
void setup() {
Serial.begin(9600);
while (!Serial) ; // Needed for Leonardo only
//Set Pin Modes Appropriately//
pinMode(REDLED, OUTPUT);
//pinMode(GREENLED, OUTPUT);
pinMode(BLUELED, OUTPUT);
analogWrite(REDLED,255);
//analogWrite(GREENLED,255);
analogWrite(BLUELED,255);
// TimeLord Object Initialization //
myLord.TimeZone(TIMEZONE * 60);
myLord.Position(LATITUDE, LONGITUDE);
myLord.DstRules(3,2,11,1,60); // DST Rules for USA
setSyncProvider(RTC.get); // the function to get the time from the RTC
if(timeStatus()!= timeSet)
Serial.println("Unable to sync with the RTC");
else
Serial.println("RTC has set the system time");
}
/******************** MAIN LOOP STARTS HERE *******************
****************************************************************/
void loop(){
if (timeStatus()!= timeNotSet) {
minNow = minute();
if (minNow != minLast) {
minLast = minNow;
hourNow = hour();
minOfDay = hourNow * 60 + minNow; //minute of day will be in the range 0-1439
#if DEBUG == 1
Serial.print(" hourNow:");
Serial.print(hourNow);
Serial.print(" minNow:");
Serial.print(minNow);
Serial.print(" minOfDay:");
Serial.print(minOfDay);
Serial.print(" minLast:");
Serial.print(minLast);
Serial.print(" hourLast:");
Serial.print(hourLast);
Serial.println();
#endif
if (hourNow != hourLast) { // Noting that the Sunrise/Sunset is only calculated every hour => less power.
/* Sunrise: */
sunTime[3] = day(); // Uses the Time library to give Timelord the current date
sunTime[4] = month();
sunTime[5] = year();
myLord.SunRise(sunTime); // Computes Sun Rise. Prints:
mSunrise = sunTime[2] * 60 + sunTime[1];
#if DEBUG == 1
Serial.print("SUNRISE:");
//DisplayTime(sunTime);
#endif
/* Sunset: */
sunTime[3] = day(); // Uses the Time library to give Timelord the current date
sunTime[4] = month();
sunTime[5] = year();
myLord.SunSet(sunTime); // Computes Sun Set. Prints:
mSunset = sunTime[2] * 60 + sunTime[1];
#if DEBUG == 1
Serial.print("SUNSET:");
//DisplayTime(sunTime);
#endif
hourLast = hourNow;
}
if(minOfDay < mSunrise || minOfDay >= mSunset){
analogWrite(REDLED, 0);
analogWrite(BLUELED, 0);
}
#if DEBUG == 1
Serial.print(" mSunrise:");
Serial.print(mSunrise);
Serial.print(" mSunset:");
Serial.print(mSunset);
Serial.print(" LED State:");
Serial.print(minOfDay < mSunrise || minOfDay >= mSunset);
Serial.println();
#endif
// if (minOfDay == mSunrise || minOfDay == mSunset) whistle(); Maybe cute to add sound later
} // End: if (minNow != minLast)
} // End: if (timeStatus()!= timeNotSet)
} // End loop()
/************************* FUNCTIONS **************************
****************************************************************/
//If this code below is for buttons...must remove
/*void IncrementTime(byte &hours, byte &minutes) {
// Increment minutes and hours
minutes++;
if ( minutes > 59) {
minutes = 0;
hours++;
}
if ( hours > 23 ) hours = 0;
}
void DecrementTime(byte &hours, byte &minutes) {
// Decrement minutes and hours
if ( minutes != 0) {
minutes = minutes - 1;
}
else {
minutes = 59;
if ( hours > 0 ) {
hours = hours - 1 ;
}
else {
hours = 23;
}
}
}
*/
byte decToBcd(byte val){
// Convert normal decimal numbers to binary coded decimal
return ( (val/10*16) + (val%10) );
}
Last edited: