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

Monday, July 9, 2012

LDR - Light sensor

For a coming project I'll need to know if a room has the lights on or off.
That's when a Light Dependent Resistor (LDR), or photocell comes in handy.

As usual, Ladyada provides an excellent tutorial on understanding and using electronics: Ladyada's 101 on LDR

I also found useful info here.

For the LDR that I have, I'm using this Datasheet. I'm not sure if this is the correct datasheet, but for this component I think it should be close enough.

The quantity of light can be measured in Lux, Lumen or Candela depending on several factors.
Here's some more info.

In this case, here's a table of some real world approximate Lux values, in order to understand the values we need to read:

Light source LUX
---------------------------
Moonlight 0.1
60W Bulb at 1m 50
1W Bulb at 0.1m 100
Fluorescent Lighting 500
Bright Sunlight 30,000

The resistance of a LDR can vary from +/-400 Ohm (for Bright Sunlight) to +/- 2 MOhm (in the Dark), depending also on the make of the component.

Here are some of the values I measured (from bright to dark):







Sunday, May 20, 2012

Bedflower

As I couldn't find a decent and cheap lamp to attach to my bed as a reading light, I decided to build one.

I saved some deodorant bottles as they have a nice shape and can be used in some projects.
I noticed that some light bulb screw bases I had fit perfectly in those bottles.



For the neck I used wire wrapped in a long screw for shape and strengthened it with more wire inside to have a flexible but strong neck.



As a base I chose make it out of wood so I tried to saw some squares that would connect with a 45º angle cut, but the nails I have are to big for that cut and the wood block chipped.



Then I drilled the blocks to pass the lamp's neck and some screws that will be used to secure the base to the bed.



After some polishing,



I nailed the pieces together and polished again:


These are the switches I applied to make the wires from the base to the wall wart:



Then I secured the neck to the base using the neck wire and a nail to fixate it, and secured the electrical wire as well.



I connected the switch so that it covers the holes where the screws go into, making it more aesthetic.



And here are the screws applied to the base.



So were almost there.



To make it more appealing I covered the neck of the lamp in a painters tape.
It looks kind of pretty in this photo, doesn't it? Sadly, that's the only case...



So here's the end result.



In the end, I don't think this is much appealing or practical as it is.
I made lots of mistakes on this that I was able to correct and others that I couldn't.

But the main idea is solid and when possible I will make a better version of this.
---------------------------------------------------------------------------------

Time to some improvements!

The wood panels were too small and would easily come out of the bed, so I switched to some bigger ones. But now they are too big to be plain.

I decided to try a little design:



With a X-Acto I cut on the wood some leaf design I found on Google and with my old soldering iron burned the wood to create the pattern you see above.

But I didn't feel it was enough. The upper part was still ugly.
So I tried another artistic approach:




I bought some disposable table spoons (used about 30 for testing and the final look) and glued them to a piece of toilet paper roll.


After two layers of glued spoons, I added other two layers of bent spoons and covered the hot glue at the base with some painters tape to hide the mess.


The final result is a beautiful (I think) flower:




What do you think?

Thursday, November 17, 2011

First Hack - The LED Strip

Finally finished my first hack.

I needed a light for my kitchen counter, so I ordered a LED Strip from eBay and hacked an AC adapter to include an ON / OFF button and to connect it to mains without using a power socket.

So here's the theoretical work:

To cover the surface of my counter I used 48 segments of the LED strip (about 2 meters). Each segment has 3 white SMD leds (type 3528) and a 150 Ohm resistor. For it to work it needs a 12V power source with sufficient current output.
After learning from [ladyada] about these strips I figured that the theoretical current each segment needs to function at it's maximum is 16 mA. That is:
12V total - (3 leds * 3.2V) / 150R = 0.016A

For the total 48 segments that's 768 mA, resulting in under 10W lighting!!!
For that I bought a SMPS AC adapter in order to guarantee the regulated 12V while using that much current. An average (unregulated) AC adapter wouldn't provide nor the 12V neither near the maximum 1A stated. [ladyada] also shed me some lights on that matter.

White LED StripSuitable AC AdapterThe best switch button I could find

For the practical work:

As you will see for yourself, the tools weren't exactly the best suited for the job: a kitchen knife to cut, a soldering iron to remove plastic, a hammer and a nail to open holes...

The innards of a power outletMains power derivationAdhesive cable duct

In order to cut the space for the switch button in the AC adapter, my kitchen knife wasn't enough, so I used my soldering iron to heat a metal needle and a kind of a thick clip used by stores to keep shirts folded in it's package. Even so it was a hard work.

Pierced top cover from the AC AdapterCreating the space for the switch buttonThe working conditions

Then I just needed to solder the switch button and the wire to the board and cover it all with electrical tape.

The final cutConnecting the switch buttonThat's a wrap

And there we have it!
Our working LED Strip!


Thursday, April 14, 2011

How a LCD monitor works!

Here is a fantastic video of how a LCD Monitor works:
LCD Monitor

Thursday, March 17, 2011

RGB LED Part II

After some absence, I finally got some weekend time to play with my electronics.
Now that I have 100 new RGB LEDs, it’s time for some experiments.

I wanted to know how to control the colors emitted by this LEDs so here’s how I did it.

First I searched for a datasheet and found this one on Sparkfun.
According to it, the recommended current is 20mA, and the voltages are 2.0V, 3.2V and 3.2V for red, green and blue. As I wrote on my last post, each color has a different lead, and there is another for Ground (GND). These are common cathode LEDs, as it receives energy on the leads for the colors and all that energy is returned to the circuit on a single lead.

As I source all my projects with the Arduino connected to the laptop (as it already is a regulated power source), I calculated the resistors for a 5V source power.

V=R.I
Red --> (5 – 2.0) / 0.20 = 150 Ohm
Green / Blue --> (5 – 3.2) / 0.20 = 90 Ohm (The closest I have is 100 Ohm)


Connecting all wires, we can see that 3 different tiny LEDs lit up inside our 5mm RGB LED as you can see below.

Also we can see that we can’t count on a mixed color far from the LED, as the three parts point to different directions, although there might be some ways to try to improve that situation.

So the LED lights up. Big deal! Let’s play some more...

The next step is to be able to combine the three colors into making new colors.

First I tried to make a simple program on the Arduino using a (very, very poor) simulated PWM. Basically I would light up only one color at a time and tried different delay() times, to control the ‘quantity of color embedded’ in the final result. That idea came from the LED matrix project, as some kind of multiplexing.
Please, don’t waste your time on something like this.

After some online searching, I saw that the best way is to use ‘real’ PWM, as in using the PWM pins in the Arduino and analogWrite() the value (0-255) for each color. This controls the voltage at the pin, altering the luminosity of the LED. It is best to keep all color lit at the same time (not using delay()).

So now we can programmatically define the color we want to obtain, in theory. Again, with clear LEDs, it is kind of hard to observe a good mix of the light emitted by the three ‘sub-LEDs’.

But isn’t it cooler to be able to mess with those values by hand? So enter the potentiometers (pots).
My first try was to use 3 pots, to control each color. As two of them aren’t ‘breadboard friendly’, you can see below what a mess it is to connect it all.


But then I thought: “What a good opportunity to try to use push buttons.”
So I replaced the 3 potentiometers by 3 push buttons, and altered the Arduino program to cycle through the values for each color.
A simple control to avoid altering the values too much in one push was to have a small delay() after the digitalRead() of each button.




You might notice some resistors connected from each button to GND in parallel with the reader pins of the Arduino.
Those are push-down resistors.

And here is the code:
int R = 9;
int G = 10;
int B = 11;

int vR = 0;
int vG = 0;
int vB = 0;

int T = 200;
int d = 15;

void setup() {
pinMode(R, OUTPUT);
pinMode(G, OUTPUT);
pinMode(B, OUTPUT);
pinMode(7, OUTPUT);

pinMode(2, INPUT);
pinMode(3, INPUT);
pinMode(4, INPUT);

digitalWrite(7, HIGH);
}

void loop() {
if(digitalRead(2) == HIGH)
{
vR+=d;
if(vR>l)
vR=0;

delay(T);
}

if(digitalRead(3) == HIGH)
{
vG+=d;
if(vG>l)
vG=0;

delay(T);
}

if(digitalRead(4) == HIGH)
{
vB+=d;
if(vB>l)
vB=0;

delay(T);
}

analogWrite(R, vR);
analogWrite(G, vG);
analogWrite(B, vB);
}


So to end it, I wanted to create a demo to cycle to all colors as simply as possible. I found ‘Hue-controllable RGB LED lamp‘ that shows how to cycle through the colors using only a Hue value.
I tried to use the conversion code directly from http://www.easyrgb.com/math.php?MATH=M21#text21, but all the values were quite wrong, so I lazily used the code akgraphics provided on the first post.
As the code was kind of slow because of lots of (unnecessary) math, I reduced it to:

void setup() // run once, when the sketch starts
{
//Serial.begin(9600); // set up Serial library at 9600 bps
}

void h2rgb(float H, int& R, int& G, int& B) {
int var_i;
float S=1, V=1, var_1, var_2, var_3, var_h, var_r, var_g, var_b;

var_h = H * 6;
if ( var_h == 6 ) var_h = 0; //H must be < 1
var_i = int( var_h ) ; //Or ... var_i = floor( var_h )

//var_1 = V * ( 1 - S );
var_1 = 0;

//var_2 = V * ( 1 - S * ( var_h - var_i ) );
var_2 = ( 1 - ( var_h - var_i ) );

//var_3 = V * ( 1 - S * ( 1 - ( var_h - var_i ) ) );
var_3 = ( var_h - var_i );

if ( var_i == 0 ) {
var_r = V ;
var_g = var_3 ;
var_b = var_1 ;
}
else if ( var_i == 1 ) {
var_r = var_2 ;
var_g = V ;
var_b = var_1 ;
}
else if ( var_i == 2 ) {
var_r = var_1 ;
var_g = V ;
var_b = var_3 ;
}
else if ( var_i == 3 ) {
var_r = var_1 ;
var_g = var_2 ;
var_b = V ;
}
else if ( var_i == 4 ) {
var_r = var_3 ;
var_g = var_1 ;
var_b = V ;
}
else {
var_r = V ;
var_g = var_1 ;
var_b = var_2 ;
}

R = (1-var_r) * 255; //RGB results = 0 ÷ 255
G = (1-var_g) * 255;
B = (1-var_b) * 255;
}

void loop() // run over and over again
{
for(int val=0;val<1024;val++)
{
//Serial.println(val);
float h = ((float)val)/1024;
int h_int = (int) 360*h;
int r, g, b;
h2rgb(h,r,g,b);

analogWrite(9, r);
analogWrite(10, g);
analogWrite(11, b);

delay(10);
}
}