AdSense

Showing posts with label Light. Show all posts
Showing posts with label Light. Show all posts

Monday, 17 February 2014

Control LED strip with ATmega / Arduino

(Deutsche Version) LED strips have been gaining more and more popularity within the last few years. There are even LED strips for less than 20 euro from china. Usually, an LED strip consists of a control unit, a power supply and a remote. For most people, this is sufficient. Anyone who wants to have more (e.g. run through sequences) has to put in a little effort.

Let's primarily face the structure of the strip. There are four connections, one of them is for the + 12 V power supply, the other three connections are for the individual colours. The strip is working like this: If you apply + 12 V and then connect ground to one of the colour connections, this colour is shining. The brightness is now controlled vie PWM. To fully control the LED strip you need:
  • A microcontroller (ATmega / Arduino)
  • 3 bipolar transistors (NPN) which can handle enough current!
The microcontroller sends 3 PWM signals to the base of the transistors (apply pre-resistors, I use 470 Ohms). The emitter of the transistors is connected to ground (a common ground of the 12 V power supply and the microcontroller), the collector is connected to the corresponding colour channel.

To control a single color, you have to execute:


analogWrite(8, 127);

This command will set the transistor which is connected to pin 8 to 50% (255 is the maximum), so the connected colour has 50% brightness. You can only use PWM channels for this (in the data sheet usually referred as OCR).


To achieve any color, you have to mix the colors. therefore, you have to choose a colour in the RGB space, e.g. orange: this colour is R: 255, G:255, B:0. Now you have to program this into the microcontroller:


analogWrite(RED_PIN, 255);
analogWrite(GREEN_PIN, 255);
analogWrite(BLUE_PIN, 0);  

It could occur that different colours are seen at different brightness, you should test this and then set the maximum limit e.g. for green to 127 (green appears very bright for the human eye, therefore the green colour could be too bright.

Thursday, 24 October 2013

Control RGB LED with ATmega16A

(Deutsche Version) RGB LEDs are pretty interesting (e.g. if they are in an LED strip). Today, I want to explain how to control an RGB LED with an ATmega16A. At first a short introduction to the RGB LED: I use this LED from Tayda Electronics. This LED consists of three different LEDs which are all in the same body. Therefore, there are 3 pins for the different LEDs and a common cathode (-). If you apply a PWM signal to these 3 pins, you can control the color of the LED. I use the ATmega16A because the ATmega8 only has 2 PWM channels, this is not enough for 3 pins. This should cover the basics for an RGB LED, here is the code which runs through the whole colour space:

#include <avr/io.h>
#define F_CPU 16000000UL
#include <util/delay.h>

int main(void)
{
  DDRA = 0xFF;//Output
  DDRD = 0xFF;
  ICR1 = 256;
  TCCR2 = (1<<WGM20) | (1<<COM21) | (1<<CS20); // PWM, phase correct, 8 bit.
  TCCR1A = (1<<WGM10) | (1<<COM1A1) | (1<<COM1B1); // PWM, phase correct, 8 bit.
  TCCR1B = (1<<CS10);// | (1<<CS10); // Prescaler 64 = Enable counter, sets the frequency
  double rCounter = 255;
  double rMax=255;
  double bCounter = 255;
  double bMax = 180;
  double gCounter = 0;
  double gMax = 70;
  int stages = 0;
  while(1)
  {
    switch (stages)
 {
   case 0:
     bCounter --;
     if (bCounter <= 0)
  {
    stages = 1;
  }
  break;
      case 1:
     gCounter ++;
     if (gCounter >= 255)
  {
    stages = 2;
  }
  break;
   case 2:
     rCounter --;
     if (rCounter <= 0)
  {
    stages = 3;
  }
  break;
   case 3:
     bCounter ++;
     if (bCounter >= 255)
  {
    stages = 4;
  }
  break;
   case 4:
     gCounter --;
     if (gCounter <= 0)
  {
    stages = 5;
  }
  break;
   case 5:
     rCounter ++;
     if (rCounter >= 255)
  {
    stages = 0;
  }
  break;
 }
 OCR1B = (int)(bCounter*bMax*bCounter/255/255);
 OCR1A = (int)(gCounter*gMax*gCounter/255/255);
 OCR2 = (int)(rCounter*rMax*rCounter/255/255);

 _delay_ms(5);
  }

}

Monday, 9 September 2013

Comparison of different lamps

(Deutsche Version) Today I want to compare three lamps which could be suitable as room light. The candidates are:
a) An "old" halogen bulb
b) A helical energy-effective lamp (Link)
c) A COB-LED (Link)

At first the specifications:
a) Power: 40 W
luminous flux: 390 Lum
life time: 2 000 h
price: 2 €

b) Power: 23 W
luminous flux: 1 550 Lum
life time: 10 000 h
price: 8 €

c) Power: 7 W
luminous flux: 560 Lum
life time: >10 000 h (no value on Pollin.de, approximately 25 000 h)
price: 6 € (with heat sink, the LED only costs 3 €)

The first point of comparison is: How much light comes out of how much power? I show the values in Lum/W:
a) 10
b) 67
c) 80
The LED and the energy-effective lamp are clearly winning at this point.

The next point: how much light comes out of how much money? Here are the values in Lum/€:
a) 195
b) 194
c) 95
The LED looses this competition because LEDs are more expensive.

As the most important point of comparison I want to light a room for 5 years. I assume 5000 Lum and 6 hours of light per day, this are about 2000 hours. How many lamps would I need to reach the 5000 Lum?
a) 13
b) 3
c) 9
If you consider the life time, all halogen bulbs have to be switched every year, whilst the energy-effective lamp and the LED survive the whole 5 Jears. This increases the costs for the halogen bulbs by a factor of 5. The prices for the lamps are:
a) 128
b) 26
c) 53
consider: The costs for the LED are 50% for the heat sink. Now i want to examine the power consumption:
a) 1026 kWh
b) 148 kWh
c) 125 kWh
If I assume 20 ct / kWh, the costs for 5 jears are:
a) 205
b) 30
c) 25

The cheapest one is the energy-effective lamp. For the LED: Please note that the costs are basically only 50% because of the heat sinks. Additionally, an LED lasts much longer than an energy-efficient lamp, in the long term, the LED wins this competition because it also has a slightly smaller power consumption.

LED room light - selfmade

(Deutsche Version) At Pollin, there are COB-LEDs for sale (Pollin). The great thing about them is that they don't need any resistor or anything else, you just have to apply the suitable voltage and a heat sink.
560 lm is quite a lot, I will compare different light sources in a different post. The great advantage of LEDs is that they are effective and have a very high life time so maybe the future belongs to LEDs. The only problem with this LED is that the light comes out of a very small area and the LED is very bright and is eventually dangerous for the eye. Therefore, I had to build a lamp shade. I used greaseproof paper. The instructions are very simple, you only should ensure that b > a/2, otherwise there will be a hole in the middle.
Cut along the red edges. Afterwards fold the vertical dottet lines about 90° so the paper makes a closed cylinder. Afterwards, the flaps have to be folded over and the whole thing is some kind of bucket which can be put over the lamp. The final result is the following: