Jump to content

Meanwell LED controller


RockyBoy
 Share

Recommended Posts

After a few weeks of coding, hardwiring, finally made my controller from scratch.

My DIY controller is for

1) dimming the blues and the whites based on timinngs

2) moonlight based on days, towards the mid-month, would be the brightest

3) measure temperatures for my 2 LED heatsinks, if hit certain temperature that I think is too high, the LEDs intensity will be powered down less than 40% for abt 20 minutes to cool down. The overheat condition is to anticipate if the heatsink fans are not working, or ambient temperature is too high.

4)switching on/off the heatsink fans when the LED is siwtched on/off.

5)Added 2 buttons, white and blue, if pressed any one of them, let say blue button, will shut down the white LEDs and switch on the blues. Just for demo purposes.

post-1761-034426600 1288527741_thumb.jpg

Member of :
post-1182-0-60431600-1322062247_thumb.jp

post-2241-0-43391700-1354511230.png

UEN: T08SS0098F

MASS in Facebook

Reefing in LED

Link to comment
Share on other sites

My crappy arduino sketch:

#include <avr/io.h> 

#include <stdlib.h> 

#include <Wire.h>


/*LCD CONTROL

CONTROL CHARACTER DECIDED BY INTERNAL OPERATION OF 

ATTINY2313 SPI LCD / RS232 CONTROLLER

T0 SEND CONTROL CHARACTERS.

     Serial.write(CR);

     Serial.write(CD);

         OR

     Comm (CD,0)  (0 for SPI and 1 for RS232)


SEND ASCII 250 AND THEN ANY CONTROL CHARACTER  */


#define CR 250  //TO ACCESS CONTROL REGISTER


/*SEE PAGE 191,192,193 OF HITACHI LCD CONTROLLER HD44780 DATSHEET

0 0 0 0 0 0 0 1   */

#define CD 1    //CLEAR DISPLAY 


//1 ADD ADD ADD ADD ADD ADD ADD

#define L1 0X80   //ROW 0 COL 0

#define L2 0XC0   //ROW 1 COL 0

#define L3 0x94    //ROW 2 COL 0

#define L4 0xD4    //ROW 3 COL 0


// 0 0 0 0 1 D C B

#define CBY 0X0F   //CURSOR ON BLINK ON 00001DCB

#define CBN 0X0C   //CURSOR 0FF BLINK 0FF


#define SCK 13

#define MISO 12

#define MOSI 11

#define RESET 10


//#define START_H 8  // Clock start of PWM light

int START_H=11;

//#define STOP_H 14  // Clock stop PWM light

int STOP_H=23;

int value = 0;     // variable to keep the actual value  

int White = 9;  // White LEDs

int Blue = 3;  // Blue LEDs

int Moon = 5; //Moonlight

int fans = 8; // Fan

int moonVals[31] = {5, 5, 5, 5, 10, 20, 60, 70, 80, 90, 110, 130, 180, 250, 180, 130, 110, 90, 80, 70, 60, 50, 40, 30, 20, 20, 10, 10, 10, 10, 10}; 


int stepper1;

int stepper2;

int lights_fade_time = 1;

int buttonwhite;

int buttonblue;


int temp1 = 0; // temperature variables

int temp2 = 0;

int temp3 = 0;

int sample1[20]; 

int sample2[20];

int range; //temp range

int i;

int alarm1a=0;

int alarm1val=0;

int aval1;

int aval2;

int RCByte;

int TCByte = 0xff; 

int mv = 0;

int tog = 0;

char c[30];

