On/Off functin for meanwell HLG style drivers using dimming and arduino

VegasWinner

Well-Known Member
So far I am using a typhon controller for testing with the adafruit outlet controller. it is working fine with no inrush current issues so far. I have two otehr receptacle controllers set aside from building in case this does not work. Lights all came on on time and went off on time 24 hours now, including Royal Blues, Deep Red, IR, and Far Red including both cob's on and off on time. I am working on the open source code, now that I have found a good Lcd shield with a rotary encoder; potentiometer to scroll through menus. I have to add a real time clock, RTC circuit to the arduino, taking away two more pins, so it seems the arduino mega2560 is going to be the workhorse for this project, more pin outs available both digital and analog. I removed four timers, three lpc drivers, and I a pile of extension cords, no longer needed, just an arduino, a 48v power supply, an ldd driver, and two receptacles controlled by the arduino to turn lights on/off. peace
 

VegasWinner

Well-Known Member
I have been working. i am using an adafruit i2c lcd shield, because it only uses two analog pins. the dht11 uses another analog pin. The rtc will use another analog pin as well. So I have been working hard over here. here is the dhtll code sketch for arduino uno with a dht11 and an adafruit i2c lcd shield. code can be modified for any lcd shield. peace
=============================
#define DHT11_PIN 0 // ADC0 Analog pin A0
// include the library code:
#include <Wire.h>
#include <Adafruit_RGBLCDShield.h>
#include <utility/Adafruit_MCP23017.h>


// The shield uses the I2C SCL and SDA pins. On classic Arduinos
// this is Analog 4 and 5 so you can't use those for analogRead() anymore
// However, you can connect other I2C sensors to the I2C bus and share
// the I2C bus.
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();

// These #defines make it easy to set the backlight color
#define RED 0x1
int LCD_C=16;
int LCD_R=2;
int dhtTemp=0;
int dhtHumidity=0;

// end of i2c rgb lcd shield definitions

void setup()
{
DHTSetup();
SPrintBegin();
PrintBegin();
PrintTempMenu();
} // end setup

void loop()
{
GetDHTData();
PrintTempMenu();
} // end loop

// ---Functions----//
// setup ddrc and portc
void DHTSetup(){
DDRC |= _BV(DHT11_PIN);
PORTC |= _BV(DHT11_PIN);
}
// read dht11 data line for input
byte read_dht11_dat()
{

byte i = 0;
byte result=0;
for(i=0; i< 8; i++)
{
while(!(PINC & _BV(DHT11_PIN))); // wait for 50us
delayMicroseconds(30);
if(PINC & _BV(DHT11_PIN))
result |=(1<<(7-i));
while((PINC & _BV(DHT11_PIN))); // wait '1' finish
}
return result;
}
// serial printbegin
void SPrintBegin()
{
Serial.begin(9600);
Serial.println("Ready");
}
// print setup routine
void PrintBegin()
{
lcd.begin(LCD_C, LCD_R);
lcd.clear();
lcd.setCursor(0,0);
} // end PrintBegin
// print temperature menu on line 1 on lcd
void PrintTempMenu()
{
lcd.setCursor(0,0);
lcd.print("Temp: F/RH: %");
lcd.setCursor(5,0);
lcd.print(dhtTemp);
lcd.setCursor(13,0);
lcd.print(dhtHumidity);
lcd.setCursor(15,0);
lcd.print("%");
}
// read data for input from dht11 temp/humidity sensor
void GetDHTData()
{
byte dht11_dat[5];
byte dht11_in;
byte i;// start condition
// 1. pull-down i/o pin from 18ms
PORTC &= ~_BV(DHT11_PIN);
delay(18);
PORTC |= _BV(DHT11_PIN);
delayMicroseconds(40);
DDRC &= ~_BV(DHT11_PIN);
delayMicroseconds(40);

dht11_in = PINC & _BV(DHT11_PIN);
if(dht11_in)
{
Serial.println("dht11 start condition 1 not met");
lcd.print("DHT11 checksum error");
return;
}
delayMicroseconds(80);
dht11_in = PINC & _BV(DHT11_PIN);
if(!dht11_in)
{
Serial.println("dht11 start condition 2 not met");
return;
}

delayMicroseconds(80);// now ready for data reception
for (i=0; i<5; i++)
dht11_dat = read_dht11_dat();
DDRC |= _BV(DHT11_PIN);
PORTC |= _BV(DHT11_PIN);
byte dht11_check_sum = dht11_dat[0]+dht11_dat[1]+dht11_dat[2]+dht11_dat[3];// check check_sum
if(dht11_dat[4]!= dht11_check_sum)

{
Serial.println("DHT11 checksum error");
}
dhtTemp=(int)round(1.8*dht11_dat[2]+32);
dhtHumidity=(int) dht11_dat[0];
} // end read data
======
enjoy
VW
 

Organic Miner

Well-Known Member
This awesome @VegasWinner , this was gonna be my next project after getting my lights built! Hopefully you will have all the kinks worked out before I get there.

Any plans to create a GitHub project to share all your code and schematics? I like version control and traceability.
 

VegasWinner

Well-Known Member
This awesome @VegasWinner , this was gonna be my next project after getting my lights built! Hopefully you will have all the kinks worked out before I get there.

Any plans to create a GitHub project to share all your code and schematics? I like version control and traceability.
I do plan on using gitHub to share the code. I am thinking it will be easy for folks with experience in arduino's and coding. I am using a breadboard to run these devices concurrently, as a shield would take away all the pins from other devices. :( I am documenting the project. I want to make it inexpensive and easy to assembly as a DIY kit. I still have to hook up the RTC breakout board. waiting for the batteries, so I can test and complete coding on that device. I am also looking at a 16 channel PWM driver for the big boys to dive larger groups of DIY lights. After I have all the devices needed, I can start the in-depth programming to integrate the devices. I am sure some folks here have some experience with using CO2 with arduino's and sensors. if they share that part, it is a complete grow room controller for the DIY crowd. peace
Vegas
 

Organic Miner

Well-Known Member
I do plan on using gitHub to share the code. I am thinking it will be easy for folks with experience in arduino's and coding. I am using a breadboard to run these devices concurrently, as a shield would take away all the pins from other devices. :( I am documenting the project. I want to make it inexpensive and easy to assembly as a DIY kit. I still have to hook up the RTC breakout board. waiting for the batteries, so I can test and complete coding on that device. I am also looking at a 16 channel PWM driver for the big boys to dive larger groups of DIY lights. After I have all the devices needed, I can start the in-depth programming to integrate the devices. I am sure some folks here have some experience with using CO2 with arduino's and sensors. if they share that part, it is a complete grow room controller for the DIY crowd. peace
Vegas
I have contemplating how to build in scalability into my lights so I don't have to do a major overhaul to control them later. In the end I will have 18 individual light units to cover the room, so I would need more than 16 channels, and that's a lot wire running around the room. Really like the idea of individual wireless controllers in each light controlled by a master controller, but that won't be cheap; maybe for the high end user. Or maybe a local wireless unit that controls 4 light units via cables, a comprise. Just thoughts for now, I will monitor progress, and help out where I can. I am couple of months away from starting the automation project.

Keep up the good work.
 

qballizhere

Well-Known Member
I have contemplating how to build in scalability into my lights so I don't have to do a major overhaul to control them later. In the end I will have 18 individual light units to cover the room, so I would need more than 16 channels, and that's a lot wire running around the room. Really like the idea of individual wireless controllers in each light controlled by a master controller, but that won't be cheap; maybe for the high end user. Or maybe a local wireless unit that controls 4 light units via cables, a comprise. Just thoughts for now, I will monitor progress, and help out where I can. I am couple of months away from starting the automation project.

Keep up the good work.
I will be doing one with the raspberry pi 3 since it has on board wifi and ble Im looking at more of home automation control and control it wifi or through your cell
 

Organic Miner

Well-Known Member
I will be doing one with the raspberry pi 3 since it has on board wifi and ble Im looking at more of home automation control and control it wifi or through your cell
I looked into this a year ago, but shelved because time constraints. I think a combination of raspberry pi's and Arduino's will be the most cost effective. I like the cell phone app, but my first goal is a database and website so I can start gather data to make automated decisions. Gotta gather the data first; plus I like plots and graphs.

Keep us informed of your progress.
 

VegasWinner

Well-Known Member
What's the point for the normally on and normally off labels. Kinda weird.
two of the outlets are always on, the other two are controlled by the 5vdc logic. you get two outlets for normal use and two outlets for controlled use.they work just fine. I have been using them for two weeks now. no problems. Lights ramp up, go bright, ramps down and go off. No more timers and controls, just one led controller.peace
 

VegasWinner

Well-Known Member
I have been looking into another option. I have found an arduino board that allows for 16 PWM signals separate control. The arduino can have up to four of these boards as each board is controlled by one PWM signal. Four of these boards would allow the control of 64 LED light fixtures like the ones @REALSTYLES, @mau5 and others have in large numbers. I am going to experiment with one of these boards, but I already know th outcome. It will be great. Imagine controlling all of your lights from one location and one timer for various times on/off and brightness. here is the link to the board. ->https://www.adafruit.com/products/815

The sky is then limit on how many fixtures can be controlled by one arduino with proper programming. I have completed the temp/humidity section, the lcd section, and I am working on the input section, menus controls portion. I plan on keeping the menu straightforward and direct, start time, stop time, ramp up time, ramp down time, brightness levels, individual channel controls and recycle timers control. peace
 

VegasWinner

Well-Known Member
I will be doing one with the raspberry pi 3 since it has on board wifi and ble Im looking at more of home automation control and control it wifi or through your cell
They now have a WiFi shield for the arduino and an app too for smartphones. I am not going for public connections, b t others may do that on their own. I prefer offline and secure from internet. prying eyes and all. Eventually you can have a system with internet cameras to check just like daycare does. I did the Unix before I am going to stick with arduino. peace
 

VegasWinner

Well-Known Member
I have decided to use the i2c RGB shield for a couple of reasons. 1. It can be hooked up with just four pins. 2. It has five buttons, left, right, up, down, and select for a menu controll mechanism and setting variables. The shield can be bought as a kit and takes many 16x2 lcd's both monochrome and color back light. Her is the code for the shield I will be using, along with the temperature and humidity sensor.
------------------------------
/*********************

i2c RGB LCD Shield with 5 buttons and display
**********************/
// include the library code:
#include <Wire.h>
#include <Adafruit_RGBLCDShield.h>
#include <utility/Adafruit_MCP23017.h>
// The shield uses the I2C SCL and SDA pins. On classic Arduinos
// this is Analog 4 and 5 so you can't use those for analogRead() anymore
// However, you can connect other I2C sensors to the I2C bus and share
// the I2C bus.
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();

// These #defines make it easy to set the backlight color
#define RED 0x1
#define YELLOW 0x3
#define GREEN 0x2
#define TEAL 0x6
#define BLUE 0x4
#define VIOLET 0x5
#define WHITE 0x7
// setup variables
int LCD_C=16;
int LCD_R=2;
int time=0;
uint8_t i=0;
// setup
void setup() {
// Debugging output
SPrintBegin();
// set up the LCD's number of columns and rows:
PrintBegin();
PrintMessage();
// Print a message to the LCD. We track how long it takes since
// this library has been optimized a bit and we're proud of it :)
lcd.print("Hello, world!");
GetTime();

}// end setup

// loop
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis()/1000);
ReadButtons();

} // end loop
// -- Functions---//
// print setup routine
void PrintBegin()
{
lcd.begin(LCD_C, LCD_R);
lcd.clear();
lcd.setCursor(0,0);
} // end PrintBegin
void PrintMessage()
{
GetTime();
Serial.print("Took "); Serial.print(time); Serial.println(" ms");
lcd.setBacklight(WHITE);
}
// end PrintMessage
// ReadButtons
void ReadButtons()
{
uint8_t buttons = lcd.readButtons();

if (buttons) {
lcd.clear();
lcd.setCursor(0,0);
if (buttons & BUTTON_UP) {
lcd.print("UP ");
lcd.setBacklight(RED);
}
if (buttons & BUTTON_DOWN) {
lcd.print("DOWN ");
lcd.setBacklight(RED);
}
if (buttons & BUTTON_LEFT) {
lcd.print("LEFT ");
lcd.setBacklight(RED);
}
if (buttons & BUTTON_RIGHT) {
lcd.print("RIGHT ");
lcd.setBacklight(RED);
}
if (buttons & BUTTON_SELECT) {
lcd.print("SELECT ");
lcd.setBacklight(RED);
}
}
}
// end ReadButtons
// GetTime
void GetTime()
{
int time = millis();
time = millis() - time;

} // end getTime
// serial printbegin
void SPrintBegin()
{
Serial.begin(9600);
Serial.println("Ready");
}// end SPrintBegin

This sketch will read and interpret the buttons allowing for menu control, which I will add later.

I am waiting for batteries for ther Real Time Clock module RTC, so I can ad that code and set up the master file, as well. enjoy the two pieces so far, temp/humidity sensor and lcd and button controls. peace
Vegas
 

VegasWinner

Well-Known Member
Here is the data data about the PWM board i am looking at and will be testing.

When we saw this chip, we quickly realized what an excellent add-on this would be. Using only two pins, control 16 free-running PWM outputs! You can even chain up 62 breakouts to control up to 992 PWM outputs (which we would really like to see since it would be glorious)
  • It's an i2c-controlled PWM driver with a built in clock. That means that, unlike the TLC5940 family, you do not need to continuously send it signal tying up your microcontroller, its completely free running!
  • It is 5V compliant, which means you can control it from a 3.3V microcontroller and still safely drive up to 6V outputs (this is good for when you want to control white or blue LEDs with 3.4+ forward voltages)
  • 6 address select pins so you can wire up to 62 of these on a single i2c bus, a total of 992 outputs - that's a lot of servos or LEDs
  • Adjustable frequency PWM up to about 1.6 KHz
  • 12-bit resolution for each output - for servos, that means about 4us resolution at 60Hz update rate
  • Configurable push-pull or open-drain output
  • Output enable pin to quickly disable all the outputs
How many of you guys have over 900 fixtures. Control over 900 fixtures from one arduino. peace

As far as coding goes. I learned to code in CPM/M and BCD, as well as Machine Code. very unforgiving. I moved to C, C+ and eventually C++, I created my own GUI before windows was up and running using DB2 for a foundation. I learned to be modular a long time ago and still continue that today. thanks for the note.
peace
Vegas
 

VegasWinner

Well-Known Member
By the time I am finished i expect to have shared all the code I develop right here with you folks for your use, or I may offer a DIY kit through some source, to include the LCD shield, RTC module, Temp/humidity sensor, cabling, two electric controlled outlets, arduino uno with coding installed and running. All would be needed would be to connect the pieces or get it an assembled kit.
I plan on developing two units, a home unit and a commercial unit. The home unit will have six control signals, four for lights and two for recycle timers. The commercial unit will have the same system with 16-64 control signals available. beyond 64 channels, we would have to talk. lol
peace
Vegas
 

Organic Miner

Well-Known Member
By the time I am finished i expect to have shared all the code I develop right here with you folks for your use, or I may offer a DIY kit through some source, to include the LCD shield, RTC module, Temp/humidity sensor, cabling, two electric controlled outlets, arduino uno with coding installed and running. All would be needed would be to connect the pieces or get it an assembled kit.
I plan on developing two units, a home unit and a commercial unit. The home unit will have six control signals, four for lights and two for recycle timers. The commercial unit will have the same system with 16-64 control signals available. beyond 64 channels, we would have to talk. lol
peace
Vegas
Nice!

Do you have any photos of what you are building that you are willing to share?
 

VegasWinner

Well-Known Member
I have produced pictures of the components. the arduino is in pieces all over my desk. Figuring out to connect an lcd shield with buttons, a humidity/temperature sensor, a real time clock module all over the place, all wanting the same pins too . When I add the 16 channel driver, it will be even larger. I plan on putting the package in a small job box with connectors and the lcd mounted on the outside with the buttons. I will put pin connectors to connect channel cables on the outside too.

It will definitely be bigger than the aquarium controllers due to keeping costs down and performance up. I figure a larger grower can run 25 pair cat 5 cable with 24 signal lines and one common ground at 5v control voltage. For smaller home folks, a controller with two outlets four channels, two for leds and two for cobs, and two channels for recycle timers, flood and drain and aeroponics.

Working on the main menu code. most important. The main menu will be setup, channels, timers, and sensors. I will need assistance form those folks ujsing CO2 and PI or arduino to work out the CO2. I have temp and humidity already worked out. Main menu will look like this. Setup -> Clock, Time/Date, TempDisplay (f/C), Channels, Timers, Sensors. Channels->All On, All Off, Auto Mode, Set/Modify, Timers-> Set/Modify, Sensors->Set/Modify, Exit. Unit will run , displaying time and temp until key interrupt to display menu and change setup of components. For those with leds, a meanwell 48v power supply and LDD drivers would be best to dim and control leds, Far Red, Royal Blue, Deep Red, IR, Green, etc to drive the leds just like the cob's.

Everything will be at one location, timers, controllers, everything. no more timers, no more expensive recycle timers, as well for F&D and aero systems, including cloners. All you need is the outlet controller to control pumps and motors, etc.

I just have to work out who I can get to host my systems for you guys, like cutters or other DIY guys out there to buy and send units anonymously with confidence. I see the future and it is controlled by an led controller, in a tent, in a basement, in a closet, in a bedroom, or in a warehouse. peace
Vegas
 
Top