(Another) DIY LED Controller - Simple Arduino Style

Mike check my code....

My temp does not freezes. I believe most people here has the same problem, but I think I found a way and I am running it right now.

I took the concept of blink without delay. Also used it on my RELAY1 and RELAY2 function. I just duplicated it and created a THEMISTOR function.

Take a look here.

Maybe you can do the same with your DS18B20???

I first created and defined the function PRINTTEMP outside of the loop...

PHP:
/* ******************************************************************************************************************** */
/* *                                                                                                                  * */
/* *                                 D E F I N E  :  T H E R M I S T O R                                              * */
/* *                                                                                                                  * */
/* ******************************************************************************************************************** */


double Thermistor(int RawADC) {
  double Temp;
  // See See http://en.wikipedia.org/wiki/Thermistor for explanation of formula
  Temp = log(((10240000/RawADC) - 10000));
  Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
  Temp = Temp - 273.15;           // Convert Kelvin to Celcius
  Temp = (Temp * 1.8) + 32.0;     // Convert to Fahrenheit
  return Temp;
}

 


void printTemp()
{
  double temp = Thermistor(analogRead(3));                // Read sensor on Pin 3
          lcd.setCursor(9,0);
          lcd.print("   ");
          lcd.print(temp, 0);                             // Prints out Temp, 0 converts it to real numbers, no decimal
          lcd.print((char)223);                           // Prints degree character
          lcd.print("F ");
         
  unsigned long currenttempMillis = millis();             // Use blink without delay to set temp sampling frequency
  if(currenttempMillis - tempMillis > 30000)              // 30 seconds delay between sampling. We do not want
    {                                                     // for our fan to be ON and off too fast.
    tempMillis = currenttempMillis; 
      if (temp > 80)                                     
        {                                                
         digitalWrite(tempPin1, HIGH);                    // If temp is greater than 80, fan is on
         lcd.setCursor(10,0);
         lcd.print("Fan:On ");
        }
      else
        {
         digitalWrite(tempPin1, LOW);                     // If temp is less than 80, fan is off
         lcd.setCursor(9,0);
         lcd.print("Fan:Off ");
        }
    }
}  // End printTemp

Then i just inserted the function and call it out inside the loop for the FADE IN, MAX, and FADE OUT. Together with other functions that need to run while fading in and out.

PHP:
{
          onesecond(); // updates clock once per second
          countdown--;
          relay2();
          relay1();
          printTemp();
        }

Hope this helps.
 
Hey guys,

I did add something similar about a week ago and just have not had a chance to test it out, work has been hectic.

Mike, I am going to post the code that I am currently using below, try it out and let me know if you get the I2C working. I had to check all my 5v wires to see i they were close to 5v to my surprise half were around 2 volts and that was one of the reasons that my LCD was not working. If you wouldn't mind when you get finished with your code, I would like to compare it to mine to see if there is anything that I am missing.

This has been a great thread and I continue to learn.


Thanks,
 

Attachments

Hey guys,

I did add something similar about a week ago and just have not had a chance to test it out, work has been hectic.

Mike, I am going to post the code that I am currently using below, try it out and let me know if you get the I2C working. I had to check all my 5v wires to see i they were close to 5v to my surprise half were around 2 volts and that was one of the reasons that my LCD was not working. If you wouldn't mind when you get finished with your code, I would like to compare it to mine to see if there is anything that I am missing.

This has been a great thread and I continue to learn.


Thanks,

It barfed on when I tried to compile it. It was complaining about the I2C libraries. Maybe mine is different than yours? Also, I have the Uno so I had to change a bunch of pins.
 
LOL,

Mike I probably should have mentioned that it is compiled in 0022, and I may have a different library then you.

Here is a link to the library that I am using, let me know if it still has problems compiling.

http://www.reefprojects.com/LCDI2C-v0.4.zip

Good Luck,

That did the trick. Compiled without error and I uploaded it. I say screw it, I'm using this version. Why reinvent the wheel. You rock. I'm going to take out the stuff I don't need and assign the correct pins to things but this is awesome. Great job!


photo by mikez104, on Flickr
 
Mike Im glad you figure it out. i really like your shield, too bad the one i got as a kit use a different shield. We have the same relay board.

ard2-001.jpg


ard2-009.jpg
 
I have dug through this entire thread and no one has reported what watt the 1K ohm resisters should be. I have 4 1/2s and 4 2 w and i'm not sure if the 2 w are even needed. We would love to have an update for this. Please let us know if possible.
 
I have dug through this entire thread and no one has reported what watt the 1K ohm resisters should be. I have 4 1/2s and 4 2 w and i'm not sure if the 2 w are even needed. We would love to have an update for this. Please let us know if possible.

I use 1/4 watt. Any of yours should be fine.
 
@moncapitane

Which one? are we talking about? If you are talking about the one used for our transistor, then yes 1/4 watt is fine. Sorry I will try to update my webpage.
 
Hey guys,

I did add something similar about a week ago and just have not had a chance to test it out, work has been hectic.

Mike, I am going to post the code that I am currently using below, try it out and let me know if you get the I2C working. I had to check all my 5v wires to see i they were close to 5v to my surprise half were around 2 volts and that was one of the reasons that my LCD was not working. If you wouldn't mind when you get finished with your code, I would like to compare it to mine to see if there is anything that I am missing.

This has been a great thread and I continue to learn.


Thanks,

I took you code and your library and converted them so you can use the latest and greatest Arduino 1.0.1. I posted the libraries and your sketch on a google code site. Here ya go. :beer:

http://code.google.com/p/marduino/downloads/list
 
Mike Im glad you figure it out. i really like your shield, too bad the one i got as a kit use a different shield. We have the same relay board.

ard2-001.jpg


ard2-009.jpg

Was wondering, is the relay board optoisolated? It didn't say it was in the description but looks like it has them on there. I haven't messed with mine yet. I wasn't going to use one. I was just going to dim my LEDs down all the way but then I liked the idea of actually shutting the drivers off so I figured I'd order the board. I like that little proto board that came in your kit.
 
Shutting the drivers off. I believe this is not needed??? I checked the drivers when fully dimmed down with watt mater, they are registering none. As in they are like off. No power being generated, no wattage not even a tiny one.

Maybe a mechanical timer will do the trick?

One thing to note. These relay boards uses a power too that drains arduino too. Everytime I run them, my LCD dim down a bit. Unlike my original relay without the board works really well and the PIN from arduino is enough to run the relay itself. And you are correct, I also believe that they are not optoisolated, im not worried since it has its own electronics inside to protect my arduino... I hope...

The protoboard is not as useful as yours, I like your protoboard since you just screw the wires in... no need to make pins like i did... Pain in the arse...
 
Mike,

Thanks bud, I am glad that you got it working, I like the I2C bus, and the few wires it takes to run the LCD.

Thanks for converting them over, I need to start using the new version...

Do you guys know anything about controlling DC Motors and how they require a MOSFET?

Thanks for the recognition on your page, that is awesome!!!


Thanks,
 
Hey bud,

Just realized you spelled my name wrong in the ino file. Can you please fix it when you get time, I'm a little OCD with spelling names... LOL

Thanks,
 
Hi guys,

Anyone find way to fix dimming part that all function can work during that time ?
I would do, but not so strong in coding. The problem I see is that code stuck in this part whenever it enters it. None other functions are working. Not temp , not timers not others for me.

Would be nice to fix that part in a way that other parts of sketch can stay unmodified if possible. Millis could be the right answer (or not). If arduino can count seconds and put them in to a specific counter like millis - that would make it easy.

Sorry if this was already covered.
 
Last edited:
Hi Arduinophiles!
I am having a very basic issue:
I have just set up my wiring by directly driving my P modell driver with 2n222´s without a pot.
Unfortunately I don´t have a 10v power supply but a 9v one which gives me 8,9V at the output. When I directly hook up the power supply to the white and blue cable of the Meanwell (without 2n222s and without arduino) I get a very bright light on both channels, white and blue.
So far soo god.

Then, I tried to hook up my arduino on pin 3 and 11 and I can power on and off the channels by doing an analogWrite(3, x); and analogWrite(11, x);
The threshold between no power at all and lights on seems to be arround an x value of 35. But now, I have the following problem:

void setup() {

pinMode(11, OUTPUT);

}


void loop() {

analogWrite(11, 40);
delay(5000);
analogWrite(11, 255);


Should switch from low dimming to high dimming every five seconds, but it doesn´t!
It just leaves the light on at the same value, while

void loop() {

analogWrite(11, 20);
delay(5000);
analogWrite(11, 255);

Turns the light on and off every five seconds due to 20 being below the threshold.

What´s the problem here? Can it be the voltage being too low? But I have seen people here also using 9v instead of 10 even on the P modell.

Can I get help please??
 
Hi guys,

Anyone find way to fix dimming part that all function can work during that time ?
I would do, but not so strong in coding. The problem I see is that code stuck in this part whenever it enters it. None other functions are working. Not temp , not timers not others for me.

Would be nice to fix that part in a way that other parts of sketch can stay unmodified if possible. Millis could be the right answer (or not). If arduino can count seconds and put them in to a specific counter like millis - that would make it easy.

Sorry if this was already covered.

katchupoy did a fix back up in post 1621 and RonnyTheReefer described how to fix the problem also back in post 1504. Looks like Katchupoy built a get temp function and called it from the onesecond function since it runs every second. I'm not sure if the other things still freeze during the ramp though. I'm going to start testing and building soon and I am curious about the freezes also.
 
Yes other functions freezes too. Temp is not the only. Thats why I ask if fading has ever been fixed.
Also I too chicken to adapt termistor thing for my needs. Im using regular probe as most others. But as I mentioned temp is not the only problem.

Must dig into Tonys version. Thanks for sharing link.

Hmmm. Seems not to be a final solution...
 
Last edited:
Muda, what other functions are freezing. I haven't had the time to put everything to use to see what is working and what is not.

Thanks,
 
Back
Top