char *MONTH[]={"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};

char *DAYS[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};

//clock setup


#define clockAddress 0x68  // This is the I2C address

// RTC variables 

byte second, rtcMins, oldMins, rtcHrs, oldHrs, dayOfWeek, dayOfMonth, month, year, psecond;


/***** RTC Functions *******/ 

/***************************/ 

// Convert normal decimal numbers to binary coded decimal 

byte decToBcd(byte val) 

{ 

  return ( (val/10*16) + (val%10) ); 

} 


// Convert binary coded decimal to normal decimal numbers 

byte bcdToDec(byte val) 

{ 

  return ( (val/16*10) + (val%16) ); 

} 


// 1) Sets the date and time on the ds1307 

// 2) Starts the clock 

// 3) Sets hour mode to 24 hour clock 

// Assumes you're passing in valid numbers. 

//void setDateDs1307(byte second,        // 0-59 

//                   byte minute,        // 0-59 

//                   byte hour,          // 1-23 

//                   byte dayOfWeek,     // 1-7 

//                   byte dayOfMonth,    // 1-28/29/30/31 

//                   byte month,         // 1-12 

//                   byte year)          // 0-99 

//{ 

//   Wire.beginTransmission(DS1307_I2C_ADDRESS); 

//   Wire.send(0); 

//   Wire.send(decToBcd(second)); 

//   Wire.send(decToBcd(minute)); 

//   Wire.send(decToBcd(hour)); 

//   Wire.send(decToBcd(dayOfWeek)); 

//   Wire.send(decToBcd(dayOfMonth)); 

//   Wire.send(decToBcd(month)); 

//   Wire.send(decToBcd(year)); 

//   Wire.endTransmission(); 

//} 


// Gets the date and time from the ds1307 

void getDateDs1307(byte *second, 

          byte *minute, 

          byte *hour, 

          byte *dayOfWeek, 

          byte *dayOfMonth, 

          byte *month, 

          byte *year) 

{ 

  Wire.beginTransmission(clockAddress); 

  Wire.send(0); 

  Wire.endTransmission(); 


  Wire.requestFrom(clockAddress, 7); 


  *second     = bcdToDec(Wire.receive() & 0x7f); 

  *minute     = bcdToDec(Wire.receive()); 

  *hour       = bcdToDec(Wire.receive() & 0x3f); 

  *dayOfWeek  = bcdToDec(Wire.receive()); 

  *dayOfMonth = bcdToDec(Wire.receive()); 

  *month      = bcdToDec(Wire.receive()); 

  *year       = bcdToDec(Wire.receive()); 

} 



void setup()                    

{

   Wire.begin();

  Serial.begin(57600);



 pinMode(6,OUTPUT);

 pinMode(7,OUTPUT);

  // following delays may not work on all targets...

  pinMode(RESET, OUTPUT);

  digitalWrite(RESET, LOW);

  delay(50);

  digitalWrite(RESET, HIGH);

  delay(50);

  pinMode(SCK, OUTPUT);

  //digitalWrite(SCK, LOW);

  pinMode(MISO, INPUT);

  pinMode(MOSI, OUTPUT);


  spi_init();

  //pinMode(9,OUTPUT);

 //digitalWrite(9,LOW);

 //digitalWrite(10,LOW);

 //delay(50);

 //pinMode(10,INPUT);

 //digitalWrite(10,HIGH);

 // myspi.init();

 digitalWrite(6,LOW);

 LCD_Reset(0);

 digitalWrite(6,HIGH);

 digitalWrite(7,LOW);

 LCD_Reset(0);

 digitalWrite(7,HIGH);

 LCD_Reset(1);


 pinMode(2,INPUT); //button for white

 pinMode(4,INPUT); //button for blue

 digitalWrite(2,LOW);

 digitalWrite(4,LOW);

 pinMode(Blue,OUTPUT);

 pinMode(White,OUTPUT);

 pinMode(Moon,OUTPUT);

 pinMode(fans,OUTPUT);

}




void loop()                     // run over and over again

{

  if(tog==0){

   digitalWrite(7,HIGH);

   digitalWrite(6,LOW);

   tog = 1; }

  else{

   digitalWrite(7,LOW);

   digitalWrite(6,HIGH);

   tog = 0; 

  }


   spi_send(CR);  //  | Alternate |

   spi_send(L1);  //  | Comm(CD)  |



   Serial.write(CR);

   Serial.write(L1);

 // Getting clock data


  getDateDs1307(&second, &rtcMins, &rtcHrs, &dayOfWeek, &dayOfMonth, &month, &year);  


 sprintf(c,"%2.2u:%2.2u  %s %2.2u,%s'%2.2u",rtcHrs,rtcMins,DAYS[dayOfWeek-1

 ],dayOfMonth,MONTH[month-1],year);

     Serial.print(c);

   spi_trans(c);   


    spi_send(CR);

   spi_send(L2);

 Serial.write(CR);

 Serial.write(L2);


for(i = 0;i<=19;i++){ // gets 20 samples of temperature


  sample1[i] = ( 5.0 * analogRead(2) * 100.0) / 1023.0;// to change to analogRead(0

  temp1 = temp1 + sample1[i];

  sample2[i] = ( 5.0 * analogRead(2) * 100.0) / 1023.0;

  temp2 = temp2 + sample2[i];

  delay(50);


  }



temp1 = temp1/20.0; // better precision

temp2 = temp2/20.0; // better precision

   sprintf(c,"HS1=%u%cC HS2=%u%cC ",temp1,0xdf,temp2,0xdf);


 Serial.print(c);

  spi_trans(c);


    //White PWM starts here


  if (temp1 < 69){    //check LED temperature


  if (rtcHrs == START_H && rtcHrs < (START_H + lights_fade_time)){

    if (rtcMins >= 0 && rtcMins <= 30) {stepper1 = map(rtcMins,0,30,0,255);}

     analogWrite(White,stepper1);

  digitalWrite(fans,HIGH);

  analogWrite(Moon,0);  

  }else if(rtcHrs>= (START_H + lights_fade_time) && rtcHrs < (STOP_H - lights_fade_time)){

    digitalWrite(fans,HIGH);

    analogWrite(Moon,0);

    stepper1 = 255;

    analogWrite(White,stepper1);

  }else if(rtcHrs == (STOP_H - lights_fade_time)&& rtcHrs < STOP_H){

      if (rtcMins >= 0 && rtcMins <= 30) {stepper1 = map(rtcMins,0,30,255,0);}

    digitalWrite(fans,HIGH);

    analogWrite(White,stepper1); 

   analogWrite(Moon, moonVals[dayOfMonth-1]); 

  }else if(rtcHrs <START_H || rtcHrs >= STOP_H && rtcHrs <=23){

    digitalWrite(fans,LOW);

    stepper1 = 0;

    analogWrite(White,stepper1);

    analogWrite(Moon, moonVals[dayOfMonth-1]);

  }

  spi_send(CR);

  spi_send(L3);

  Serial.write(CR);

  Serial.write(L3);

    sprintf(c,"Whites = %3u%%",100*stepper1/255);

  Serial.print(c);

  spi_trans(c);


  }else if (temp1 > 70){

  stepper1 = 150;

  analogWrite(White,stepper1);

  digitalWrite(fans,HIGH);

  spi_send(CR);

  spi_send(L1);

   Serial.write(CR);

   Serial.write(L1);

    sprintf(c,"**High Temperature**");

    Serial.print(c);

    spi_trans(c);

  spi_send(CR);

  spi_send(L3);

   Serial.write(CR);

   Serial.write(L3);

    sprintf(c,"Whites = %3u%%",100*stepper1/255);

    Serial.print(c);

    spi_trans(c);

    delay(200000);

}


    //Blue PWM starts here


    if (temp2 < 69){  //check LED temperatures


  if (rtcHrs == START_H && rtcHrs < (START_H + lights_fade_time)){

    if( rtcMins >= 30 && rtcMins <= 60) {stepper2 = map(rtcMins/2,15,30,0,255);}

     analogWrite(Blue,stepper2);

  digitalWrite(fans,HIGH);  

  }else if(rtcHrs>= (START_H + lights_fade_time) && rtcHrs < (STOP_H - lights_fade_time)){

    digitalWrite(fans,HIGH);

    stepper2 = 255;

    analogWrite(Blue,stepper2);

  }else if(rtcHrs == (STOP_H - lights_fade_time)&& rtcHrs < STOP_H){

      if (rtcMins >=30 && rtcMins <=60) {stepper2 = map(rtcMins/2,15,30,255,0);}

    digitalWrite(fans,HIGH);

    analogWrite(Blue,stepper2);  

  }else if(rtcHrs <START_H || rtcHrs >= STOP_H && rtcHrs <=23){

    digitalWrite(fans,LOW);

    stepper2 = 0;

    analogWrite(Blue,stepper2);

  }

  spi_send(CR);

  spi_send(L4);

  Serial.write(CR);

 Serial.write(L4);

    sprintf(c,"Blues  = %3u%%",100*stepper2/255);

  Serial.print(c);

  spi_trans(c);


    }else if (temp2 > 70){

  stepper2 = 150;

  analogWrite(Blue,stepper2);

  digitalWrite(fans,HIGH);

  spi_send(CR);

  spi_send(L1);

   Serial.write(CR);

   Serial.write(L1);

    sprintf(c,"**High Temperature**");

    Serial.print(c);

    spi_trans(c);

  spi_send(CR);

  spi_send(L4);

   Serial.write(CR);

   Serial.write(L4);

    sprintf(c,"Blues  = %3u%%",100*stepper2/255);

    Serial.print(c);

    spi_trans(c);

    delay(200000);

}



   delay(500); 

   spi_send(CR);

   spi_send(CBN); 



   buttonwhite = digitalRead(2);

   buttonblue = digitalRead(4);

   if(buttonwhite == HIGH){

     analogWrite(fans,255);

     analogWrite(Blue,0);

     analogWrite(White,255);

     spi_send(CR);

  spi_send(L3);

   Serial.write(CR);

   Serial.write(L3);

    sprintf(c,"Whites = %3u%%",100);

    Serial.print(c);

    spi_trans(c);

    spi_send(CR);

  spi_send(L4);

   Serial.write(CR);

   Serial.write(L4);

    sprintf(c,"Blues  = %3u%%",0);

    Serial.print(c);

    spi_trans(c);

      delay(20000);} 

     else if (buttonblue == HIGH){

       analogWrite(fans,255);

       analogWrite(White,0);

       analogWrite(Blue,255);

            spi_send(CR);

  spi_send(L3);

   Serial.write(CR);

   Serial.write(L3);

    sprintf(c,"Whites = %3u%%",0);

    Serial.print(c);

    spi_trans(c);

    spi_send(CR);

  spi_send(L4);

   Serial.write(CR);

   Serial.write(L4);

    sprintf(c,"Blues  = %3u%%",100);

    Serial.print(c);

    spi_trans(c);

       delay(20000);}

   /*



*/




   //digitalWrite(6,HIGH);

   //digitalWrite(7,LOW);

   ////BLINK LED CONNECTED TO ATTINY2313 SPI OPTOISOLATED I/O BOARD

  //for (int i=0; i <= 5; i++){


   //TCByte = 0;

   //RCByte = myspi.Transmit(TCByte);

   //delay(500);  


   //TCByte = 0XFF;

   //RCByte = myspi.Transmit(TCByte);


   //delay(500);  

   //}




}


void LCD_Reset(uint8_t inter) //inter is for interface: 0 for SPI: 1 for RS232

{

 Comm(0b00110000,inter);

 delay(5);

 Comm(0b00110000,inter);

 delayMicroseconds(100); 

 Comm(0b00110000,inter);

 Comm(0b00111000,inter); 

 Comm(0b00001100,inter);

 Comm(0b00000001,inter); 

 Comm(0b00000110,inter); 


}


void Comm(uint8_t mval, uint8_t inter){

   if (inter == 0){  

   spi_send(CR);

   spi_send(mval);  }

  if (inter == 1){  

   Serial.write(CR);

   Serial.write(mval);  

}

}


void spi_init() {

  uint8_t x;

  SPCR = 0x53;

  x=SPSR;

  x=SPDR;

}

void spi_wait() {

  do {

  } 

  while (!(SPSR & (1 << SPIF)));

}


uint8_t spi_send(uint8_t  {

  uint8_t reply;

  SPDR=b;

  spi_wait();

  reply = SPDR;

  delay(2);//very importent for the LCD board to process

  return reply;


}

uint8_t spi_trans(const char *str) 

 {

  while (*str)

    spi_send(*str++);

}

[/code]

Member of :
post-1182-0-60431600-1322062247_thumb.jp

post-2241-0-43391700-1354511230.png

UEN: T08SS0098F

MASS in Facebook

Reefing in LED

Link to comment
Share on other sites

Pro-ness~ :welldone:

Mind sharing how much did you spend on this baby?

Not pro la...

Not more than $120, it think.

Costs for the items:

the solid state relay at $20,

LCD $23,

arduino $17,

LCD controller $10,

clock $28,

components like transistor, resistor, box abt $20++ or less.

I would add more features such as internet, but too costly, at $70 I think.

Member of :
post-1182-0-60431600-1322062247_thumb.jp

post-2241-0-43391700-1354511230.png

UEN: T08SS0098F

MASS in Facebook

Reefing in LED

Link to comment
Share on other sites

:welldone::welldone::welldone:

6.5 * 2 * 2 + 3.75 * 1.5 *1.5,(Decomn on 14/9/08)
4*2*2 + 2.5*1.25*1.25 (Decomn on 1/8/09)
5*2*2 (Fully LED light system, 140 3 watt SSC leds with 60 degree lens)(Decomm)
2.5*2*2(Fully LED Light System,96 3 watt SSC leds with 60 degree lens)(Decomm)

5*2.5*2(LED only)

Eheim return 1 * pump

1 HP Daikin compressor with cooling coil
2 Jebao OW40, 1 ecotech MP40,
1X6085 Tunze wm,

1 CURVE 7 Skimmer

  1 DIY 80 led control by Bluefish mini 

1 radion XR30W G2, 2 Radion XR15G3

Sump area lite by 5 ft T5 , 6 * SSC 3 watt red LED for refugium

1 Full spectrum E27 led light

1 CR control by bubble count

Start No Water Change since 1st Dec 2016

Add new 2.5x2x 1.5 ft 

 nLekOfpYts.jpg
[/quote]


 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



×
×
  • Create New...