Jump to content
Innovative Marine Aquariums

Simulate sunrise / sunset using Arduino


quietstorm

Recommended Posts

Hi everyone,

 

I'd like to simulate sunrise and sunset with my LED lighting system using an Arduino but I've had problems with my code. I use a RTC module for time also.

 

I've used the code available on arduino.cc for PWM and it works well with my led array. The problem is that when the light is dimming, the time that displays on my LCD screen doesn't increment correctly, it just stops. I think the issue comes from the fact that I use delay() for dimming and that it affects the whole programm.

 

Has anyone a code suggestion to have a smooth sunrise / sunset without affecting the rest of the programm ?

 

Thanks in advance for your help !

Link to comment

Here is one piece of code that relies to new Time library. I wrote this from memory as I'm not at home now. So check carefully if I have made mistakes. I made this quite simple, only white leds.

 

#include <DS1307RTC.h>#include <Wire.h>#include <Time.h>// Next comes variables for white leds, you have to do the same for blues too.byte pwmWhite = 0;// Next idea from Dave_uk, thanks (http://www.nano-reef.com/forums/index.php?showtopic=206246)// Array of pwm values for 15 minute sectionsbyte whiteLeds[96] = {  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,  // 00-03  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,  // 00-06  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,  // 06-09  20, 30, 40, 50, 60, 80, 100, 120, 140, 160, 180, 200, // 09-12  220, 240, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,  // 12-15  255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,  // 15-18  240, 220, 200, 180, 160, 140, 120, 100, 80, 80, 80, 60,  // 18-21  60, 40, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0 // 21-24}; byte whiteMaxCurrent = 70; // Percentage of, 70 is 70%, so 1000mA puckbuck is driven at 700mA// Next the pin for writingbyte whitePin = 11;void setup() {// Setup stuff, LCD, pins, RTC etc.}void loop() {  // Main loop  getWhitePwm();  analogWrite(whitePin, pwmWhite);}void getWhitePwm() {  int tempIndex = 0; // Index for the array containing dimming values for the leds, calculated in 15 mins sectors  long tempTime = 0; // Used to store number of seconds since last midnight  pwmWhite = 0; // Public variable. Reset the value (just to be sure)    tempTime = elapsedSecsToday(now()); // From Time.h, seconds since last midnight, now() is current time  // Check out what is the index of 15 min sections  tempIndex = (tempTime / (SECS_PER_HOUR / 4)); // macro SECS_PER_HOUR from Time.h  // Calculate the PWM value according the index and maximum power we have defined.  pwmWhite = ( whiteLeds[tempIndex] * (whiteMaxCurrent) /100 );  }

 

Hope this helps.

 

Jouko

Link to comment

There is a way to connect one of those wireless atomic clock modules to arduino,

then somehow(supposedly easily) you can choose what time zone and such.

Using that would be a great idea,

I'd use it but it won't work out here...

Link to comment

nfh63, thanx for the code ! I'm going to try to combine that to Dave_UK's code to see if it works. I'll tell you then.

 

If anyone else has other suggestions, please share !

Link to comment
  • 2 years later...

Archived

This topic is now archived and is closed to further replies.

  • Recommended Discussions

×
×
  • Create New...