Pages: [1]   Go Down
Author Topic: LED sensing  (Read 994 times)
0 Members and 1 Guest are viewing this topic.
malaysia
Offline Offline
Full Member
***
Karma: 1
Posts: 101
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hey.. im try to make led as sensing.. but my serial port read not constant..
this coding should turn on led when in dark, but my led keep turning even in light condition..is my arduino got problem?
when i simulated i got
when in light, led turn on with blink
when in dark, led turn on not blink
Code:
int sense01 = 5;        // sensing LED connected to analog5
   
                                               
int LED01 = 3;          // LED on dig3
 
                       
int val01 = 0;          // variable to store the value read from sense01
     

int light = 217;        // set light threshold

void setup()
{
  Serial.begin(9600);          //  setup serial
  pinMode(LED01, OUTPUT);
  digitalWrite(LED01,LOW);

}

void loop()
{
  val01 = analogRead(sense01);      // read sense01 led
     
 
  Serial.println(val01);            //debug print
 
 if (val01 >= light) {              // check if light
      digitalWrite(LED01, LOW);     // if light, turn off led
    } else {                     
      digitalWrite(LED01,HIGH); 
    }

   
   

« Last Edit: March 06, 2011, 04:53:27 am by dut » Logged

dut eden rockes

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

LEDs don't work in reverse. Unless you're talking about something else, there's no way that will work. You need a photoresistor or a photodiode of some sort.

Also, if you're trying to take an input that's not either on or off (digital), you have to use one of the Analog pins. You can't analogRead from a digital pin.
Logged

malaysia
Offline Offline
Full Member
***
Karma: 1
Posts: 101
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i read from here http://www.instructables.com/id/LEDs-as-light-sensors/

taking analogRead from analog pin..
but my reading is not constant why?
Logged

dut eden rockes

UK
Offline Offline
Faraday Member
**
Karma: 16
Posts: 2883
Gorm deficient
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
LEDs don't work in reverse
Sorry, but yes they can!

http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.69.1570&rep=rep1&type=pdf

You're not using the LED correctly - read the paper I linked, it is very good.
« Last Edit: March 06, 2011, 06:49:25 am by Groove » Logged

Per Arduino ad Astra

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
LEDs don't work in reverse
Sorry, but yes they can!

http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.69.1570&rep=rep1&type=pdf

You're not using the LED correctly - read the paper I linked, it is very good.

Wow, sorry, I had no idea. Either way I think he wants to use an analog pin rather than a digital pin, though.
Logged

UK
Offline Offline
Faraday Member
**
Karma: 16
Posts: 2883
Gorm deficient
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No, I think an analogue conversion on the AVR would be too slow for this.
In essence, you're measuring the discharge of a capacitor, so time is more important.

As an aside, it was an area I was fascinated by as a teenager, that many transducers could be used as sensors, like a loudspeaker used as a microphone.
« Last Edit: March 06, 2011, 07:10:23 am by Groove » Logged

Per Arduino ad Astra

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No, I think an analogue conversion on the AVR would be too slow for this.
In essence, you're measuring the discharge of a capacitor, so time is more important.

As an aside, it was an area I was fascinated by as a teenager, that many transducers could be used as sensors, like a loudspeaker used as a microphone.

Fair enough, but then comparing it to a value that's not high or low would be moot, I'd think.
Logged

malaysia
Offline Offline
Full Member
***
Karma: 1
Posts: 101
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

led react as ldr in reverse bias..
i connect led in reverse pin 0 to res 330ohm+kathode+anode+gnd

when i try to read a=analogRead(A0);
Serial.println(a);
it give me not accurate value when dark or light..
what is problem?
Logged

dut eden rockes

0
Offline Offline
Newbie
*
Karma: 1
Posts: 38
Turn it off!!!!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
led react as ldr in reverse bias..

I'm afraid that isn't true.  You should read through that instructable again.

You don't need a resistor at all actually.  Simply connect the cathode (short pin) to ground, and the anode (long pin) to an analog pin.  The 217 threshold value isn't to bad, but you will have to adjust it to your specific LED and lighting conditions.

And LED used this way actually acts like a solar cell -- it produces power.  The current is very low, but the voltage can be as high as the forward driving voltage of the LED.

To Groove, yes, that paper outlines one way to read LEDs as a sensor, however, that is not the easiest way.  It does let you read them with a digital pin though, which could be advantageous in some circumstances.  I would suggest you do that mini experement outlined in the instructable.  Measure the voltage on a meter from an LED.
Logged

Ohio - USA
Offline Offline
Full Member
***
Karma: 0
Posts: 104
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What a fascinating topic!! I had no idea this was possible, so when I got to the PDF link I took the time to read their whole paper. The whole time I was reading it I was wondering what I would see if I simply applied light to a typical 5mm LED and measured it with a DVM. So when I read your last post above I decided to do just that. I chose a blue LED (just arbitrary color choice) and measured about 50mV with it standing vertically under my fluorescent lighted bench magnifier, about a foot above it. I then laid the LED on its side and used an LED flashlight which has 109 bright white LEDs, and got as much as 230 mV from the LED! I had the flashlight about a foot away from the LED. In the rather bright incandescent-replacement fluorescent lighting I have in this room I can read 3 mV from the LED simply oriented vertically in my lap. So if the circuit being used with such an LED as an input could distinguish the difference of a few mV ( I know a comparator could do it) the LED does indeed make a good light sensor. I wonder why this idea never went to market on a massive scale? The ideas they present in that paper seem like good ideas, and very inexpensive to implement.

I am very new to the Arduino, and still working through beginner level books experimenting with it. Can the Arduino differentiate single mV readings and have their programming react on them?
Logged

      Zoandar
  ---v/\/\/\v---

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 551
Posts: 46240
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Can the Arduino differentiate single mV readings and have their programming react on them?
You do the math. The analogRead function returns a value in the range 0 to 1023, based on the measured voltage with respect to VRef. If VRef is 5V (the default value), the analogRead function's step size is ~5mV.
Logged

malaysia
Offline Offline
Full Member
***
Karma: 1
Posts: 101
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

it) the LED does indeed make a good light sensor. I wonder why this idea never went to market on a massive scale? The ideas they present in that paper seem like good ideas, and very inexpensive to implement.
Yes the LED is a very good in light sensor. it been produce in a big scale name LDR or photodiode..LED is just LED and when it use as light sensor it name is LDR or photodiode/phototransistor..


