Introduction: Light Sensing LEDs

About: Preapering for my medical entrance exams
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

Arduino Challenge

Participated in the
Arduino Challenge