Introduction: Light Sensing LEDs

I was recently reserching on LEDs and I stumbled upon this page as I read it I found that LEDs are not just used to emit light but the also have the ability to sense light.At first using LED as light sensor sounds complicated but it quiet quickly becomes clear. This is a fun project in which we will be experimenting with LEDs requires minimal parts.

This instructable will explain you how to use a LED as sensor,creating it on a breadboard,making a shield for arduino, how to get a reading from our LED sensor and how to change the sensitivity of our sensor.

This is my first instructable, any suggestions,corrections or comments are welcome.

This instructable is a entry in the arduino contest so if you like it please vote.

A short video of the sensor in sensitive to dark mode:

 

A short video of it in the light sensitive mode:


Step 1: Why Arduino?

Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. It's intended for artists, designers, hobbyists, and anyone interested in creating interactive objects or environments.There are many other microcontrollers and microcontroller platforms available for physical computing. Parallax Basic Stamp, Netmedia's BX-24, Phidgets, MIT's Handyboard, and many others offer similar functionality. All of these tools take the messy details of microcontroller programming and wrap it up in an easy-to-use package. Arduino also simplifies the process of working with microcontrollers, but it offers some advantage for teachers, students, and interested amateurs over other systems:

~ Inexpensive - Arduino boards are relatively inexpensive compared to other microcontroller platforms. The least expensive version of the Arduino module can be assembled by hand, and even the pre-assembled Arduino modules cost less than $50

~ Cross-platform - The Arduino software runs on Windows, Macintosh OSX, and Linux operating systems. Most microcontroller systems are limited to Windows.
Simple, clear programming environment - The Arduino programming environment is easy-to-use for beginners, yet flexible enough for advanced users to take advantage of as well. For teachers, it's conveniently based on the Processing programming environment, so students learning to program in that environment will be familiar with the look and feel of Arduino

~ Open source and extensible software- The Arduino software and is published as open source tools, available for extension by experienced programmers. The language can be expanded through C++ libraries, and people wanting to understand the technical details can make the leap from Arduino to the AVR C programming language on which it's based. SImilarly, you can add AVR-C code directly into your Arduino programs if you want to.

~ Open source and extensible hardware - The Arduino is based on Atmel's ATMEGA8 and ATMEGA168 microcontrollers. The plans for the modules are published under a Creative Commons license, so experienced circuit designers can make their own version of the module, extending it and improving it. Even relatively inexperienced users can build the breadboard version of the module in order to understand how it works and save money.

(Taken From Official Website Of Arduino)

Step 2: Parts & Tools

Parts:
~ Random Assortment Of LEDs - Sparkfun.com
~ Current limiting Resistors For LEDs - Sparkfun.com
~ Multimeter - Sparkfun.com
~ Breadboard - Sparkfun.com
~ Flashlight  
~ Arduino Uno - Sparkfun.com

Tools:
~The arduino programming Environment - Arduino.cc 
~USB Cable A-B - Sparkfun.com
~Soldering Iron - Sparkfun.com
~Solder Wire - Sparkfun.com

The price is about 12.20 $ assuming you are having a multimeter,arduino,breadboard and excluding all the tools.

Step 3: How Can a LED Sense Light?

An LED can be used for light detection as well as emission.LED is a simple diode which has been adopted to emit light.Therefore if it is inserted into the circuit the same way as the photodiode it will serve the same function of sensing light

The LEDs will be sensitive to the light which has the wavelength equal to it or lesser than it.

When light falls on the LED a small voltage is produced this voltage produced can be fed to a microcontroller which can read it and follow the further instructions.

Step 4: Lets Experiment!!

Get some different coloured LEDs an start experimenting.Connect the longer lead of the led to the red wire of the multimeter and the shorter lead to the black wire.

Here are my results:

BRIGHT LIGHT                                                     AMBIENT     
   
