Using an LED as a Light Sensor

Posted: March 27, 2012 in Arduino, Uncategorized
Tags: , , ,

It turns out that many electronic components can run backwards and forwards. For example, it’s possible to use headphones as a microphone. Here’s a simple Arduino-based circuit that shows how to use an LED as a light sensor. The diagram below shows how to hook everything up.

LED Light Sensor Diagram

The basic idea is then to use analogRead() to detect the voltage across the LED. If the value is low, it means the LED is not detecting much light, while if the value is higher then there is more light present.

Three different versions of the code that goes along with this circuit is available at The SerialOutput folder has a sketch that just dumps the values it reads to the serial port. You can use this to find a good threshold value, depending on the exact light conditions you are seeing. The Threshold sketch simply turns the LED on pin 13 off when there is light, and on otherwise. You could use this as a simple night light. Finally, the Fading sketch adjusts the intensity of the LED based on how much light is detected. It requires the output LED to be connected to a PWM pin, so if you are using an Arduino Uno instead of a Mega, you’ll want to adjust the code and the circuit to use, for example, pin instead of pin 13 for the output.

Here’s a video of the fading example.

  1. Neal says:

    Haha, headphones as microphone reference! Good times..

  2. speedymcrunfast says:

    That’s clever. I knew about using speakers as microphones, but hadn’t though much about LEDs doing something similar with light. I imagine you could slap some electrical tape around your receiving LED and use it as a light sensor limiting switch.

  3. esaliya says:

    So do LEDs actually generate some voltage or change resistance when light is received?

    • Eric Holk says:

      I’m honestly not sure how it works… It seems like the analog pin has some non-zero voltage, and as more light is applied to the LED, the resistance changes, which leads to a change in voltage at the analog pin.

      • esaliya says:

        Interesting! I’ve used a 2N3055 ( transistor with top cutoff exposing the internals. It also acts pretty much like and LDR.

      • Eric Holk says:

        (Saliya, I’m replying to you here because I can’t reply to yours directly)

        Interesting! I’ve heard you can do that too. Have you done a lot of electronics work? If you’re interested in this stuff, should should come to the Arduino Hacking Sessions on Fridays at 6 in LH008.

  4. esaliya says:

    Thanks for inviting, that would be a fun session!. Yes before coming here I used to play around Electronics and PCB etching.

  5. speedymcrunfast says:

    says here the LEDs will only pick up light wavelengths that are equal to or shorter than the light the emit, good to know if you are using whatever is lying around.

  6. ken says:

    how can i make a stealth device for my metal detector please.instead of bleep when i get a target
    using my headphone socket leds light will be connected using a headphone jack.

    • Eric Holk says:

      Is sounds like you’re trying to make it so the metal detector lights up instead of beeping? Does it already have a headphone jack? I’m not sure what typical voltages are for headphone jacks, but you might be able to just solder a 1/8″ connector onto an LED and plug it in.

      • ken says:

        Hi Eric
        I want to thank you for your reply and yes the metal detector does already have a headphone jack.
        someone has already done this project it is called stealth device you can see it on ebay but it comes
        from america but there is some clever people on here that could advise me how to make one.Please
        look on ebay and just type in stealth device plus there is something on you tube.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s