Ask MAKE: LED as light sensor

Technology
Ask MAKE: LED as light sensor

AskMake_CoBrand_Jameco_f1.gif

Ask MAKE is a weekly column where we answer reader questions, like yours. Write them in to becky@makezine.com or drop us a line on Twitter. We can’t wait to tackle your conundrums!

ledtouch_photo.jpg

This week’s question comes from Kevin:

I heard that you can use an LED as a light sensor. How?

LEDs are diodes tuned specifically to emit light and packaged in translucent enclosures. A photodiode is essentially the same thing, but sensitive to a wider range of light wavelengths. From the very informative Wikipedia page on the subject:

For example, a green LED will be sensitive to blue light and to some green light, but not to yellow or red light. Additionally, the LED can be multiplexed in such a circuit, such that it can be used for both light emission and sensing at different times. In Dietz et al., a scheme for implementing this multiplexing is presented:

  • A LED is connected to two bidirectional CMOS I/O pins on a microcontroller (or a microprocessor with an I/O bus).
  • To emit light, both of the I/O pins are set to output mode, and the LED is driven with current in the forward direction, resulting in current through the LED and emission of light.
  • To detect ambient light:
    • The I/O pins are set to output mode, and the diode is driven in the reverse-bias direction, such that the diode inhibits the current and the LED’s inherent capacitor is charged.
    • The I/O pins are set to high-impedance CMOS input mode.
    • The diode leaks current at a rate proportional to the incident light, as incident photons cause electrons to leap across the band gap.
    • The time it takes for this leakage current to discharge the LED’s inherent capacitor is measured and is inversely proportional to the incident light.

Don’t be intimidated by the electronics terms above, it’s actually pretty simple. Arduino has an example on their site showing a LED connected from one digital pin to another through a 100 ohm resistor. Part of the code tells the LED to light up, and part of it reverses the current and tells the former power pin to read the current leakage of the diode, which will change relative to the amount of ambient light in the room.

Here’s a short video showing a grid of red LEDs being used also as photodiodes (also photo above). Provolot tried it out, too, with success (and source code). Forest M. Mims III uses this technique to sense specific wavelengths of light for sun research in Hawaii.

Have you worked with LEDs as photodiodes? Share your project, video, or tips with us in the comments!

This week’s Ask MAKE has been sponsored by Jameco Electronics.

20 thoughts on “Ask MAKE: LED as light sensor

  1. Kyle McDonald says:

    I found a great app note on this a couple days ago: http://www.edn.com/article/CA6387024.html

  2. Timothy D. Swieter says:

    Just over two years ago I did experimenting with this based on previous posts by the Make Blog. You can see the discussion and Propeller code in the forum here: http://forums.parallax.com/forums/default.aspx?f=21&m=128674

  3. Chris W says:

    I just got a wireless video security camera (with motion sensor) which will trigger a VCR or DVR to start/stop recording via an IR LED on the receiver. To set it up you have to hold your VCR’s remote control within 2 inches of the LED so it can learn your VCR’s RECORD and STOP commands. I thought that 2 inch requirement was odd, but now I suspect they are using the IR LED as a sensor when in learning mode.

  4. Silverman says:

    I did a project based on this principle. There’s a short video on YouTube:
    http://tinyurl.com/lgaqhj
    and a PDF of the report
    http://silverman.ath.cx/LEDSensorBar.pdf

    The bummer is that, unlike for the ordinary use of LEDs, the clever ways of multiplexing bidirectional LEDs are limited. According to my attempts, you really can only connect an LED directly to a pair of microcontroller pins, and there are even limitations on which pins you can use (see Seciton 3).

  5. Dale Wheat says:

    I found an even easier way to do this. LEDs also have a “photovoltaic” characteristic, meaning they emit voltage when you shine light on them. Just connect an LED’s anode (long lead) to an analog input on an Arduino, for example, and the cathode to ground. No resistor is required as we’re not lighting up the LED, although we could. Here is the code. I modified the “AnalogInput” example by DojoDave:

    /*
    * AnalogInput
    * by DojoDave
    *
    * Turns on and off a light emitting diode(LED) connected to digital
    * pin 13. The amount of time the LED will be on and off depends on
    * the value obtained by analogRead(). In the easiest case we connect
    * a potentiometer to analog pin 2.
    *
    * http://www.arduino.cc/en/Tutorial/AnalogInput
    */

    // changed to analog input 0
    // added serial output

    int potPin = 0; // select the input pin for the potentiometer
    int ledPin = 13; // select the pin for the LED
    int val = 0; // variable to store the value coming from the sensor

    void setup() {
    Serial.begin(115200); // configure serial port baud rate
    }

    void loop() {
    val = analogRead(potPin); // read the value from the sensor
    Serial.println(val); // display value on serial port
    pinMode(14, OUTPUT);
    digitalWrite(14, 0);
    pinMode(14, INPUT);
    digitalWrite(ledPin, HIGH); // turn the ledPin on
    delay(val); // stop the program for some time
    digitalWrite(ledPin, LOW); // turn the ledPin off
    delay(val); // stop the program for some time
    }

    The Arduino’s onboard LED blinks faster when it gets darker, and prints out the brightness value on the serial port.

    I was inspired by the SpriteMods “reduction” of the Evil Mad Scientist’s original “flickering LED” circuit:

    http://spritesmods.com/?art=minimalism

  6. Silverman says:

    I posted another comment but it was held for moderation, probably because it contains links. I did a project using this phenomenon. Search YouTube for (LED sensor bar 2) and you’ll find it. Once the other comment comes out of moderation, you’ll find a link to a PDF report about the device.

    Off-topic: How come some comments with links (like Dale Wheat’s informative one) are posted right away and some are held in moderation indefinitely?

    1. Ask MAKE: LED as light sensor Becky Stern says:

      @Silverman All moderated comments for this post have been approved now. Dale Wheat logs in and posts relevant comments with nonspam links a lot, so our comment system “trusts” him and doesn’t moderate his comments. We try to get to moderated comments in a timely manner, but even we have to sleep sometime. =] The more you comment, the sooner you too will be a “trusted” commenter whose links aren’t moderated.

      1. Silverman says:

        Thanks for your explanation, Becky. Does that mean I should start logging in to comment? Or does the trust-building algorithm work on anonymous comments as well? I have a login, it’s just quicker and lazier to click “comment anonymously”…

        1. Ask MAKE: LED as light sensor Becky Stern says:

          It only works if you log in. Anonymous comments with links will always be moderated.

  7. Randall Bohn says:

    I tried this on a solderless breadboard and failed. This is one application where building on a PC board or prototype board is critical. I built a mini-cylon board that would trigger on a light level change, run for a few cycles, then go back to sleep.

Comments are closed.

Discuss this article with the rest of the community on our Discord server!
Tagged

Becky Stern is a Content Creator at Autodesk/Instructables, and part time faculty at New York’s School of Visual Arts Products of Design grad program. Making and sharing are her two biggest passions, and she's created hundreds of free online DIY tutorials and videos, mostly about technology and its intersection with crafts. Find her @bekathwia on YouTube/Twitter/Instagram.

View more articles by Becky Stern

ADVERTISEMENT

Maker Faire Bay Area 2023 - Mare Island, CA

Escape to an island of imagination + innovation as Maker Faire Bay Area returns for its 15th iteration!

Buy Tickets today! SAVE 15% and lock-in your preferred date(s).

FEEDBACK