Photodiode Light Detector with Arduino

photodiode

This Arduino electronics tutorial illustrates how to use Photodiode as a light sensor with Arduino. When light impinges on the photodiode LED, current is produced and thereby voltage is generated which is captured by the ADC(Analog Digital Converter) of the Arduino. The amount of current/voltage generated by the Photodiode depends upon the light intensity falling onto the photodiodes hence measuring the light intensity. Because the photodiode produced voltage is directly related to amount of light intensity, the photodiode is often called light sensor, light detector,optical detectors or photodetectors. The voltage generated due to the photodiode   is then displayed on the serial monitor using Arduino IDE.Here we will use Arduino Nano to detect the voltage produced by the photodiode. Photodiode circuit with Arduino is provided and program code is also provided. Video demonstration is also provided.


There are various types of Photodiodes such as Photodiode LED, PIN photodiode, Schottky Barrier Photodiode and Avalanche Photodiode. They differ mainly in the construction and due to this they have varying sensitivity to light. The function of photodiodes is to convert light signal into either voltage or current based on mode of operation. These all Photodiode are designed to operate in reverse bias condition. That is the cathode is connected to +ve supply and anode is connected to ground.


Video Demo

Watch the following video demonstration of Photodiode used as light detector using Arduino Nano.

  

Arduino Photodiode & Interfacing Circuit Schematic Drawing

The following picture shows interfacing of Arduino Nano with Photodiode LED and 1MOhm resistor on breadboard.

Photodiode Light Detector with Arduino


 The following shows the circuit wiring diagram of Photodiode with Arduino Nano and 1MOhm resistor.

Circuit diagram Photodiode Light Detector with Arduino Nano

Arduino Program for Photodiode detector

The following is photodiode Arduino code.

//Program for Photodiode Light detection with Arduino
//Source: https://www.ee-diary.com


//alias pin name for Photodiode
int photodiodePin = A4;

void setup(){
  Serial.begin(9600); //set Serial output baud rate
  //For output format
  Serial.println("\nVoltage(V):");
  Serial.print("--------------------------------------------------\n");
}

void loop() {
    int anaValue = analogRead(photodiodePin); // potentiometer voltage

    float voltage = 5-(anaValue/1024.0)*5;
        Serial.println(String(voltage,2)+"V");
        delay(2000); //delay 2000ms to prevent any duplicates

}

The above Arduino program code measures the voltage of a photodiode and prints it to the serial monitor.

  • A constant integer photodiodePin is defined with value A4, which is an analog input pin on the Arduino board.

  • In the setup() function, the serial communication is initialized at a baud rate of 9600 and a string "Voltage(V):" is printed to the serial monitor, followed by a line of dashes.

  • In the loop() function, the analog voltage at photodiodePin is read using the analogRead() function and stored in anaValue.

  • The voltage is calculated using the formula: voltage = 5-(anaValue/1024.0)*5 and is printed to the serial monitor as a string with two decimal places and the unit "V".

  • Finally, the program waits for 2 seconds using delay(2000) to prevent any duplicates.

In this tutorial we have shown how to use a LED Photodiode to measure light intensity with Arduino. Other example of application where photodiodes are popular is obstacle detection used in robotics and industrial machinery. In this applications, photodiodes are commonly called Infrared Sensor(IR sensor). An example of object detection using Photodiode module with Arduino was illustrated in IR sensor with Arduino, LCD, Buzzer and LED.

Recommended Tutorials

 If you are interested in circuits that involves light then the following tutorial might be helpful.

- Arduino light sensor circuit using LDR

- LDR laser security system

9 Comments

  1. AK
    AK

    Hi,

    Would this setup work to detect an event lasting 4ms. I want a laser shining on a photodiode, and the beam breaks for around 4ms. Can this be detected through this method?

    Many thanks

    Reply Delete February 11, 2022 at 2:50 AM
  2. ee-diary

    hi, yes this can be done. you need to write code in your program to stop/start the timer for the period. This blog post https://ee-diary.blogspot.com/2021/08/laser-diode-ldr-based-alarm-system.html uses laser with LDR but you can replace the LDR with photodiode. also see https://ee-diary.blogspot.com/2020/09/IR-sensor-Arduino-LCD-Buzzer-LED.html which is similar. The codes in these tutorial might help you. you might want to use interrupt feature on pin where the laser or photodiode is connected to trigger the time delay. Hope this helps.

    Reply Delete February 11, 2022 at 11:49 AM
  3. Anonymous

    what is the reference of the photodiode and the resistor

    Reply Delete February 21, 2023 at 5:23 PM
  4. Anonymous

    what is the reference of the photodiode and the resistor used !!

    Reply Delete February 21, 2023 at 6:01 PM
  5. drf5n

    Why not swap the 1M and the photodiode & don't use the subtraction in the formula?

    Reply Delete May 16, 2023 at 9:59 AM
    1. ee-diary

      i think that possible, have to check

      Reply Delete May 18, 2023 at 11:24 AM
Previous Post Next Post