Measuring light intensity using photodiode BPW21R

// Define the analog input pin connected to the photodiode and the op-amp output
const int photodiodePin = 12 ; 
const int amplifierPin =10;  


// Define the LED pin if necessary
const int ledPin = 4; 

void setup() {
  // Initialize the LED pin as an output if used
  pinMode(ledPin, OUTPUT);

  // Initialize the analog input pin
  pinMode(photodiodePin, INPUT);
  pinMode(amplifierPin, INPUT);

  // Initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

void loop() {
  // Read the input on the amplifier pin:
    int photodiodeValue = analogRead(photodiodePin);
    int amplifierValue = analogRead(amplifierPin);

  // Turn on the LED for indication
  digitalWrite(ledPin, HIGH);
  delay(1000);
  
  digitalWrite(photodiodePin,HIGH);
  
   // Turn on the LED for indication
  digitalWrite(ledPin, LOW);
  delay(1000);
  
  // Convert the analog readings (which range from 0 - 1023) to voltage
  float photodiodeVoltage = photodiodeValue * (3.3 / 1023.0);
  float amplifierVoltage = amplifierValue * (3.3 / 1023.0);

  //Print out the raw analog values and voltage values you read:
  Serial.print("Photodiode Value: ");
  Serial.print(photodiodeValue);
  Serial.print(" | Amplifier Value: ");
  Serial.print(amplifierValue);
  Serial.print(" | Photodiode Voltage: ");
  Serial.print(photodiodeVoltage);
  Serial.print(" V | Amplifier Voltage: ");
  Serial.println(amplifierVoltage);
  
  // Wait for a second before the next loop
  delay(1000);

Summary

This text will be hidden

this is a snippet of my code. However the photodiode isnt printing any value. but the amplfier prints values. I'm wondering how thats possible. The photodiode is connected in reverse bias

Photodiode Value: 0 | Amplifier Value: 55 | Photodiode Voltage: 0.00 V | Amplifier Voltage: 0.18
Photodiode Value: 0 | Amplifier Value: 614 | Photodiode Voltage: 0.00 V | Amplifier Voltage: 1.98
Photodiode Value: 0 | Amplifier Value: 502 | Photodiode Voltage: 0.00 V | Amplifier Voltage: 1.62

Your photodiode and amplifier need to be connected to Analog pins like A0, A1 ...

It's also impossible to power an Uno via the 3.3V output pin

Thanks for getting back Jim. I have connected the photodiode and the amplifier to Analog pins. I have also disconnected the 3.3V to the arduino

This is the output now. I'm not getting an output for the amplfier. The photodiode values aren't changing too.

Photodiode Value: 675 | Amplifier Value: 0 V | Amplifier Voltage: 0.00
Photodiode Value: 675 | Amplifier Value: 0 V | Amplifier Voltage: 0.00
Photodiode Value: 675 | Amplifier Value: 0 V | Amplifier Voltage: 0.00

What's the part number of the opamp?

741 operational amplifier

Why are you using 3.3V?
uA741 or LM741?
Remove this line

digitalWrite(photodiodePin,HIGH);

LM741 Please, I have removed that line

Lm741 is not specified for single supply operation. You either need a different opamp or dual +/- 12V supplies.

Hm this is interesting, thanks for letting me know. LM741 is the default opAmp in tinkercard.


the image i have uploaded is the actual project i am working on. however the photodiode doesnt seem to print any value. The photodiode used is BPW21R, the amplifier is OPA380, ADC is ADC121C021. The reason for giving 3.3V was test the project with that before supplying the circuit with 5V

Do you plan on making a real circuit or are you just playing with simulations?

It is real project i'm working on, the idea of tinkercard was to get the photodiode to work. I just uploaded a schematic of the entire project im working on. Let me know if you can see it.

I can see it. So what is the problem.
Does tinkercan have a model of the BPW21R and the OPA380?

Nope, they don't. My actual circuit doesnt work and I cant also read values from the photodiode. I'm also wondering why the amplifier gives an output but the photodiode doesn't. The amplifier value is also very low. I get a value around 0.5V. which is too small.

The circuit you posted has neither a photodiode, OPA380 or an Uno.

How about showing a schematic of the actual circuit you are trying to make work. with the compontents you are actually using.

I'm sorry about that. In the actual hardware, I am using esp32-wroom-32E. I couldnt not exact components in KiCad thats why i used those components. for the photodiode, i uploaded the spice models for the photodiode, amplifier and ADC. I hope this clarifies the schematics. Also, the resistor and capacitor values are same as my hardware

No it doesn't. I have no idea if you have thing connected the right way if you use substitute components, that may or may have the same pinout.
Also the image is very blurry and I can't make out part numbers
Where is the photodiode?

Here is what I see:
image

Hint: using pencil and paper, it is quite easy to make a schematic that has the correct parts, legible pin numbers, legible device IDs and correct connections. Post a photo.

  • is d2 The bpw?
  • how is d2 connected to the op-amp ( I think you need to connect the catode to the inverting input )?
  • did you also connect the catode to an analog pin of the esp32 ( don't do that )?

ADDITION
also the capacitor in series with the output of the op-amp what is used for ( remove it )
and why connecting io4 directly to vcc ( quite dangerous )?

The substitute components are similar to actual components with the same number of pinouts.

But the diagram is wrong and the circuit won't do anything useful. For help on this forum, post correct information about your project.