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.
The following shows the circuit wiring diagram of Photodiode with Arduino Nano and 1MOhm resistor.
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 valueA4
, 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 atphotodiodePin
is read using theanalogRead()
function and stored inanaValue
.
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.
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
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.
what is the reference of the photodiode and the resistor
what is the reference of the photodiode and the resistor used !!
the ground
Why not swap the 1M and the photodiode & don't use the subtraction in the formula?
i think that possible, have to check
Why do you subtract the converted voltage read value from 5?
Why do you subtract the calculated read value from 5?