The main scope of my project was to create a controller for Reef lighting bar using Arduino. The goal was to have a sunrise , sunset , timer and brightness control for 2 channels (White, Blue). All packed in a box operated by buttons.
I have created a prototype and it works well. Issue:
moving the controller to the Led Bar Light the lights start to go on and off in approx. 1s intervals when I reach 35-30% dimming . This was not the case with leds of the proto
What changed vs the prototype:
This means there is a new light :
and new power supply(original of the light bar):
TureFull led Driver
Input 100-240v AC
Output 20-33v 660mA
PFC>0.96
Efficiency>88%
My setup:
I use Arduino Uno with LCD keypad shield. By using a mosfet module I connect the power supply to the lights and use PWM to create the Fade effect.
Prototype used a small Led module and 12v power supply/ adapter.
Any Idea why the On Off is happening ?
I can not attach code as it exceeds the max number of characters </>
#include <Wire.h>
#include "RTClib.h"
#include <LiquidCrystal.h>
LiquidCrystal lcd(8,9,4,5,6,7);
RTC_DS1307 RTC;
//led dimming vars
int bluePin = 11; // blue LEDs connected to digital pin
int whitePin = 3; // white LEDs connected to digital pin
double blueFadeValue = 255;
double whiteFadeValue = 255;
double userWhiteMax = 90; // maximum percentage intensity of white leds, 0-100 user defined
double userBlueMax = 90; // maximum percentage intensity of blue leds, 0-100 user defined
double blueMaxPwm; // variable used to convert the userBlueMax value into a PWM value
double whiteMaxPwm; // variable used to convert the userWhiteMax value into a PWM value
int second;
int hour;
int minute;
int blueLightsOn = 12; // time of day (hour, 24h clock) to begin blue lights fading on
int whiteLightsOn = 13; // time of day (hour, 24h clock) to begin white lights fading on
int whiteLightsOff = 20; // time of day (hour, 24h clock) to begin white lights fading out
int blueLightsOff = 21; // time of day (hour, 24h clock) to begin blue lights fading out
double fadeTime = 60; // amount of time in minutes for the fade in/out to last **must be in 60 minute increments**
//button vars
int buttonValue=0; // stores the value from the A0 pin
//menu vars
int menuCount=1; //stores the position of menu
void setup () {
Serial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.setCursor(5,0);
lcd.print("v1.4");
Wire.begin();
RTC.begin();
// if (!RTC.isrunning()) { //uncomment the ! and the //RTC.adjust to be able to reset the datetime value
// this will allow you to set RTC to the current computer date and time if uncommented and compiled
// RTC.adjust(DateTime(__DATE__, __TIME__));
}
void loop () {
setFade();
ledRtc();
// SerialOut();
// screen();
buttons();
menu();
delay(200);
}
//void setFade class used to covert the user percentage input to a PWM value and set to white/blue
void setFade(){
blueMaxPwm = (userBlueMax*2.55); //converts the user input value (0-100) to a PWM value (0-255)
whiteMaxPwm = (userWhiteMax*2.55); //converts the user input value (0-100) to a PWM value (0-255)
}
//void ledRtc class to control the leds with the ds1307 timer, absolute value and using the time periods(<= etc) is to gain the correct fade position in case of a power outage
void ledRtc(){
DateTime now = RTC.now();
hour = now.hour();
minute = now.minute();
second = now.second();
int totBlueHrOn = hour - blueLightsOn;
int totBlueHrOff = hour - blueLightsOff;
int totWhiteHrOn = hour - whiteLightsOn;
int totWhiteHrOff = hour - whiteLightsOff;
int totalMinute = minute;
abs(totBlueHrOn);
abs(totBlueHrOff);
abs(totWhiteHrOn);
abs(totWhiteHrOff);
abs(totalMinute);
int totalBlueOn = ((totBlueHrOn*60) + totalMinute);
int totalBlueOff = ((totBlueHrOff*60) + totalMinute);
int totalWhiteOn = ((totWhiteHrOn*60) + totalMinute);
int totalWhiteOff = ((totWhiteHrOff*60) + totalMinute);
//fades on blue lights from blueLightsOn through blueLightsOn plus fadeTime and outputs light intensity based on the current time
if((hour >= blueLightsOn)&&(hour < (blueLightsOn+(fadeTime/60)))&&(totalBlueOn < fadeTime)){
blueFadeValue = blueMaxPwm*(totalBlueOn/fadeTime);
analogWrite(bluePin, blueFadeValue);
}
//fades on white lights from whiteLightsOn to whiteLightsOn plus fadeTime and outputs light intensity based on the current time
if((hour >= whiteLightsOn)&&(hour <= (whiteLightsOn+(fadeTime/60)))&&(totalWhiteOn <= fadeTime)){
whiteFadeValue = whiteMaxPwm*(totalWhiteOn/fadeTime);
analogWrite(whitePin, whiteFadeValue);
}
//puts blue lights up to full if the fade in period is complete and less than bluelightsoff, so full from 10 to 20:59
if((hour >= (blueLightsOn+(fadeTime/60)))&&(hour < blueLightsOff)){
blueFadeValue = blueMaxPwm;
analogWrite(bluePin, blueFadeValue);
}
//puts white lights up to full if the fade in period is complete and less than whitelightsoff, so full from 11 to 19:59
if((hour >= (whiteLightsOn+(fadeTime/60)))&&(hour < whiteLightsOff)){
whiteFadeValue = whiteMaxPwm;
analogWrite(whitePin, whiteFadeValue);
}
//fades out whites from whiteLightsOff to whiteLightsOff plus fadeTime and outputs light intensity based on the current time
if((hour >= whiteLightsOff)&&(hour < (whiteLightsOff+(fadeTime/60)))&&(totalWhiteOff <= fadeTime)){
whiteFadeValue = (whiteMaxPwm - (whiteMaxPwm*(totalWhiteOff/fadeTime)));
analogWrite(whitePin, whiteFadeValue);
}
//fade out blues from blueLightsOff to blueLightsOff plus fadeTime and outputs light intensity based on the current time
if((hour >= blueLightsOff)&&(hour < (blueLightsOff+(fadeTime/60)))&&(totalBlueOff <= fadeTime)){
blueFadeValue = (blueMaxPwm - (blueMaxPwm*(totalBlueOff/fadeTime)));
analogWrite(bluePin, blueFadeValue);
}
//this sets the white lights to be off from end of whiteLightsOff plus fadeTime to midnight
if((hour >= (whiteLightsOff+(fadeTime/60))&&(hour <= 24))){
whiteFadeValue = 0;
analogWrite(whitePin, whiteFadeValue);
}
//this sets the blue lights to be off from end of blueLightsOff plus fadeTime to midnight
if((hour >= (blueLightsOff+(fadeTime/60))&&(hour < 24))){
blueFadeValue = 0;
analogWrite(bluePin, blueFadeValue);
}
//this sets the white lights to be off from midnight to whiteLightsOn in case of reset of power outage
if((hour >= 0)&&(hour < whiteLightsOn)){
whiteFadeValue = 0;
analogWrite(whitePin, whiteFadeValue);
}
//this sets the blue lights to be off from midnight to blueLightsOn in case of reset or power outage
if((hour >= 0)&&(hour < blueLightsOn)){
blueFadeValue = 0;
analogWrite(bluePin, blueFadeValue);
}
}
thanks for your reply. I am using the power supply provided with the lamp. As per their product info :
Rated power consumption is 54w , actual power consumption is 22w .
To your question if the lamp can be driven by PWM, I do not know the answer , I thought all leds can be controlled by PWM. My bad.
I can definitely use the lamps with the power supply, it just brakes during the dimming process.
I have limited knowledge and will search for info further.
To your question if the lamp can be driven by PWM, I do not know the answer , I thought all leds can be controlled by PWM.
When the LEDs are that big, they need driving with a constant current drive. So turning them on and off rapidly sometimes interferes with the constant current circuit unless it is specifically designed to do this. So you should assume that if a constant current supply is not advertised as dimmable it is probably not.
It was hard to read that none English web site and it gave very little real data in terms of voltage and current. Talking simply about Watts is not good enough in electronic terms, especially when you want to do something they were not designed to do.
Thank you much Mike , this helps a lot and brings more understanding to me. I am thinking that either I will replace the power supply to a constant current dimmable one or I will limit the fading effect to around 40% and just live with that . ( I have observed that the issues star bellow 35%)