Pages: [1]   Go Down
Author Topic: How to use an LED as a simple light sensor?  (Read 947 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,

I would like to make a very simple example of using an LED as a light sensor (using the fact that an LED can work as a very simple photoresistor -- its resistance changes when light shines on it).

My only question is how to hook up the LED. Can I just plug one leg into +5V and the other into an analog pin? Or does something need to be connected to ground as well?

Sorry for the n00b question!  :smiley
Logged

Norway@Oslo
Offline Offline
Edison Member
*
Karma: 12
Posts: 2033
loveArduino(true);
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I have done something a bit similar. I used two I/P pins, and pinMode(both,OUTPUT) and then digitalWrite(HIGH) on one and digitalWrite(LOW) on the other.

Wait... Light sensor... NOT touch.
Quote
Can I just plug one leg into +5V and the other into an analog pin? Or does something need to be connected to ground as well?

I think that is correct, you can ofcourse always try. smiley
« Last Edit: January 23, 2009, 07:54:32 am by AlphaBeta » Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 514
Posts: 31550
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
its resistance changes when light shines on it

No, it is a capacitor and the discharge rate depends on the light incident on it. So you have to charge it up first, cathode to + anode to ground. Then change cathode pin to an input and using pluseIn see how long it takes to drop to a zero.
Logged

Connecticut, US
Offline Offline
Edison Member
*
Karma: 2
Posts: 1036
Whatduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Then change cathode pin to an input and using pulseIn see how long it takes to drop to a zero.

Ooooo.  I thought it was proposed to fix a bug in pulseIn(), but your example usage of it won't work with the "fixed" version.

See, pulseIn(pin, HIGH) should wait for a LOW-HIGH transition before starting to time or you may get partial pulse width measurements, but the current version just starts timing it anyway if the pin is already HIGH.  If you are timing the discharge of a fast capacitor-like system, waiting for the LOW-HIGH transition first won't work well.  You might need to roll your own custom dischargeIn(pin) function to do it, if they fix pulseIn().
Logged

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

Hurmmm, I think I may just go find a real photoresistor. Measuring the discharge rate and stuff seems a little complicated for me while I'm just learning about this...

If I had a regular photoresistor, would I just stick one leg in +5V and the other in an analog pin? Does something need to be connected to ground as well?

Thanks!
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 354
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

sample circuit:
http://www.acroname.com/howto/photoresistor/photoresistor.html
Logged

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

Ahhh, the concept of a "voltage divider circuit" helps a lot. Now I know why there is always a resistor connected between the input pin and ground in these examples.

Thanks!  smiley-grin
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 514
Posts: 31550
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

There is a playground page on this:-

http://www.arduino.cc/playground/Learning/LEDSensor
Logged

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

is the dimming effect hard to see? Will a 100ohm resistor make much difference compared to a 150 ohm?
I've been changing things around and changing high to low etc but I fail to see a light-dependant effect...
Does anyone have a clue what I could be doing wrong?
(feels stupid failing something so simple...)

Is there a way I can increase the effect so that I can see it?
« Last Edit: February 02, 2009, 05:10:19 pm by Nick_de » Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 514
Posts: 31550
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Will a 100ohm resistor make much difference compared to a 150 ohm
No difference at all.

I found that adding:-
Code:
   _SFR_IO8(0x35) |= 0x10;   // global disable pull up resistors
in the setup() helps a lot.
Logged

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

where would you put it?
what does it mean?
(thx btw  smiley)
Logged

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

oops sorry in setup, right... :-X

still don't see a difference...
« Last Edit: February 02, 2009, 05:18:57 pm by Nick_de » Logged

Pages: [1]   Go Up
Jump to: