MeanWell HLG PWM controll

Hi!
I am new to arduino programming. I am trying to make aquarium lighting based on the MeanWell HLG-60H-C350B power supply (datasheet: https://www.meanwell.com/Upload/PDF/HLG-60H-C/HLG-60H-C-SPEC.PDF). I would like to control it with an arduino. Using RTC, I want to automatically brighten and then dim the light at a specific time. However, I have a problem with dimming the light. I found a few posts like this: Arduino controlling pwm of MeanWell driver but please explain in simple words how I should go about it. Thank you in advance.

1 Like

But you don't want to tell us what that problem is? Difficult to help, it is.
Brightening and dimming a light are the same, just different start and end values.

The documentation states 0 to 10 volts.
The 0 to 5 volts of an Arduino will not help you much without another bit of hardware.

You have two options.

  1. PWM a MOSFET fed with 10 volts.
  2. Use a PWM adaptor that converts the 0-5 to 0-10

Used option (2) here for a client project a long time ago but cannot remember the link to the module.

See this link

I don't know if what I was doing was right butI was trying to use mosfet module HW-517 (Hw-517 High Power Mos Tube Field Effect Transistor Trigger Switch Drive Module a for sale online | eBay) to control the PWM. I connected the power supply from arduino (5V) by step up converter (10V). I udes simple "Fade" program from examples from Adruino IDE to check if mosfet module would work and it worked (little red diode on the module fas fading) but my light didn't. Then I was trying to connect external power supply 10V to mosfet module with the same result. I noticed that when i connect just mean well power supply there is already 10V on dimming cables. When I connect them together the light is off and when they are disconnected the light is on. What i can do next?

Post your FULL CODE, and your wiring SCHEMATIC. Remember, we can't see what you see!

This is my previous wiring:

When i swapped the grey (DIM+) and black (DIM-) cables and plugged them back in inversely with HW-517 (DIM+ into OUT- and DIM- into OUT+) it suddenly started working!

I changed the wiring completely to this:


My testing code was just simple Fade:

int led = 6;           
int brightness = 0;    
int fadeAmount = 5;    

void setup() {
   pinMode(led, OUTPUT);
}

void loop() {
    analogWrite(led, brightness);

  brightness = brightness + fadeAmount;

    if (brightness <= 0 || brightness >= 255) {
    fadeAmount = -fadeAmount;
  }
   delay(30);
}

It worked pretty well but not perfect. First, the circuit works in reverse logic. When the variable brightness =0, the led lighting is fully on. The system has some kind of inertia. When I turn it off slowly (brightness=0 and then up to 255) the light is off when brightness=230 what is ok. But when I turn it on (brightness=255 and then down to 0) the light is on when brightness=210 and with some grater intensity then it is turning off. It seems to me that this is a property of the power supply itself.

I added ds1307 rtc module and my new code is:

#include <RTClib.h>
#include <Wire.h>
#define SWITCHPIN 6
#define OnHour  16
#define OnMin  5
#define OnSec  59
#define OffHour  16
#define OffMin  50


int brightness = 255;    
RTC_DS1307 rtc;


void setup() {
   //rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  Serial.begin(9600);
  rtc.begin();
  pinMode(SWITCHPIN, OUTPUT);
   if (!rtc.begin())
  {
    Serial.println("Couldn't find RTC"); // Error Message!
    while (1);  
  }
  if (!rtc.isrunning())
  {
    Serial.println("RTC is NOT running!");
}}

void loop() {

  analogWrite(SWITCHPIN, brightness);
 DateTime now = rtc.now();
  Serial.print(now.hour(), DEC); // Only For Serial Monitor
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();
    
  if(now.hour() == OnHour && now.minute() == OnMin - 31)
  {  brightness = 230;
    Serial.println(brightness);}

    else if(now.hour() == OnHour && now.minute() == OnMin - 30)
    { brightness = 228;
    Serial.println(brightness);}

     else if(now.hour() == OnHour && now.minute() == OnMin - 29)
    { brightness = 224;
    Serial.println(brightness);}

     else if(now.hour() == OnHour && now.minute() == OnMin - 28)
    { brightness = 217;
    Serial.println(brightness);}

     else if(now.hour() == OnHour && now.minute() == OnMin - 27)
    { brightness = 210;
    Serial.println(brightness);}

     else if(now.hour() == OnHour && now.minute() == OnMin - 26)
    { brightness = 203;
    Serial.println(brightness);}
    
    else if(now.hour() == OnHour && now.minute() == OnMin - 25)
    { brightness = 196;
    Serial.println(brightness);}

    else if(now.hour() == OnHour && now.minute() == OnMin - 24)
    { brightness = 189;
    Serial.println(brightness);}
    
    else if(now.hour() == OnHour && now.minute() == OnMin - 23)
    { brightness = 182;
    Serial.println(brightness);}
   
    else if(now.hour() == OnHour && now.minute() == OnMin - 22)
    { brightness = 175;
    Serial.println(brightness);}
      
    else if(now.hour() == OnHour && now.minute() == OnMin - 21)
    { brightness = 168;
    Serial.println(brightness);}
   
    else if(now.hour() == OnHour && now.minute() == OnMin - 20)
    { brightness = 161;
    Serial.println(brightness);}
   
    else if(now.hour() == OnHour && now.minute() == OnMin - 19)
    { brightness = 154;
    Serial.println(brightness);}
   
    else if(now.hour() == OnHour && now.minute() == OnMin - 18)
    { brightness = 147;
    Serial.println(brightness);}
      
    else if(now.hour() == OnHour && now.minute() == OnMin - 17)
    { brightness = 140;
    Serial.println(brightness);}
      
    else if(now.hour() == OnHour && now.minute() == OnMin - 16)
    { brightness = 133;
    Serial.println(brightness);}
      
    else if(now.hour() == OnHour && now.minute() == OnMin - 15)
    { brightness = 126;
    Serial.println(brightness);}
    
    else if(now.hour() == OnHour && now.minute() == OnMin - 14)
    { brightness = 119;
    Serial.println(brightness);}
      
    else if(now.hour() == OnHour && now.minute() == OnMin - 13)
    { brightness = 112;
    Serial.println(brightness);}
      
    else if(now.hour() == OnHour && now.minute() == OnMin - 12)
    { brightness = 105;
    Serial.println(brightness);}
      
    else if(now.hour() == OnHour && now.minute() == OnMin - 11)
    { brightness = 98;
    Serial.println(brightness);}
      
    else if(now.hour() == OnHour && now.minute() == OnMin - 10)
    { brightness = 91;
    Serial.println(brightness);}
      
    else if(now.hour() == OnHour && now.minute() == OnMin - 9)
    { brightness = 84;
    Serial.println(brightness);}
      
    else if(now.hour() == OnHour && now.minute() == OnMin - 8)
    { brightness = 77;
    Serial.println(brightness);}
      
    else if(now.hour() == OnHour && now.minute() == OnMin - 7)
    { brightness = 70;
    Serial.println(brightness);}
      
    else if(now.hour() == OnHour && now.minute() == OnMin - 6)
    { brightness = 63;
    Serial.println(brightness);}
      
    else if(now.hour() == OnHour && now.minute() == OnMin - 5)
    { brightness = 56;
    Serial.println(brightness);}
      
    else if(now.hour() == OnHour && now.minute() == OnMin - 4)
    { brightness = 49;
    Serial.println(brightness);}
      
    else if(now.hour() == OnHour && now.minute() == OnMin - 3)
    { brightness = 42;
    Serial.println(brightness);}
      
    else if(now.hour() == OnHour && now.minute() == OnMin - 2)
    { brightness = 35;
    Serial.println(brightness);}
      
    else if(now.hour() == OnHour && now.minute() == OnMin - 1)
    { brightness = 28;
    Serial.println(brightness);}
      
    else if(now.hour() == OnHour && now.minute() == OnMin)
    { brightness = 0;
    Serial.println(brightness);}
      
   
    
      else if(now.hour() == OffHour && now.minute() == OffMin - 30)
    { brightness = 0;
    Serial.println(brightness);}

     else if(now.hour() == OffHour && now.minute() == OffMin - 29)
    { brightness = 35 ;
    Serial.println(brightness);}

     else if(now.hour() == OffHour && now.minute() == OffMin - 28)
    { brightness = 42;
    Serial.println(brightness);}

     else if(now.hour() == OffHour && now.minute() == OffMin - 27)
    { brightness = 49;
    Serial.println(brightness);}

     else if(now.hour() == OffHour && now.minute() == OffMin - 26)
    { brightness = 56;
    Serial.println(brightness);}
    
    else if(now.hour() == OffHour && now.minute() == OffMin - 25)
    { brightness = 63;
    Serial.println(brightness);}

    else if(now.hour() == OffHour && now.minute() == OffMin - 24)
    { brightness = 70;
    Serial.println(brightness);}
    
    else if(now.hour() == OffHour && now.minute() == OffMin - 23)
    { brightness = 77;
    Serial.println(brightness);}
   
    else if(now.hour() == OffHour && now.minute() == OffMin - 22)
    { brightness = 84;
    Serial.println(brightness);}
      
    else if(now.hour() == OffHour && now.minute() == OffMin - 21)
    { brightness = 91;
    Serial.println(brightness);}
   
    else if(now.hour() == OffHour && now.minute() == OffMin - 20)
    { brightness = 98;
    Serial.println(brightness);}
   
    else if(now.hour() == OffHour && now.minute() == OffMin - 19)
    { brightness = 105;
    Serial.println(brightness);}
   
    else if(now.hour() == OffHour && now.minute() == OffMin - 18)
    { brightness = 112;
    Serial.println(brightness);}
      
    else if(now.hour() == OffHour && now.minute() == OffMin - 17)
    { brightness = 119;
    Serial.println(brightness);}
      
    else if(now.hour() == OffHour && now.minute() == OffMin - 16)
    { brightness = 126;
    Serial.println(brightness);}
      
    else if(now.hour() == OffHour && now.minute() == OffMin - 15)
    { brightness = 133;
    Serial.println(brightness);}
    
    else if(now.hour() == OffHour && now.minute() == OffMin - 14)
    { brightness = 140;
    Serial.println(brightness);}
      
    else if(now.hour() == OffHour && now.minute() == OffMin - 13)
    { brightness = 147;
    Serial.println(brightness);}
      
    else if(now.hour() == OffHour && now.minute() == OffMin - 12)
    { brightness = 154;
    Serial.println(brightness);}
      
    else if(now.hour() == OffHour && now.minute() == OffMin - 11)
    { brightness = 161;
    Serial.println(brightness);}
      
    else if(now.hour() == OffHour && now.minute() == OffMin - 10)
    { brightness = 168;
    Serial.println(brightness);}
      
    else if(now.hour() == OffHour && now.minute() == OffMin - 9)
    { brightness = 175;
    Serial.println(brightness);}
      
    else if(now.hour() == OffHour && now.minute() == OffMin - 8)
    { brightness = 182;
    Serial.println(brightness);}
      
    else if(now.hour() == OffHour && now.minute() == OffMin - 7)
    { brightness = 189;
    Serial.println(brightness);}
      
    else if(now.hour() == OffHour && now.minute() == OffMin - 6)
    { brightness = 196;
    Serial.println(brightness);}
      
    else if(now.hour() == OffHour && now.minute() == OffMin - 5)
    { brightness = 203;
    Serial.println(brightness);}
      
    else if(now.hour() == OffHour && now.minute() == OffMin - 4)
    { brightness = 210;
    Serial.println(brightness);}
      
    else if(now.hour() == OffHour && now.minute() == OffMin - 3)
    { brightness = 217;
    Serial.println(brightness);}
      
    else if(now.hour() == OffHour && now.minute() == OffMin - 2)
    { brightness = 224;
    Serial.println(brightness);}
      
    else if(now.hour() == OffHour && now.minute() == OffMin - 1)
    { brightness = 228;
    Serial.println(brightness);}
      
    else if(now.hour() == OffHour && now.minute() == OffMin)
    { brightness = 230;
    Serial.println(brightness);}


                                
    
    delay (1000);
  }

Next I want to add some DS18b20 and some fans to controll the temperature of my LED light. And then I want to add OLED display to display time and temperature. I think that I have to use interrupts to do this but I don't know how.

P.S. I am very grateful for your interest and any help :slight_smile:

Hi,

Please read the post at the start of any forum , entitled "How to use this Forum".

It will tell you how to post your code in a scrolling frame.

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

I have achieved some success. The circuit works as I wanted. In addition, I added a second Mosfet Hw-517 module that controls fan fans to control the temperature of the LEDs (I have two Lamps). I am also using OLED 1.3" SH1106 display. Below is my code. If anyone has any suggestions to improve the code, I am writing about any suggestions.

#include <RTClib.h>

#include <Wire.h>

#include <OneWire.h>

#include <DallasTemperature.h>

#include <Arduino.h>

#include <U8x8lib.h>

 

#define Fans 5

#define Light 6

#define OnHour 11

#define OnMin 00

#define OffHour  20

#define OffMin  30

#define Hour now.hour()

#define Min now.minute()

#define Sec now.second()

 

U8X8_SH1106_128X64_NONAME_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE);

RTC_DS1307 rtc;

OneWire oneWire(2);

DallasTemperature sensors(&oneWire);

int brightness = 255;

float tempLamp1 = 0;

float tempLamp2 = 0;

float tempWater = 0;  

 

void setup()

{

  //rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));

  Serial.begin(9600);

  rtc.begin();

  Wire.begin();

  sensors.begin();

  pinMode(Light, OUTPUT);

  pinMode(Fans, OUTPUT);

  u8x8.begin();

  

 }

 

 

void loop() {


   DateTime now = rtc.now();

   u8x8.setFont(u8x8_font_courB18_2x3_f);

  

   u8x8.setCursor(0, 0);

  

   if (Hour >= 0 and Hour < 10)

            {u8x8.print("0");

             u8x8.print(Hour);}

            else

            {u8x8.print(Hour);}

   u8x8.print(":");

   if (Min >= 0 and Min < 10)

            {u8x8.print("0");

             u8x8.print(Min);}

            else

            {u8x8.print(Min);}

   u8x8.print(":");

   if (Sec >= 0 and Sec < 10)

            {u8x8.print("0");

             u8x8.print(Sec);}

            else

            {u8x8.print(Sec);}

  

   u8x8.setFont(u8x8_font_chroma48medium8_r );

   u8x8.setCursor(0, 3);

   u8x8.setInverseFont(1);

   u8x8.print("Water:    "); u8x8.print(tempWater); u8x8.print("'C");

  

   u8x8.setCursor(0, 4);

   u8x8.setInverseFont(0);

   u8x8.print("Light: ");

   if (brightness<255)

   {u8x8.print(100-((brightness*100)/230));

    u8x8.print("%");}

    else

    { u8x8.print("Off");}

   

   u8x8.setCursor(0, 5);

   u8x8.print("Lamp1:  "); u8x8.print(tempLamp1); u8x8.print("'C");

  

   u8x8.setCursor(0, 6);

   u8x8.print("Lamp2:  "); u8x8.print(tempLamp2); u8x8.print("'C");

 

   u8x8.setCursor(0, 7);

   u8x8.print("Fans.:   ");

   if ((digitalRead(Fans)) == 1)

   {u8x8.print("On");}

    else {u8x8.print("Off");}

   

    analogWrite(Light, brightness);

   

   

    Serial.print(now.hour(), DEC); // Only For Serial Monitor

    Serial.print(':');

    Serial.print(now.minute(), DEC);

    Serial.print(':');

    Serial.print(now.second(), DEC);

    Serial.println();

   

    Serial.print("T_Lamp1:  ");

    Serial.print(tempLamp1, 2);

    Serial.println(" *C");

 

    Serial.print("T_Lamp2:  ");

    Serial.print(tempLamp2, 2);

    Serial.println(" *C");

 

    Serial.print("T_Water:  ");

    Serial.print(tempWater, 2);

    Serial.println(" *C");

   

    Serial.print("Light: ");

       if (brightness<255)

   {Serial.print(100-((brightness*100)/230));

    Serial.println("%");}

    else

    { Serial.println("Off");}

   

    Serial.print("Fans ");

    Serial.println(digitalRead(Fans));

    Serial.println("");

 

    sensors.requestTemperatures(); //Pobranie temperatury czujnika

 

    tempLamp1 = sensors.getTempCByIndex(0);

    tempLamp2 = sensors.getTempCByIndex(2);

    tempWater = sensors.getTempCByIndex(1);

 

    

    if ((tempLamp1 >= 26.00) || (tempLamp2 >= 26.00))

    {digitalWrite(Fans, HIGH); }

 
    else if ((tempLamp1 < 24.00) || (tempLamp2 < 24.00))

    {digitalWrite(Fans, LOW);} 
    

if ((tempLamp1 >= 30.00) || (tempLamp2 >= 30.00))

    {digitalWrite(Light, HIGH);} 

   

    if(Hour == OnHour && Min == OnMin && Sec == 0)

    { brightness = 215;}

   

    else if(Hour == OnHour && Min == OnMin && Sec == 1)

    { brightness = 226;}

   

    else if(Hour == OnHour && Min == OnMin +1)

    { brightness = 225;}

 

    else if(Hour == OnHour && Min == OnMin +2)

    { brightness = 220;}

 

    else if(Hour == OnHour && Min == OnMin +3)

    { brightness = 217;}

 

    else if(Hour == OnHour && Min == OnMin +4)

    { brightness = 215;}

 

    else if(Hour == OnHour && Min == OnMin +5)

    { brightness = 203;}

   

    else if(Hour == OnHour && Min == OnMin +6)

    { brightness = 196;}

 

    else if(Hour == OnHour && Min == OnMin +7)

    { brightness = 189;}

   

    else if(Hour == OnHour && Min == OnMin +8)

    { brightness = 182;}

  

    else if(Hour == OnHour && Min == OnMin +9)

    { brightness = 175;}

     

    else if(Hour == OnHour && Min == OnMin +10)

    { brightness = 168;}

  

    else if(Hour == OnHour && Min == OnMin +11)

    { brightness = 161;}

  

    else if(Hour == OnHour && Min == OnMin +12)

    { brightness = 154;}

  

    else if(Hour == OnHour && Min == OnMin +13)

    { brightness = 147;}

     

    else if(Hour == OnHour && Min == OnMin +14)

    { brightness = 140;}

     

    else if(Hour == OnHour && Min == OnMin +15)

    { brightness = 133;}

     

    else if(Hour == OnHour && Min == OnMin +16)

    { brightness = 126;}

   

    else if(Hour == OnHour && Min == OnMin +17)

    { brightness = 119;}

     

    else if(Hour == OnHour && Min == OnMin +18)

    { brightness = 112;}

     

    else if(Hour == OnHour && Min == OnMin +19)

    { brightness = 105;}

     

    else if(Hour == OnHour && Min == OnMin +20)

    { brightness = 98;}

     

    else if(Hour == OnHour && Min == OnMin +21)

    { brightness = 91;}

     

    else if(Hour == OnHour && Min == OnMin +22)

    { brightness = 84;}

     

    else if(Hour == OnHour && Min == OnMin +23)

    { brightness = 77;}

     

    else if(Hour == OnHour && Min == OnMin +24)

    { brightness = 70;}

     

    else if(Hour == OnHour && Min == OnMin +25)

    { brightness = 63;}

     

    else if(Hour == OnHour && Min == OnMin +26)

    { brightness = 56;}

     

    else if(Hour == OnHour && Min == OnMin +27)

    { brightness = 40;}

     

    else if(Hour == OnHour && Min == OnMin +28)

    { brightness = 25;}

     

    else if(Hour == OnHour && Min == OnMin +29)

    { brightness = 10;}

     

    else if(Hour == OnHour && Min == OnMin +30)

    { brightness = 0;}

     

    else if(Hour > OnHour && Hour < OffHour)

    { brightness = 0;}

 

  

    

     else if(Hour == OffHour && Min == OffMin)

    { brightness = 10;}

 

    else if(Hour == OffHour && Min == OffMin +1)

    { brightness = 35 ;}

 

    else if(Hour == OffHour && Min == OffMin +2)

    { brightness = 42;}

 

    else if(Hour == OffHour && Min == OffMin +3)

    { brightness = 49;}

 

    else if(Hour == OffHour && Min == OffMin +4)

    { brightness = 56;}

   

    else if(Hour == OffHour && Min == OffMin +5)

    { brightness = 63;}

 

    else if(Hour == OffHour && Min == OffMin +6)

    { brightness = 70;}

   

    else if(Hour == OffHour && Min == OffMin +7)

    { brightness = 77;}

  

    else if(Hour == OffHour && Min == OffMin +8)

    { brightness = 84;}

     

    else if(Hour == OffHour && Min == OffMin +9)

    { brightness = 91;}

  

    else if(Hour == OffHour && Min == OffMin +10)

    { brightness = 98;}

  

    else if(Hour == OffHour && Min == OffMin +11)

    { brightness = 105;}

  

    else if(Hour == OffHour && Min == OffMin +12)

    { brightness = 112;}

     

    else if(Hour == OffHour && Min == OffMin +13)

    { brightness = 119;}

     

    else if(Hour == OffHour && Min == OffMin +14)

    { brightness = 126;}

     

    else if(Hour == OffHour && Min == OffMin +15)

    { brightness = 133;}

   

    else if(Hour == OffHour && Min == OffMin +16)

    { brightness = 140;}

     

    else if(Hour == OffHour && Min == OffMin +17)

    { brightness = 147;}

     

    else if(Hour == OffHour && Min == OffMin +18)

    { brightness = 154;}

     

    else if(Hour == OffHour && Min == OffMin +19)

    { brightness = 161;}

     

    else if(Hour == OffHour && Min == OffMin +22)

    { brightness = 168;}

     

    else if(Hour == OffHour && Min == OffMin +21)

    { brightness = 175;}

     

    else if(Hour == OffHour && Min == OffMin +22)

    { brightness = 182;}

     

    else if(Hour == OffHour && Min == OffMin +23)

    { brightness = 189;}

     

    else if(Hour == OffHour && Min == OffMin +24)

    { brightness = 196;}

     

    else if(Hour == OffHour && Min == OffMin +25)

    { brightness = 203;}

     

    else if(Hour == OffHour && Min == OffMin +26)

    { brightness = 210;}

     

    else if(Hour == OffHour && Min == OffMin +27)

    { brightness = 217;}

     

    else if(Hour == OffHour && Min == OffMin +28)

    { brightness = 224;}

     

    else if(Hour == OffHour && Min == OffMin +29)

    { brightness = 228;}

     

    else if(Hour == OffHour && Min == OffMin +30)

    { brightness = 255;}
  

  }

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.