In this tutorial, you’ll learn how to do Arduino Photodiode Interfacing and use the BPW34 photodiode with Arduino as a light intensity sensor. We’ll also create a couple of Arduino Photodiode Light Sensor Example Projects which can be a very good starting point for your Arduino + Photodiode project idea. Without further ado, let’s get right into it!
Table of Contents
- Arduino With Photodiode
- Arduino Photodiode Circuit Diagram
- Arduino Photodiode Code Example
- Concluding Remarks
Arduino With Photodiode
A Photodiode is a semiconductor device that’s sensitive to light as it turns light energy into an electric voltage that can push some current into a load. Small photodiodes are typically used for light sensing (intensity measurement) applications, while large photodiode cells are used to generate electric power from natural renewable solar power.
Below is the BPW34 which is a photodiode device that we’ll be using in this tutorial with Arduino to create a light-intensity sensor application.
The voltage developed across the photodiode terminals changes with the light intensity that hits the surface of the photodiode device. It can be easily measured with a DMM (digital multimeter) to also identify the diode pins’ polarity.
Photodiode Applications
- Solar Tracking
- Light Intensity Meters
- Position Sensing
- Photo-interrupters
- etc
Buy a BPW34 Photodiode: you can find it here on Amazon.com
Arduino Photodiode Circuit Diagram
We need to design a simple electronic circuit to interface the photodiode device with the Arduino microcontroller to read the output voltage developed across the photodiode when light hits it.
The first and easiest way to achieve this goal is to use a simple resistor as a load across the photodiode terminals and read the voltage developed across the photodiode with any Arduino’s ADC analog input channel pins. The output voltage swing from darkness to full sunlight will be relatively small, therefore the system’s sensitivity is considered a little bit low.
The second circuit design that we’ll go through hereafter adds an OpAmp for signal amplification which makes our system more sensitive to light changes as it amplifies the output voltage developed across the photodiode terminals.
Arduino Photodiode Light Sensor Circuit #1
Here is the Arduino with Photodiode circuit diagram. Note that we’re using a 4.7kΩ resistor here in this circuit.
Arduino Photodiode Light Sensor OpAmp Circuit #2
This is the second circuit design for Arduino with Photodiode + OpAmp.
Note that we’re using the UA741 opAmp, a 10kΩ resistor, and a 100nF capacitor here in this circuit.
This article will give more in-depth information about LDR light sensors interfacing with Arduino and how to use the LDR for light intensity measurement with Arduino.
Arduino Photodiode Code Example
In this example project, we’ll use an Arduino + Photodiode (BPW34) as a light intensity sensor to measure the ambient light intensity. The analog voltage reading will be sent back to the PC over the serial port and we’ll display it on the serial monitor and the serial plotter.
We’ll test both circuits shown earlier in this project. Using the photodiode only and with the opAmp for output signal amplification.
Arduino Photodiode Circuit Wiring
The wiring diagram for this example project is shown in the previous section, scroll up and check it out. Below is an image of how the whole setup looks like at the end, ready for the test.
Arduino Photodiode Light Sensor Circuit #1
Arduino Photodiode Light Sensor OpAmp Circuit #2
Code Example
Here is the full code listing for this example.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
/* * LAB Name: Arduino Photodiode Example * Author: Khaled Magdy * For More Info Visit: www.DeepBlueMbedded.com */ void setup() { Serial.begin(9600); } void loop() { float Vout = (analogRead(A0)*5)/1023.0; Serial.println(Vout); delay(100); } |
Code Explanation
setup()
in the setup() function, we’ll initialize the serial port to operate @ 9600bps.
1 |
Serial.begin(9600); |
loop()
in the loop() function, we’ll read the analog voltage on the A0 pin, convert the digital value to an analog voltage, and send it over the serial port to the PC where we’ll be monitoring it.
1 2 3 4 5 |
void loop() { float Vout = (analogRead(A0)*5)/1023.0; Serial.println(Vout); delay(100); } |
Arduino + Photodiode TinkerCAD Simulation
Here is the simulation result for the first circuit design on the TinkerCAD simulator. You can run it as is, or make a copy, add your own code, and start simulating to see how it’s going to behave.
You can check this simulation project on TinkerCAD using this link.
Arduino Photodiode OpAmp Circuit Example Simulation
The simulation results are only for logic verification and you should not expect to get the exact same output voltage levels on the real hardware. The results may vary depending on: the resistor value you’re using, the photodiode silicon device itself, or the light source used while testing.
In the hardware testing that I’ve done, the output voltage for the first photodiode circuit swings from 0v (darkness) up to 0.4v (intense light). And for the photodiode + opAmp circuit, the output swings from 2v (darkness) up to 4.2v (intense light).
Required Parts List
Here is the full components list for all the parts that you’d need to perform the practical LABs mentioned here in this article and for the whole Arduino Programming series of tutorials found here on DeepBlueMbedded. Please, note that those are affiliate links and we’ll receive a small commission on your purchase at no additional cost to you, and it’d definitely support our work.
Download Attachments
You can download all attachment files for this Article/Tutorial (project files, schematics, code, etc..) using the link below. Please consider supporting my work through the various support options listed in the link down below. Every small donation helps to keep this website up and running and ultimately supports our community.
Concluding Remarks
To conclude this tutorial, we can say that you can easily interface a photodiode with Arduino and use it as a light sensor for measuring the ambient light intensity. Try the provided example circuits on your hardware setup or at least run them in the TinkerCAD simulation environment to maximize the information gained from this tutorial.
If you’re just getting started with Arduino, you need to check out the Arduino Getting Started [Ultimate Guide] here.
And follow this Arduino Series of Tutorials to learn more about Arduino Programming.
In this tutorial, you’ll learn how to interface Arduino with Phototransistor devices and use it as a light-intensity sensor or darkness-light detector.
Very helpful and informative. Thanks!