Pages: [1]   Go Down
Author Topic: UNO LED light sensor  (Read 3328 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 49
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

Quote
/* 
##########
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);

  


I really appreciate any solution!

Andrew
Logged

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

Quote
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.
Logged

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

Hello Paul,

look at this: http://www.arduino.cc/playground/Learning/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
Logged

Central Europe
Offline Offline
Edison Member
*
Karma: 7
Posts: 1220
Use the Source, Luke.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: October 12, 2010, 05:13:58 am by Korman » Logged

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

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
Logged

Central Europe
Offline Offline
Edison Member
*
Karma: 7
Posts: 1220
Use the Source, Luke.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: October 12, 2010, 06:21:21 am by Korman » Logged

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

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.
Logged

France
Offline Offline
Faraday Member
**
Karma: 39
Posts: 3560
There is an Arduino for that
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
   resArray[i] = analogRead(A0);  
Did you put all your code.
For me A0 is not declared and it returns an error at compile time.
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 627
Posts: 34217
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Quote
For me A0 is not declared and it returns an error at compile time.
Under version 20 and beyond A0 is a predefined constant.
« Last Edit: October 12, 2010, 08:16:23 am by Grumpy_Mike » Logged

Pages: [1]   Go Up
Jump to: