Green Digit Electronics

RGB ledstrip controller

inleiding

Creative Commons-Licentie

As I had this LED strip lying around i decided to make my own Controller for it. I based it on the Arduino Uno featuring the Atmega328p, and 3 BD139 npn Transistors.
The common anode configuration of the led strip makes the cheaper NPN transistors perfect for the job.

Schematic

The circuit is build around the popular Atmega328P (to be precise an Arduino Nano). The reason here for was an easy development of the software.
I did require 3 PWM outputs and an arduino sounded the best solution at that moment of my knowlegde.

To Change the color os the ledstrip i added 3 NO buttons and 3 leds (1 led of each color (RGB)). The leds indicate the color i'm changing. The center button (see pictures below) is the "Enter" button, the other 2 te Up and Down. When the maximum intensity has been reached the led of that color will flash faster then in normal change operation.

Afterwards i did change the resistor value of the leds as they were to bright and distracting in low light environments. The resistors between the microcontroller and the Transistor base have been chosen while testing, a 1k&Omega resistor seemed to be the best solution. You'll notice that i did not use any pull-up of pull-down resistors for the buttons, this is because the pcb i had was to much damaged and I din't want to go out to get a new one. So i desided to use the internal pull-ups.

Board:

Aangezien de schakeling op gaatjes print gemaakt is heb ik geen moeite gestoken in het maken van een print.

Pictures:

Code:

The code has been writen in the arduino IDE tool.
In the code fragment you find bellow I chose to use variables to point to a specific pin on the arduino. This makes it easyer to modify my code later on without the need of to much comments.
The ledstrip is controlled using PWM on pins 9-11 on the arduino (no pun intended with the 9-11 notation).
For the led indication i chose to use pins 8,12 and 13, i did remove the onboard led from the arduino.
The buttons use pins 2,4 and 7. Configured to be used as inputs with the internal (weak) pullups.

int red = 10;
int green = 11;
int blue = 9;
int lred = 12;
int lblue = 13;
int lgreen = 8;
int up = 7;
int down = 2;
int ok = 4;

void setup() {
 pinMode(up,INPUT_PULLUP);
 pinMode(ok,INPUT_PULLUP);
 pinMode(down,INPUT_PULLUP);
 pinMode(lblue,OUTPUT);
 pinMode(lred, OUTPUT);
 pinMode(lgreen,OUTPUT);
}
The variables for the PWM are stored in the EEPROM Memory, for ease of acces i copy them in a global variable to preserve EEPROM from to many read/write cycles. At first the values are 0, or any random value that has been writen to the EEPROM before. There is no need to store the values by hand. this is an automated function.
The current code has 4 diferent 'modi' that can be configured seperatly: Red, Green, Blue, and all 3 colors. I did plan to add a 5th but never took the time for it. The variable 'bump' is used to track in what state the Menu is at any given moment.
//variable configuration
int vred = 0;
int vgreen = 0;
int vblue = 0;
int bump = 0;
int mode = 0;
At startup all leds are turned on seperatly so you can do a visual check for defects if required.
void test(){
 analogWrite(red,255);
 digitalWrite(lred,HIGH);
 delay(1000);
 analogWrite(red,0);
 digitalWrite(lred,LOW);
 digitalWrite(lgreen,HIGH);
 analogWrite(green,255);
 delay(1000);
 analogWrite(green,0);
 digitalWrite(lgreen,LOW);
 digitalWrite(lblue,HIGH);
 analogWrite(blue,255);
  delay(1000);
 analogWrite(green,255);
 analogWrite(red,255);
 digitalWrite(lgreen,HIGH);
 digitalWrite(lred,HIGH);
 delay(1000);
 analogWrite(blue,0);
 analogWrite(green,0);
 analogWrite(red,0);
 digitalWrite(lgreen,LOW);
 digitalWrite(lblue,LOW);
 digitalWrite(lred,LOW);
}
And because i'm to lazy to repeat myself i created a small function to update the PWM signal.
void update(){
 analogWrite(red,vred);
 analogWrite(green,vgreen);
 analogWrite(blue,vblue);
}
The rest of the code is actualy just the menu. Tracking the status of the menu, and updating the colors of the ledstrip when requested by user input.
Is this the best way to implement this menu? No, but at the time of creating this project i just started of with electronics as a hobby, and that was before my electronics education.
void loop() {
 test();
 while(1){
   update();
   int bok = digitalRead(ok);
   if(!bok){
  flash();
  }
  while(!bok){
  int bok2 = digitalRead(ok);
  int bup = digitalRead(up);
  int bdown = digitalRead(down);
  int bump = bok2;
  if (!bump){
  digitalWrite(lred,HIGH);
  digitalWrite(lgreen,HIGH);
  digitalWrite(lblue,HIGH);
  delay(500);
  }else{
  digitalWrite(lred,LOW);
  digitalWrite(lgreen,LOW);
  digitalWrite(lblue,LOW);
  }
  while(!bump){
  bup = digitalRead(up);
  bdown = digitalRead(down);
  bok2 = digitalRead(ok);
  if(!bok2){
  bump = 1;
  delay(200);
  }
  if(!bup){
  vred++; vgreen++; vblue++;
  if(vred == 256){
   vred = 255;
   digitalWrite(lred,LOW);
   delay(15);
   digitalWrite(lred,HIGH);
  }
  if(vgreen == 256){
   vgreen = 255;
   digitalWrite(lgreen,LOW);
   delay(15);
   digitalWrite(lgreen,HIGH);
  }
  if(vblue == 256){
   vblue = 255;
   digitalWrite(lblue,LOW);
   delay(15);
   digitalWrite(lblue,HIGH);
  }
  if(vblue == 255 && vgreen == 255 && red == 255){
   flash();
  }
  update();
  delay(50);
  }
  if(!bdown){
  if(vred == 0){
   vred = 1;
  }
  if(vgreen == 0){
   vgreen = 1;
  }
  if(vblue == 0){
   vblue = 1;
  }
  vred--; vgreen--; vblue--;
  update();
  delay(50);
  }
}
}
}}

Creative Commons-Licentie
GD Led-Strip Controller van Frederick Roels is in licentie gegeven volgens een Creative Commons Naamsvermelding-GelijkDelen 4.0 Internationaal-licentie .