by try and error again, i used black IR led. it is very sensitive. it will react in very dark place, and when in light room even a small light it will detect them..but it is not suitable to use on outside room, natural light come from the sun..the red led is good for outdoor..

the problem is, when i put red led, it read not constant. i get 1023 900 655 0 0 544 1023 0 0 300..
is it my arduino analoqread going something wrong?
Logged

dut eden rockes

0
Offline Offline
Newbie
*
Karma: 1
Posts: 38
Turn it off!!!!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Yes the LED is a very good in light sensor. it been produce in a big scale name LDR or photodiode..LED is just LED and when it use as light sensor it name is LDR or photodiode/phototransistor..

An LED indeed functions as a photodiode.  However, phototransistors and LDR (light dependent resistors) work rather differently.  A LDR literally changes resistance depending on how much light strikes it.  A phototransistor is essentially a photodiode connected to the base of a NPN transistor.  An LED and photodiode, on the other hand, actually are current/voltage
Quote
sources
, and could be used in the place of a battery (they don't provide anywhere near the power needed for any normal circuit though.)

Quote
the problem is, when i put red led, it read not constant. i get 1023 900 655 0 0 544 1023 0 0 300..
is it my arduino analoqread going something wrong?

How fast does it cycle?  60hz?  If the IR LED worked correctly, then you would need to assume it is a hardware problem, or due to lighting conditions.  Make sure the longer lead is connected to the analog pin, and the shorter one to ground.

Hey Zoandar, try a different color LED (green,) or a meter with lower input impedence.  I just did the same test with two difference LEDs and they both had much more voltage difference.  One was just a standard green LED (not super bright, and it had a green diffuse case,)  The other was a bi-color green/red three pin LED (also not super bright, and it has a white diffuse body.)  The two green LEDs gave me 1.5-1.7V, and the red one was more like .7V.  This is compared to 100-200mV for ambient light.  I used a single LED super bright mini flashlight, pointed right into the LEDs from an inch or so away.
Logged

Ohio - USA
Offline Offline
Full Member
***
Karma: 0
Posts: 104
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Can the Arduino differentiate single mV readings and have their programming react on them?
You do the math. The analogRead function returns a value in the range 0 to 1023, based on the measured voltage with respect to VRef. If VRef is 5V (the default value), the analogRead function's step size is ~5mV.

Thanks Paul. I have not gotten deeply enough into the arduino yet to have known this information. smiley
Logged

      Zoandar
  ---v/\/\/\v---

Ohio - USA
Offline Offline
Full Member
***
Karma: 0
Posts: 104
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote

Hey Zoandar, try a different color LED (green,) or a meter with lower input impedence.  I just did the same test with two difference LEDs and they both had much more voltage difference.  One was just a standard green LED (not super bright, and it had a green diffuse case,)  The other was a bi-color green/red three pin LED (also not super bright, and it has a white diffuse body.)  The two green LEDs gave me 1.5-1.7V, and the red one was more like .7V.  This is compared to 100-200mV for ambient light.  I used a single LED super bright mini flashlight, pointed right into the LEDs from an inch or so away.

Actually I did just that after posting. It seems my choice of the blue LED which came with my arduino starter kit just happened to be the lucky choice to be the most impressive in voltage output for this experiment. The rest of the colored lens 5mm LEDs saw much lower voltage under the same bright flashlight conditions.

I have a few "ultra-bright white" 5mm LEDs which have 'water clear' lenses. Those saw as high as 1.3V when I put them closely in the beam of that flashlight, and they may actually produce in excess of 5mV under the ambient light in this room. It would depend upon how I oriented them and how close to the ceiling they were. As PaulS explained above, if they will exceed 5mV the arduino could then work with them as an ambient light detector. I should mention though that the 'viewing angle' on the LED doing the sensing is very critical, and not very wide, in order to achieve these numbers.

However, the article that launched this discussion talks of normal LEDs illuminating each other. I have yet to try that (I think the next experiment in the book I am following lights an LED constantly on or off, so that would be a good time to measure this) but I can't imagine the light from a single LED producing much of a voltage on another LED in its path of illumination. So they must be working with very tiny voltage levels, such as those a comparator could sense.

It is cool that I just happened to read this thread last night, because I have a project in mind where I need to remotely indicate when an LED on a device in this room is lit. I had thought I would need some special sensor to do that, but now maybe not. smiley
Logged

      Zoandar
  ---v/\/\/\v---

Pages: [1]   Go Up
Jump to: