Lesson Objectives
- Understand how a photodiode converts light into current and voltage.
- Use Arduino to measure ambient light, darkness, and LED flicker.
- Deploy Red Pitaya STEMlab 125-14 to visualize high-speed light fluctuations
Theory & Introduction
Modern sensing systems often need to monitor not only slow changesâlike a day/night cycleâbut also fast fluctuations, such as flicker in lighting. Flicker can arise from AC mains, poorly regulated LED drivers, or purposeful modulation (e.g. IR remote signals). A photodiode is an ideal sensor for this task: under illumination it produces a current proportional to light intensity, which we can convert to a voltage and digitize with a microcontroller.
Photodiode Basics
- Structure:
A photodiode is a pân junction operated in reverse bias (or zero bias) so that incoming photons generate electronâhole pairs, resulting in a photocurrent.
- Linear Response:Iph=RĂP,
Within its operating range, photocurrent IphI_{ph}Iph is approximately proportional to incident light power PPP:
Iph=RĂP, I_{ph} = R \times P,
where RRR (A/W) is the responsivity of the device.
- Voltage Conversion:
To measure this current with an Arduino (which reads voltage), we use a pull-up resistor (here 10 kΩ). The tiny current flowing through the resistor develops a voltage V=IphĂRpullâupV = I_{ph} \times R_{pull-up}V=IphĂRpullâup, which the ADC samples.
Why Flicker Matters
- Health & Comfort:
Flicker at 50â60 Hz (or higher harmonics) can cause headaches, eye strain, or neurological effects.
- Signal Integrity:
In optical communications (IR remote controls, LiFi), flicker is the information carrierâso sensing speed and fidelity matter.
- Performance Diagnosis:
Mechanical or electrical faults in lighting fixtures often reveal themselves as irregular flicker patterns.
Arduino vs. High-Speed Analysis
- Arduino ADC:
- Pros: Simple, built-in, direct.
- Cons: Limited sample rate (~10 kS/s), averaging hides fast events.
- Red Pitaya Oscilloscope:
- Pros: 125 MS/s sample rate, real-time waveform, FFT analysis.
- Cons: Requires external setup.
In this lab you will:
- Quantify ambient and dark conditions with Arduinoâs ADC.
- Drive LEDs at controlled flicker rates and observe the photodiodeâs analog readings.
- Visualize the same flicker in fine detail on the Red Pitayaâcapturing fast edges, envelope shape, and spectral content.
By comparing Arduinoâs coarse readings to Red Pitayaâs high-speed plots, youâll learn both the capabilities and limitations of embedded ADCsâand see why high-speed instruments are indispensable for characterizing transient phenomena like light flicker.
1. Hardware Setup
Components
Component | Quantity | Purpose |
BPW34 Photodiode | 1 | Light-to-current sensor |
10 kΩ resistor | 1 | Pull-up resistor (converts current â voltage) |
LED + 220 Ω resistor | 1 | Flicker source |
Arduino Uno (or R4) | 1 | Analog sampling and LED drive |
Breadboard & Jumper Wires | 1 | Prototyping connections |
Red Pitaya STEMlab 125-14 | 1 | High-speed oscilloscope & spectrum analyzer |
Circuit Diagram
Wiring
- Pull-up network & photodiode:
- +5 V â 10 kΩ â junction
- Photodiode anode â junction â Arduino A0 & Red Pitaya IN1
- Photodiode cathode â GND
- Arduino GND â Red Pitaya GND
+5 V ââ 10 kΩ âââŹâââââââââââââș Arduino A0 & Red Pitaya IN1 â BPW34 Photodiode â GND âââââââââââș Arduino GND & Red Pitaya GND
2. Arduino: Measuring Light Levels
Part A: Ambient vs. Darkness
// Part A: Ambient vs. Dark const int photoPin = A0; void setup() { Serial.begin(115200); } void loop() { int v = analogRead(photoPin); // 0â1023 Serial.println(v); delay(200); // 200 ms between readings }
- Upload the sketch.
- Open Tools â Serial Plotter.
- Ambient: point photodiode at room light â ~600â800.
- Dark: cover photodiode â near 0.
Â
Part B: Single-LED Steady Illumination
Wiring Update
- LEDâ (steady):
- Arduino D9 â 220 Ω â LEDâ anode
- LEDâ cathode â GND
- Photodiode network remains unchanged.
Sketch
// Part B: Steady LED const int photoPin = A0; const int ledPin = 9; void setup() { pinMode(ledPin, OUTPUT); Serial.begin(115200); } void loop() { digitalWrite(ledPin, HIGH); // LEDâ ON Serial.println(analogRead(photoPin)); delay(200); }
Observation & Explanation
- When LEDâ turns ON, the photodiode sees maximum light, reading ~1023.
- Plot: a flat high lineâconfirms full-scale photodiode response.
Single-LED 100 Hz Flicker
Wiring (no change)
- LEDâ on D9 + photodiode as before.
100 Hz Blink
// Part C: Manual 100 Hz Flicker const int photoPin = A0; const int ledPin = 9; void setup() { pinMode(ledPin, OUTPUT); Serial.begin(115200); } void loop() { digitalWrite(ledPin, HIGH); delayMicroseconds(5000); // 5 ms ON @100 Hz Serial.println(analogRead(photoPin)); digitalWrite(ledPin, LOW); delayMicroseconds(5000); // 5 ms OFF Serial.println(analogRead(photoPin)); Serial.println("---"); // cycle marker }
- Upload the code.
- Observe the signal using the red pitaya oscilloscope. The signal captured on the photodiode resembles the square signal (on/off) we are powering the LED with.
- Adjust the
5000
value to explore other frequencies.
4. Arduino: Dual-LED Flicker & Photodiode Response
In this section, we drive two LEDs at different blink rates and observe how the photodiode âseesâ their combined light on the Red Pitaya oscilloscope.
Wiring Update
- Add LEDâ:
- Arduino D10 â 220 Ω â LEDâ â GND
- Photodiode remains the same:
- Anode â A0 & Red Pitaya IN1 via 10 kΩ pull-up to +5 V
- Cathode â GND
Arduino Sketch: Two-Rate Flicker
// Dual-LED Flicker const int photoPin = A0; const int led1Pin = 9; // LEDâ const int led2Pin = 10; // LEDâ const int burstCount = 200; const int sampleDelay = 100; // ”s void setup() { pinMode(led1Pin, OUTPUT); pinMode(led2Pin, OUTPUT); Serial.begin(115200); } void loop() { // Blink LEDâ at 50 Hz (10 ms on/off) digitalWrite(led1Pin, HIGH); delay(10); digitalWrite(led1Pin, LOW); delay(10); // Blink LEDâ at 100 Hz (5 ms on/off) digitalWrite(led2Pin, HIGH); delayMicroseconds(5000); digitalWrite(led2Pin, LOW); delayMicroseconds(5000); // Burst-sample photodiode for (int i = 0; i < burstCount; i++) { Serial.println(analogRead(photoPin)); delayMicroseconds(sampleDelay); } Serial.println("---"); delay(100); // pause between bursts }
- LEDâ toggles at 50 Hz (20 ms period).
- LEDâ toggles at 100 Hz (10 ms period).
- The photodiode sees the superposition of both flickers.
Red Pitaya Oscilloscope
- Run the dual-blink sketch.
- Open Oscilloscope on Red Pitaya.
- Set:
- Time/div: 5 ms/div (to capture both 50 Hz & 100 Hz)
- Voltage: 0â1 V range, probe atten. = 1 (LV)
Connecting Results
- Envelope (50 Hz): The taller peaks correspond to LEDâ on-cycles.
- Sub-peaks (100 Hz): Within each 20 ms window, LEDâ adds a faster modulation.
- Photodiode Output: Shows how two light sources at different frequencies combine into a single analog signal.
By comparing the captured waveform to our code, students can visually confirm superposition of flicker rates and appreciate how the photodiode plus Red Pitaya reveal complex light patternsâinsights that simple Arduino sampling alone cannot capture cleanly.