Arduino Forum

Using Arduino => Programming Questions => Topic started by: njs707 on Jun 12, 2011, 04:21 am

Title: Fade led with Infrared input
Post by: njs707 on Jun 12, 2011, 04:21 am
I am making an interactive LED circuit that takes a calibration reading at the beginning, then checks against that during the loop.  I am using an infrared emitter, infrared photodiode, and an led.. ( with obvious other components like resistors, capacitors, etc.).  What I want my program to do better is led fading.  When my hand is as far away as the sensor will allow as a change, the led should be fairly dim, growing brighter and brighter as my hand gets closer to the receiver.  My code can sort of do this, but instead of being smooth, the led pulses when my hand is anywhere but as close as possible to the receiver.  I need it to be a very smooth transition as my hand gets closer and closer... brighter and brighter.  Here is the code to test this...

Code: [Select]

int threshold;

void setup()

{

   pinMode(10,OUTPUT);
   pinMode(12,OUTPUT);
   threshold = analogRead(A5);
   delay(100);

}

void loop()

{

   int Receiver = analogRead(A5);
   digitalWrite(12,HIGH);
   
    if( Receiver < ( threshold - 3 ))
       
        analogWrite(10,1);
       
    if( Receiver < ( threshold - 3)) && ( Receiver < ( threshold - 4)) // checks for when the Receiver is less than ( receiver - 4)
   
       analogWrite(10,5);
       
       
       // ... and so on... all the way to about (threshold - 45) .. so I skip Receiver val every 1, but the analogWrite val every 4, because of scaling issues
       
       
       else
       analogWrite(10,0);
       }



any ideas on how to make it smoooooooth?
Title: Re: Fade led with Infrared input
Post by: Grumpy_Mike on Jun 12, 2011, 06:57 am
Google the term running average
Title: Re: Fade led with Infrared input
Post by: njs707 on Jun 12, 2011, 07:27 am
ok new question...

as I said my setup is working fairly well, but a few things could be better, for instance, the sensitivity.  I can get the led to turn on when my hand is about 4 inches away from the sensor, but what can I say, I'm American and I want MORE.  Id like to be able to have the led turn on at about twice the distance.  I think using a transistor, which I have in my possession, would help achieve this.  Not sure how to plug it in from A5 and ground and + 5 volts and all that though.  Also, do I need a resistor or capacitor for any reason with this?

Thanks
Title: Re: Fade led with Infrared input
Post by: TomS on Jun 12, 2011, 02:23 pm
If you need more distance you will either have to improve sensitivity on the detector side or light intensity on the emitter side.

I assume you were referring to a phototransistor although this will only help if it is more sensitive than your photodiode.

Easiest and most direct way would be to increase light output of your emitter. Get one with more power or a smaller beam angle, this will immediately improve maximum distance.

For more detailed recommendations you will have to provide more information on your current setup and parts...
Title: Re: Fade led with Infrared input
Post by: njs707 on Jun 12, 2011, 06:46 pm
Using these products from mouser..

PIN PHOTODIODE .... 512-QSD2030F

EverLight infrared led 940 nm .... 638-IR333C/H0/L10

94k ohm resistor with the photodiode...

200 ohms with the led...


thanks

Title: Re: Fade led with Infrared input
Post by: njs707 on Jun 12, 2011, 07:07 pm
How about an IR emitter like this  from mouser

782-TSAL5100    = 1000 mW/sr           ( the one I use now is 450 mW/sr )

... too much or no??