basic LED help

First of all, I'd like to thank you guys for getting me started with LEDs the right way. Definitely trickier than I expected but I did not think about Arduino. Amazing little device.

Anyway, I got an Arduino Uno R3 instead of the nano, got the driver installed and the Arduino program on my computer.

For what I'm trying to do, I need tight control of intensity. For dimming, I want to use momentary switches and an LCD screen that shows % of intensity like the Typhon. I am going to try and wrap my head around a sketch to make this happen. (Is it possible to borrow parts of different sketches to make a custom blended sketch?) I don't know how much you guys want to get involved there-either way I'll post results for this scrubber here when it's working.
 
You can cut and paste code from different sketches, but you will probably have to make a lot of changes to make it work due to different variable names and things. Better way of doing it is to look at the bit of code that does what you want, work out how it does it and then write it yourself into your code. Always better to try and understand how it does things as you have a much better chance of fixing it if it don't work quite right...

Tim
 
I wouldn't mess with trying to "dim" the fan, it can be done from the arduino (I've done it and it works fine) but requires extra hardware to be built and speacial coding for proper control since fans want higher frequency pwm than led drivers (you'll probably have to make the circuit yourself otherwise they are kind of pricey pre made) Just switch the fans on and off via the arduino (even for that you will need an arduino compatible relay ($2-3 on ebay) to isolate the fan from the arduino. The fan may be able to run off the same power supply if it has the right voltage and amperage but you should not supply the power thru the arduino board in most cases the fan will pull too much power for the arduino board to handle.

Is this the kind of relay to run the fans with Arduino?

http://www.ebay.com/itm/5pcs-5V-DC-...295?pt=LH_DefaultDomain_0&hash=item4d2ad9ead7

I've been trying to figure out Arduino in my spare time. I found a sketch to blink two little LEDs and goofed around with the sketch to make the LEDs alternate, but the timing is in milliseconds. So first I wanted to change the milliseconds to minutes. I should have a RTC 1307 any day. Is the RTC the part needed for that and do I need to download a certain library?
 
One of these, you need to isolate the arduino from the relay coil as well. These boards use the same type relay but have some circuitry on board to separate the arduino from the coil via optocoupler. (sort of a tiny relay that runs the relay)

http://www.ebay.com/itm/12V-1-Chann...408?pt=LH_DefaultDomain_0&hash=item1e7ce486e8

You'll need to download and install an RTC library that supports the 1307 (just google it)

There are plenty of tutorials for using the clock and generally the libraries include sample code to work with.
 
The RTC is really just a way to keep time running in the background, even when the device isn't.

To change milliseconds into minutes just do some math (in the program). Or even better a very simple function in your program which has the math in it.

Something like:

int minutesInMs(int m){
return m*60000; // minutes * 60 seconds * 1000 milliseconds
}

Then whenever you need a minute value in ms in the sketch you just use it like: minutesInMs(5) for 5 minutes in ms. =D
 
Zachts, The fans are 5V and I plan to power the Arduino with 5V from the same wall wart. Would a 5V relay be a better choice for me than 12V?

Gorgok, I did try multiplying the ms and it seemed to work but I was dealing with ridiculously big numbers. I'm going to try to understand that coding you gave me. I was thrown by ms.=D, now I realize ms. does not equal D, that's a happy face. LOL I still have to work on understanding that code.

Thanks guys!
 
Zachts, The fans are 5V and I plan to power the Arduino with 5V from the same wall wart. Would a 5V relay be a better choice for me than 12V?

Yeah, just look for the same thing in 5v (it's referencing the coil voltage of the relay, so if your running the fans on 5v then that would be the way to go)
 
Gorgok, I did try multiplying the ms and it seemed to work but I was dealing with ridiculously big numbers. I'm going to try to understand that coding you gave me. I was thrown by ms.=D, now I realize ms. does not equal D, that's a happy face. LOL I still have to work on understanding that code.

Thanks guys!

The main block of the code (the function definition) can be anywhere in the sketch, out of any loops and such. Its just a little helper function so you don't have to write 6*60000, or 10*60000, etc every time you want a time in minutes converted into millisec. There may be similar ones in some of the libraries for all i know, i don't do arduino stuff but the code is in C so its all the same.

Usage example could have been more clear indeed... But heres a more practical one (this is a copy/paste of the blink example Arduino has on the net):
Code:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(6*60000);               // wait for a 6 minutes
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(10*60000);               // wait for a 10 minutes
}
Alternately using the little function:
Code:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(minutesInMs(6));
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(minutesInMs(10));   
}

// Returns minutes in milliseconds
int minutesInMs(int m){
return m*60000; // minutes * 60 seconds * 1000 milliseconds
}

The problem with the first one is if you have to do that a lot you risk missing or adding a 0 in there eventually, changing the time. Also eventually you will go to change the code and not remember precisely why its 60000 (or some other number, if you had one for days, and hours as well). Sure you can keep comments all over the code to help you remember, but a function whose name explains what it does is pretty clear even without comments.
 
Last edited:
Thanks Gorgok-that code did the trick! I had to change the "int" to "long". I was under the assumption that an RTC was needed but what time it is doesn't matter, so no RTC.

I'd like to control the intensity as well as the alternate timing with push button switches and an LCD. Do you think changing the int to long will create a memory shortage on my Uno?

Thanks zachts for steering me in the right direction for the fan relay. This is the two channel relay that's on the way. For each half of the scrubber, four LDDs will have their dim pins connected in parallel. Would it be good practice to also connect a fan relay to the same pin?

http://www.ebay.com/itm/371030375305?_trksid=p2059210.m2749.l2649&ssPageName=STRK:MEBIDX:IT
 
it would likely work using the relays you got (since an optocoupler is essentially a tiny led that is turned on by the arduino then read by a light sensor which triggers a small transistor that switches the relay, shouldn't hurt anything if it works) but generally No. run the relay off one of the digital pins since it really only wants on/off (High/Low) signal to function.
 
What I hope to achieve is to control brightness as well as photoperiod and display it on an LCD.

I thought I’d be able to copy and paste parts of other sketches since Arduino is open source, but I have spent hours and hours spinning my wheels.

I downloaded the liquid crystal library from the sketch program, but am having trouble downloading the button library from the Arduino home site. Will I need the EEPROM library?

Back in post 19, the sketch shows up as a bunch of odd characters- IDK what the deal is there. When I first looked at it I thought that’s how it’s supposed to look.

I bought a 16x2 LCD, but would the built in controller in this make things easier for me? Could I forgo the button library if I used this display? http://www.ebay.com/itm/2-8-Inch-TF...284?pt=LH_DefaultDomain_2&hash=item23486af45c

Pull up or down resistors on button switches, hookups, soldering etc. are no problem, it’s the software that’s killing me.

Can the dimming control be separated from the photoperiod control as far as writing the sketch is concerned?

I am asking a lot, I know. The only thing I can offer in return would be advice or ideas for working on your house. I’ve earned a living for a lot of years remodeling both interior and exterior. Being the DIY crowd, I’m sure you’re handy but still, I’ve learned a couple old timer tricks.
 
What I hope to achieve is to control brightness as well as photoperiod and display it on an LCD.

Back in post 19, the sketch shows up as a bunch of odd characters- IDK what the deal is there. When I first looked at it I thought that's how it's supposed to look.
If you opened it in the arduino program it should look pretty straight forward and all be in simple English. If you're seeing gobbledy gook then try downloading and unzipping the file again. might have been corrupted. Should look just like this:
Code:
/*

This is a simple 5v Analog to PWM converter for the Arduino.
Meant to be used with an Arduino Nano or equivalent.
Made by asid61 of reefcentral.com, or MeepNand of nano-reef.com.
This supports up to 6 PWM outputs. Controlled via 10K Ohm Reverse Audio Anti Log Taper Potentiometers
*/

int read1, read2, read3, read4, read5, read6;

void setup()
{
  //This is the PWM outputs. Make sure to connect the grounds!
  pinMode(3, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  //Attach potentiometer middle pins to these pins.
  pinMode(A1, INPUT);
  pinMode(A2, INPUT);
  pinMode(A3, INPUT);
  pinMode(A4, INPUT);
  pinMode(A5, INPUT);
  pinMode(A6, INPUT);
}

void loop()
{
  read1 = analogRead(A1);
  read2 = analogRead(A2);
  read3 = analogRead(A3);
  read4 = analogRead(A4);
  read5 = analogRead(A5);
  read6 = analogRead(A6);
  
  analogWrite(3, read1/4);
  analogWrite(5, read2/4);
  analogWrite(6, read3/4);
  analogWrite(9, read4/4);
  analogWrite(10, read5/4);
  analogWrite(11, read6/4);
}

I bought a 16x2 LCD, but would the built in controller in this make things easier for me? Could I forgo the button library if I used this display? http://www.ebay.com/itm/2-8-Inch-TF...284?pt=LH_DefaultDomain_2&hash=item23486af45c
a touch screen will make programing the interface something of a nightmare as a beginner project. LCD with a few buttons will be relatively straight forward once you get the hang of it. follow the example tutorials out there to see how the code for different pieces of hard ware works.

Can the dimming control be separated from the photoperiod control as far as writing the sketch is concerned?
Yes, but at some point in the sketch they will be linked and the photoperiod code will over ride the dimming code and shut off the lights. look at using "else" and "if" statements on the arduino home page.
 
I've been at this most of today, I need to let it go for now. I sure wish the button library was included in the sketch window list. I spent, no wasted a lot of time trying to get the button library downloaded. Once I get that sorted out, I'll lift some code from the Typhon sketch and see if that can be made to work. The Typhon dims by percentage which is perfect.

Then, wire the buttons with their pull down or pull up resistors and hook up the LCD. Get some meaningful dimming numbers from the LCD. Does that sound like a logical start?
 
Can you tell us exactly what gear you have, how you've connected it, and what you're trying to achieve?

If you can get your head round electronics and basic circuit design, you can do an arduino sketch design!

The mindset is similar. But, butchering multiple skecthes and trying to merge them into one, is a very quick route to confusion and insanity :p

Tim
 
I have Arduino Uno and it's plugged into my computer with a USB cord like a printer would use.
I want to adjustably alternate two banks of 40 3W LEDs with the ability to dim them independently. Adjust using buttons and an LCD. Like the Typhon.
So now, I have a couple little bitty LEDs on a breadboard, each LED representing a bank of 3W LEDs.

I have to be honest, I can follow and build from a schematic but I can't say I have a firm grip on circuitry.

Concerning confusion and insanity, if you include a great deal of frustration I'm already there.(;
This is what I have so far. It looks like I have the button library, but I copied and pasted it from another sketch and the "Button" did not turn orange like the Liquid Crystal or EEPROM libraries I downloaded from the sketch window. I am not sure if EEPROM is needed for my sketch. Will I need the Wire library to allow the buttons to communicate with the LCD?

I appreciate you guys looking at this and helping me kick it around.

Edit: This is weird, but none of the libraries I downloaded show up in the post even though they appeared in the message box.

#include <EEPROM.h>
#include <LiquidCrystal.h>
#include <Button.h>
int redLED = 8;
int redFAN = 9;
int blueLED = 10;
int blueFAN = 11;
long minutesInMs(int m){
return m*60000; //converts milliseconds to minutes
}


void setup() // run once, when the sketch starts
{
pinMode(redLED, OUTPUT); // sets the digital pins as outputs
pinMode(redFAN, OUTPUT);
pinMode(blueLED, OUTPUT);
pinMode(blueFAN, OUTPUT);
}


void loop() {
digitalWrite(redLED, HIGH);
digitalWrite(redFAN, HIGH);
digitalWrite(blueLED, LOW);
digitalWrite(blueFAN, LOW);
delay(minutesInMs(1));
digitalWrite(redLED, LOW);
digitalWrite(redFAN, LOW);
digitalWrite(blueLED, HIGH);
digitalWrite(blueFAN, HIGH);

delay(minutesInMs(1));
}

// Returns minutes in milliseconds
 
I've been at this most of today, I need to let it go for now. I sure wish the button library was included in the sketch window list. I spent, no wasted a lot of time trying to get the button library downloaded. Once I get that sorted out, I'll lift some code from the Typhon sketch and see if that can be made to work. The Typhon dims by percentage which is perfect.

Then, wire the buttons with their pull down or pull up resistors and hook up the LCD. Get some meaningful dimming numbers from the LCD. Does that sound like a logical start?
You might be better off just writing your own code since all you really need is to dim the leds and display the level (it would be simpler to just display the level of pwm from 0-254 on the display, but not too much extra work to convert that to percent I suppose)

the only other thing you need is adjustment of photo period (on/off)

the bigest challenge will be writhing the user interface and menus to be able to program it all from the arduino and buttons (that can get compicated)

your basically writhing code for a two channel lamp timer with intensity control....
 
Last edited:
Depends on the sketch you use in your code.

I'm not much of a programer, but buttons can be used without use of any libraries. I tend to keep my projects simple and use the computer to adjust parameters rather than mess with writing complicated user interfaces.

Manually adjusting dimming on your setup should be pretty easy with a button or a pot and then displaying the set level. adjusting the photoperiod with the user interface is beyond my programing skils. I'd just set it via computer (hard coded into the sketch) and adjust as needed by plunging into the computer.

I don't see you needing to make too many adjustments as you can achieve maximum photosynthesis by adjusting dimming first and then fine tune the photo period from time to time (even if that means pluging into the computer.) rate of photosynthesis will vary A LOT depending on nutrient load so I thing adjusting light level will be the simplest way to maximize the effectiveness of the setup.

that's just my two cents to get you up and running faster.
:beer:
 
Back
Top