Bi-directional LED Sensing Try-out


Introduction: Bi-directional LED Sensing Try-out

This experiment was conducted based on the example provided on . The example was built on the PICAXE platform and I've converted it onto the Arduino. However, certain attributes to the LED that was explained by hackhut was not taken into consideration for example, the LED discharge time. I simply wrote the code treating the sensing LEDs as normal sensor and they would output whatever they detect on the other LED. The red and white LEDs were chosen as to provide a reference to see the difference of different LED colour attributes on its sensitivity and transmit ability. 

The result could be used in some sort of half-duplex Morse code application or even as an relay or isolator. As tested, the LED does conduct voltage when it senses light of same or lower wavelength than it was designed for. However, the different brands or structures of LEDs differs its capabilities. I provided the source code for Arduino for reference.

/*Demonstrates using LED as a sensor and emitter.
When LED A1 or A2 senses input, the other will emit
light according to the blinking sequence detected*/

#include "pitches.h"

const int led1 = A0;
const int led2 = A1;
const int breakTime = 3000; //in ms
const int speaker = 8;
int value1, value2;
int threshold1 = 250;
int threshold2 = 250;
int numNotes = 4;
boolean timeout = false;
long time = 0;

int melody[] = {
int noteDurations[] = {
  4, 4, 4, 4};

void setup(){

void loop(){
  value1 = analogRead(A0);
  value2 = analogRead(A1);
  if(value1 >= threshold1){
    Serial.print("Value 1 : ");
    time = millis();
    timeout = false;
  else if(value2 >= threshold2){
    Serial.print("Value 2 : ");
    time = millis();
    timeout = false;

void out(int a, int b, int threshold){
  while(timeout != true){
    int value = analogRead(a);
    if(value >= threshold){
      time = millis();
    if(millis() - time >= breakTime){
      timeout = true;

void playTone(){
  for (int thisNote = 0; thisNote < numNotes; thisNote++) {
    int noteDuration = 1000/noteDurations[thisNote];
    tone(8, melody[thisNote],noteDuration);
    int pauseBetweenNotes = noteDuration * 1.30;
As you can see from the video, the red LED cannot respond (transmit)  quick enough to the received signal.
This suggest that the red LED has capacitive properties but may differ due to the holding and discharge time of different LED. When the white LED transmits, its very clear that with every quick interval signals, the white light was able to transmit accordingly and with minimum delay. 

In terms of sensitivity, the red LED would win hands down. White light consists of broad spectrum rays and the wavelength is undetectable by the red LED unless it is put very VERY closely. With the red LED, the distance between the transmitter and receiver for successful sensing could be larger. However, we must put into account that the noise received from the atmosphere was no doubt a big disadvantage as the experiment was done under fluorescent lighting. This problem was partially solved by calibrating possible received values before writing the threshold values of both sensors. Its very simple. The piezo speaker functions to show end of transmission and the Arduino will start sensing both inputs again.

The testing code used is shown below:

void setup(){

void loop(){
  int value1 = analogRead(A0);
  int value2 = analogRead(A1);
  Serial.print("Value 1 = ");
  Serial.print("\tValue 2 = ");

Also include the pitches.h file obtained from the Arduino page .
The circuit drawings were done on Fritzing . It is open-source like the Arduino.



    • Clocks Contest

      Clocks Contest
    • Creative Misuse Contest

      Creative Misuse Contest
    • Oil Contest

      Oil Contest

    8 Discussions

    Very cool. Now, even though the red LED does not respond fast enough and seems to be on a bit longer than it's supposed to be does the voltage measured across the leads of the LED drop while light is still being produced?

    6 replies

    Is it possible to check the status (do light detection) quickly, then turn on the LED for 99/100 of a second if the light level in the area is low or if the room is dark?

    Can this be done with one LED that is both a dark sensor and a nightlight?

    1/100 of a sec, check light level
    99/100 of a sec, burn brightly if the area is dark

    Are you asking if it is possible to detect and display using only one LED?
    If you are, then my answer would be yes theoretically, but i have not tested this idea~

    However, it also depends on the type of LED you're using (size, color) and etc.

    Yes, using only one LED can it be used to detect, and also to give light. I ask because my cheapo voltmeter has an LED to light the LCD screen and when it is in bright sunlight a voltage shows onscreen until I shade the screen where the LED is.

    Perhaps there could even be a way to constantly read the (back voltage?) coming from the light hitting the LED. It might involve closely monitoring the actual voltage (current?) sent to the LED and the amount that passes through it (resistance?) could indicate the ambient light level sensed by the LED.

    Hope my terminology is close enough for some experts to diagnose my syntax. :)

    Perhaps if the LED connection was isolated from the main circuit, readings from the LED would not affect the actual voltage readings~ This could be done using relays or other isolation device. :)
    Relays used could depend on the activation voltage, ranging from lowest 5 volt.

    Not being an Electronics Engineer I can only throw out a term that I do not fully understand. That term is "back EMF" when reading (workload?) on a motor. Does this sound familiar?

    BTW, I greatly appreciate this conversation and I thank you for your time!  :)

    I'm happy to help :)
    Well, about your theory of the back EMF; i am sure that it exists for any circuit with a load (power source). However, i am not sure if it alone contributes to the varied voltage measurements. Personally, i would say yes if you were using two different types of batteries (such as energizer vs tesco batteries) for different measurements. But i don't think that was the case, was it? I believe the LED as an input, in turns, generates minor current when subjected to sunlight or anything bright.

    When i conducted my LED project with normal office lighting, the output readings from the LED varied below the threshold level i set, which was at 4.88volts, when a light source shown directly on it, it showed readings of over (250/256)x5 = 4.88 volts. This shows that the problem was with the LED and you were right with the back EMF theory here. When the LED becomes a current source, it contributes and affects the readings on the voltmeter especially when the voltmeter is not a properly designed one. To learn to design a voltmeter, you can go search for the topic 'Instrumentation' in engineering. I used the book by H.S. Kalsi :) I hope this helps.

    Thanks for the kind comment :) My measurements actually showed dropping voltage. Thats what made me thought of its capacitive qualities.