Red LED - 1.3v                                                   Red LED - 0.007V
Green LED - 1.4v                                               Green LED - 0.001v
Blue LED - 0.2v                                                  Blue LED - 0v
IR LED - 0.1v                                                      IR LED - 0.01v
Yellow LED - 1.2v                                               Yellow LED - 0.001v
White LED - 0.003v                                            Whit LED - 0v 

All my LEDs are super bright.
Your results may vary from mine due to difference in LEDs and multimeter.
The pictures show the readings I got from a super bright green LED in different conditions.

Step 5: Read the Values With a Microcontroller

A microcontroller reads the input values in a different way.In between, analogRead() returns a number between 0 and 1023 that is proportional to the amount of voltage being applied to the pin.So to read the LED input with a microcontroller I have included a sketch for the arduino microcontroller.The code first reads the analog pin 0 and then prints the value on the serial monitor. I saw that when the LED was in dark the value was below 215 and when it was in light the value went above 215 so I took 215 as my threshold value.You might be thinking how did I take the screenshot check this out
The full size screenshot can be found here and here and here


Step 6: Building the Circuit

 We have completed all our experimenting now lets bring the LEDs to life lets make the circuit. The circuit is pretty straight forward connect  the -ve pin of the sensor LED to gnd and +ve pin to analog pin0.Connect the -ve terminal of the outpue LED to gnd and +ve pin to digital pin13 or you can use the surface mount LED on the arduino to do all the outputting. 

Step 7: The Code

Now that we have made circuit lets upload some code. The code is pretty simple 215 is the threshold value if the LED sensor reades more then 215 then it is in light and the output LED is lit  and if the reading is below 215 the LED is in dark and the output LED turns off if you are using the file LED_sensor_sensitive_to_light and visa - verse if you are using the othor.I have included a downloadable file.

The code for LED_sensor_sensitive_to_light

int sensorLED = 0 ; // LED as sensor connected to analog pin 0
int LED = 13 ;// LED connected to digital pin 13
int LED2 = 12;// LED connected to digital pin 12
int LEDval = 0 ;//Variable to store the the LED sensor value
int light = 215 ;//Threshold level

void setup() {
  pinMode(13,OUTPUT);
  pinMode(12,OUTPUT);
}

void loop() {
  LEDval = analogRead(sensorLED);
 
  if (LEDval <= light) {              // check if light
      digitalWrite(LED2, HIGH);     // if light, turn off led
    } else {                     
      digitalWrite(LED2, LOW);    // if dark, turn on led
    }
   
if (LEDval < light) {              // check if light
      digitalWrite(LED, HIGH);     // if light, turn off led
    } else {                     
      digitalWrite(LED, LOW);    // if dark, turn on led
    }  
}


The code for LED _sensor_ sensitive_ to_ light:

int sensorLED = 0 ; // LED as sensor connected to analog pin 0
int LED = 13 ;// LED connected to digital pin 13
int LED2 = 12;// LED connected to digital pin 12
int LEDval = 0 ;//Variable to store the the LED sensor value
int light = 215 ;//Threshold level

void setup() {
  pinMode(13,OUTPUT);
  pinMode(12,OUTPUT);
}

void loop() {
  LEDval = analogRead(sensorLED);
 
  if (LEDval <= light) {              // check if light
      digitalWrite(LED2, HIGH);     // if light, turn off led
    } else {                     
      digitalWrite(LED2, LOW);    // if dark, turn on led
    }
   
if (LEDval < light) {              // check if light
      digitalWrite(LED, HIGH);     // if light, turn off led
    } else {                     
      digitalWrite(LED, LOW);    // if dark, turn on led
    }  
}






Step 8: Testing & Changing Sensitivity

Take the LED sensor in a well lit room or a light source and the LED connected on digital pin13 should light up and if you take your sensor in dark the LED connected to digital pin13 should switch off when you are using the sketch "LEDsensorsensitivetolight"and visa - versa if you are using the other sketch.To change the sensitivity of your sensor change the < in the if statement to > to light the LED at pin13 on when light is falling and change it to < to light the LED on pin13 when it is dark
The ful size screenshot can be found here
The 1st two pictures show the 1st mode of operation where the sensor is sensitive to light and the last two pictures show 2nd mode of operation where the sensor is sensitive to darkness.

Step 9: All Done!

Hope this project inspires further experimentation. The Arduino board is incredibly versatile,cheap, and accessible to all hobbyists . This is just one of many simple projects which can be constructed using the arduino. Keep pondering!.Dont forget to follow mores comming up. .For any queries contact me heres my E-mail ID r1398ohit@gmail.com

Comments

author
badethbermundo made it! (author)2015-01-27

is there a codes available for this ?

author
kb0iaa made it! (author)2013-04-22

Would have loved to see your videos but they no longer exist. Your pictures were great though and illustrate your instructable very well. This was a great read and I learned something because I didn't know that LEDs could be used like this. Thanks for the great info!

author
Twisted~Mind made it! (author)2012-04-25

In the supplies section, it says we need resistors - but where do we put the resistors on the Arduino?

(I'm new at this, and I thought your Instructable was really cool and decided to give it a try.)

author
Bot1398 made it! (author)Bot13982012-04-25

You can connect the resistor to the outputting LED for providing more protection to it but there is already a resistor on pin13 of the arduino so I didnt use it.

author
Twisted~Mind made it! (author)Twisted~Mind2012-04-25

Oh! I see. Thank you for the help! This is a really neat idea, thank you for sharing :).

author
blinkyblinky made it! (author)2012-03-29
I did some code editing so that I had both a light and dark detector without having the need to reprogram it. Here is the result:

author
Bot1398 made it! (author)Bot13982012-03-29
I also made the same thing earlier here is the result btw you deserve a patch for your innovation.
author
e=mc^2 made it! (author)2012-03-13

Great work!

author
oallaa made it! (author)2012-03-07

Great project never thought that a LED can be used as a sensor!!XD

author
toddie123 made it! (author)2012-02-20

Wonderful discovery! Just tried it out and thats what I call MARVELOUS!

author
Bot1398 made it! (author)Bot13982012-02-21

Post some pictures and get a patch!

author
jensenr30 made it! (author)2012-02-20

This is brilliant. I mean REALLY brilliant. I'm following XD

author
anmol11 made it! (author)2012-02-15

what a project rohit!!....badiya ekdum...abe meko patch bejh in my this account!..please

author
scromp made it! (author)2012-02-12

This is a cool discovery.. but why not just use a photoresistor?

author
Bot1398 made it! (author)Bot13982012-02-13

Yes can suerly use a photoresistor .

author
Samimy made it! (author)2012-02-11

nice man, a great post !
that was actually a big discovery, i never heard of it before.

author
Bot1398 made it! (author)Bot13982012-02-11

I too never heard about it before seeing this.It says they can be used to sense light.

Ã

author
MikB made it! (author)2012-02-11

I recall seeing a design for a clock, LED based, where the flashing colon in the time (12:00) was implemented using two discrete LEDs. When driven (high) by an I/O port, they lit. The other half of the time, they weren't just off, they were switched as analogue INPUTS to read the "light level" in the room.

This then allowed the microcontroller driving the LEDs for the whole display to adjust the brightness of the display according to the light level in the room, as the current fed to the display was under the microcontroller's supervision.

Now that's a cool trick! Two uses for the same LED. I'm sure similar things can be done on Arduiono/ATMEGA/PIC, as long as you can reprogram an I/O pin from a driven OUTPUT to an analogue INPUT.

About This Instructable

40,196views

108favorites

License:

Bio: Preapering for my medical entrance exams
More by Bot1398:555 Crriter RepellentSolar Powered Clock HackDIY Astronomy Flashlight
Add instructable to: