Hello everybody,
I am building a RGB ledstrip controller. Now I used TIP122 to drive this high currents.
The first powerup worked, my LEDstrip gave the requested RGB color. But after a couple of seconds, the LEDstrip flashed a little bit.
I thought it was the PWM code so I tried to fix it, but when I placed the Atmega328 back in the circuit, the LEDstrip does just nothing.
Is it possible that the TIP122 failed or something else?
My code:
#include <SoftPWM_timer.h>
#include <SoftPWM.h>
#include <TimedAction.h>
/*
******************************************
* Trainduino *
* *
*----------> RGBLEDCONTROLLER <----------*
* *
* V 0.9.6 PRERELEASE *
******************************************
THIS IS A PRERELEASE! I'm never resposibly for any damage to your stuff! This version is also NOT completely tested.
(c) Dylan Van Assche (2013 - 2014), producer of the Trainduino serie.
*/
#define RED_PIN 2
#define GREEN_PIN 3
#define BLUE_PIN 4
#define WHITE_PIN 5
int red = 230;
int green = 230;
int blue = 75;
int white = 0;
int redValue = 255;
int greenValue = 255;
int blueValue = 255;
int whiteValue = 255;
boolean Status = true;
TimedAction RGBTimer = TimedAction(1000, RGB);
TimedAction Clock = TimedAction(500, ClockFunction);
int currentHour = 7; // Start ALWAYS the program in DAY mode. Day is from 07:00 to 19:00.
int currentMinutes = 0;
void setup() {
SoftPWMBegin(); // Start the SoftPWM library.
pinMode(RED_PIN, OUTPUT); // Setup RED_PIN for SoftPWM.
SoftPWMSet(RED_PIN, 0);
SoftPWMSetFadeTime(RED_PIN, 4000, 4000);
pinMode(GREEN_PIN, OUTPUT); // Setup GREEN_PIN for SoftPWM.
SoftPWMSet(GREEN_PIN, 0);
SoftPWMSetFadeTime(GREEN_PIN, 4000, 4000);
pinMode(BLUE_PIN, OUTPUT); // Setup BLUE_PIN for SoftPWM.
SoftPWMSet(BLUE_PIN, 0);
SoftPWMSetFadeTime(BLUE_PIN, 4000, 4000);
pinMode(WHITE_PIN, OUTPUT); // Setup WHITE_PIN for SoftPWM.
SoftPWMSet(WHITE_PIN, 0);
SoftPWMSetFadeTime(WHITE_PIN, 4000, 4000);
randomSeed(A5);
}
void loop() {
Clock.check(); // Time tracking process.
if (Status) // DAY.
{
redValue = 230;
greenValue = 230;
blueValue = 75;
whiteValue = 255;
RGBTimer.check(); // Every time the RGBTimer is triggered, changes the PWM output. With this timer you can change the colors of the RGB LEDstrip very slowly.
}
else // NIGHT.
{
redValue = 40;
greenValue = 12;
blueValue = 100;
whiteValue = 0;
RGBTimer.check(); // Every time the RGBTimer is triggered, changes the PWM output. With this timer you can change the colors of the RGB LEDstrip very slowly.
}
}
void RGB() // This function controls the RGB LEDstrip.
{
if (red < redValue)
{
red = red++;
SoftPWMSet(RED_PIN, red);
}
else
{
red = red--;
SoftPWMSet(RED_PIN, red);
}
if (green < greenValue)
{
green = green++;
SoftPWMSet(GREEN_PIN, green);
}
else
{
green = green--;
SoftPWMSet(GREEN_PIN, green);
}
if (blue < blueValue)
{
blue = blue++;
SoftPWMSet(BLUE_PIN, blue);
}
else
{
blue = blue--;
SoftPWMSet(BLUE_PIN, blue);
}
if (white <= whiteValue)
{
if(whiteValue == 0) // Keeps the white LED OFF. Otherwise it sticks in an ON/OFF loop...
{
}
else
{
white = white++;
SoftPWMSet(WHITE_PIN, white);
}
}
else
{
white = white--;
SoftPWMSet(WHITE_PIN, white);
}
}
void ClockFunction()
{
currentMinutes++;
if (currentMinutes == 60)
{
currentHour++;
currentMinutes = 0;
if (currentHour == 7)
{
Status = true; // DAY
}
if(currentHour == 20)
{
Status = false; // NIGHT
}
if(currentHour == 24)
{
currentHour = 0;
}
}
}
PCB & Schematic see attachment.
I added a wire to connect the 12V input with the LEDstrip...
Cheers,
Dylan