UNO LED light sensor

Hello,

I set up a green or a red LED for sensing light, but it dos not work although the analog pin does sense +5V or +3,3V.

Can someone help me, please?

This is my code:

/*
##########
LED Sensor
##########
*/
byte anodePin = 7;
byte cathodePin = 14; // refer to analog in as A0 or 0 or 14 digitally
int resArray[200];

void setup() {
_SFR_IO8(0x35) |= 0x10; // global disable pull up resistors ???? do NOT seem to work
_SFR_IO8(0x35) |= 4;
_SFR_IO8(0x35) |= (1<<4);

pinMode(anodePin,OUTPUT); // declare the anode pin as output
pinMode(cathodePin,OUTPUT); // Enable cathode pin as digital output
Serial.begin(38400); // start serial with baud rate 38400
}

void loop () {

digitalWrite(anodePin,HIGH); // Turn ON LED: discharge LED
digitalWrite(cathodePin,LOW);

digitalWrite(cathodePin,HIGH); // Turn off LED
digitalWrite(anodePin,LOW); // Set anode pin low: charge LED in reverse direction
delay(2);

pinMode(14,INPUT); // disables pull-up resistor
for(int i=0; i<200; i++){
resArray* = analogRead(A0); *

  • }*
  • pinMode(cathodePin,OUTPUT); *
  • for(int i=0; i<200; i++){*
    _ Serial.println(resArray*);_
    _
    }_
    _ Serial.println(" ");
    Serial.println(" ");_

    _
    delay(15000);_
    _
    } *_

[/quote]
I really appreciate any solution!
Andrew

I set up a green or a red LED for sensing light

So, which Light EMITTING Diode did you set up to READ light levels?

An LED is an output device. Turn it on, and it emits light. It is not an input device.

Hello Paul,

look at this: Arduino Playground - LEDSensor

I tried this, too, but no luck either. Then I changed the code for sensing through the analog input A0, and it senses +5V and +3,3V all right. But when I discharge the LED through it, I seem to just get floating readings.
There are a number of videos on the web that show an LED fuction as a light sensor, and I found several sketches that are claimed to work:

http://blog.makezine.com/archive/2009/08/ask_make_led_as_light_sensor.html
or this!:
http://cs.nyu.edu/~jhan/ledtouch/index.html

But with neither the red nor the green LED do I get it to work.
I have nor idea why this does not work on the UNO board in my hands.

Can you help?

Andrew

Andrew,

you link a page with very complete instructions and a sample program. You say, the thing doesn't seem to work as described. You tinker around with the code, the thing still doesn't work.

Now you expect us give you some magic code change so that the thing works suddenly, while it's not even clear if that thing is even possible to work with the leds you use - or with any leds.

Doesn't that sound a little unreasonable to you too?

Perhaps you better check first the electric side if the described effect can be observed. If it's there, you might be able to measure it. If it isn't there, well, you'll never going to measure it no matter how often you post questions about it.

Instead of wasting all that effort, get a $0.49 photodiode. That's better, faster, easier, cheaper and works.

Korman

Well, as I cannot reproduce it, I think there's some fault with my sketch, as there's really no fault in the wiring.

There's a paper by Paul Dietz, William Yerazunis, Darren Leigh, MITSUBISHI ELECTRIC RESEARCH LABORATORIES (2003) :
"A novel microprocessor interface circuit is described which can alternately emit and detect light using only an LED, two digital I/O pins and a single current limiting resistor. This technique is first applied to create a smart illumination system that uses a single LED as both light source and sensor."

Anyway, thanks for your answer.

Andrew

Well, does the original sketch work when you reproduce the setup? If yes, you have a working base, if no you're wasting your time blaming your software.

Korman

Then, perhaps you should be e-mailing the authors your questions. There are other solutions for reading light level, using commonly available components, that are KNOWN to work under more than laboratory conditions.

    resArray[i] = analogRead(A0);

Did you put all your code.
For me A0 is not declared and it returns an error at compile time.

The technique of using an LED as a light sensor does work, I have done it my self:-

http://www.thebox.myzen.co.uk/Workshop/LED_Sensing.html
However it is dependent on the LED and also dependent on you actually shining some light on the LED to detect.
I should be considered a novelty and not a serious reliable sensor. There is nothing on the UNO that will stop this technique from working so if you are having trouble then it is either some error you have made or the type of LED you are using.

For me A0 is not declared and it returns an error at compile time.

Under version 20 and beyond A0 is a predefined constant.