Jump to content
ReefCleaners.org

Simplest Arduino-LED system


aedificator

Recommended Posts

aedificator

I have finally managed to complete an LED system (soon i'll post a pic) thanks to the many info I found on this forum.

 

Looking inside an old box in my storage room I found an Arduino Board, not sure what type; on the blue PCB it reads "SainSmart - Mega 2560", and with it a small display (i'd say 3" - 4"), a clock module RTC-DS1302 and a coupler (NTE 3220) to work with the HLG driver.

 

The LEDs are all powered by the same driver and hooked to a timer that goes ON/OFF at a specific time.

 

I want to dim the lights on a basic cycle: sunrise (about 2 hours), daylight (8 hours), sunset (about 2 hours), night (about 12 hours), and I was wondering if there is anybody who could point me to a website where I could find the code for this basic dimming project. For the purpose of this basic system, I don't need to use the display, or the timer, all I want to do is to dim the lights automatically.

 

I did some coding in high school but it's now (very) rusty. I looked at the Jarduino and Meepduino projects but there is too much code that I don't need/understand.

 

I considered the Typhoon Controller, but because I already have an Arduino and the TFT Display I was hoping save some bucks.

 

The driver is an HLG-150h-36b.

 

 

Link to comment

First thing you need to know is that you will not be able to connect an Arduino (you have a Sainsmart close of an Arduino Mega2560) directly to the HLG driver. The HLG requires a 10v signal, while the Arduino will only output 5v. You will want to connect an N-channel MOSFET between the Arduino, HLG, and a 10v source.

 

Once you get the electrical portion sorted, then you can move on to programming it.

 

All you will be doing is changing the pwm duty cycle through a for() loop over a period of time. Without the RTC, the easiest way is to just add a 1000ms delay at the end of the loop, and just set the loop up for the number of seconds that you want the ramp to cover. You can use this for ramp up and ramp down. Between those, just add a simple for() loop that runs for the amount of time in seconds that you want the lights at max brightness with only the delay in the loop. It would look something like this:

int startPWM = 0;
int maxPWM = 255;
int currentPWM;
float pwmStep;
int rampTime = 2000;
int fullLight = 10000;

loop()
{
  pwmStep=maxPWM/rampTime;

  currentPWM=startPWM;

  for(int x=0; x>rampTime; x++)
  {
    currentPWM=currentPWM+pwmStep;

    analogWrite(PIN, currentPWM);

    delay(1000); 
  }

  for(int y=0; y>fullLight; y++)
  {
    delay(1000);
  }

  for(int x=0; x>rampTime; x++)
  {
    currentPWM=currentPWM-pwmStep;

    analogWrite(PIN, currentPWM);

    delay(1000); 
  }
}

Now, this is not complete code, but enough to give you an idea on how to start. The Arduino site is a good place to learn about the different functions, and there is a lot of example code that comes with the IDE.

Link to comment

Archived

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

  • Recommended Discussions

×
×
  • Create New...