Photodiode for detecting light changes on desktop monitor

Hi

I'm fairly new to working with the Arduino and drawing electrical schematics so apologies up front if I have a few (or many!) things wrong. Any and all feedback would be really appreciated, I'm hear to learn and happy to get stuck in.

I'm trying to create a simple tool that will allow me to test light changing from black to white on my desktop monitor. Once I have the basics of detecting light changes with the photodiode down I would then like to build upon it and make the tool more accurate.

I have been following this guide which has been very helpful:

The issue I'm having is that the output value displayed in the serial monitor is only outputting 5.00 with light shinning directly on the photodiode and when it is the diode is completely covered and light removed.

Here is the drawing I created in tinkercad.

Arduino Drawing

I'm using the same code from the guide as well.

I have a few notable part differences to the above guide:

I'm using an MCP6022 op amp as opposed to the LTC1050.
An 25V 100uf capacitor. Not sure what the one is in the guide as it didn't say.
And an Vishay, BPW20RF IR + Visible Light Si Photodiode, Through Hole TO-5

The photodiode will be encased in a small box placed over 20cm x 20cm section of the monitor so that ambient light does not creep in. On the monitor display will be a simple program that changes from black to white. I would like to be able to detect when the light changes.

I would really appreciate a sanity check to see where I've gone wrong. I would also be very interested to hear how I can improve upon the design and what I should be considering when I look to improve the performance.

Thanks in advance.

Serious mistake. 100 picoFarads (100 pF) would be more appropriate. If a tutorial doesn't clearly indicate component values and provide a proper schematic diagram, find a better tutorial.

I'm using an MCP6022 op amp as opposed to the LTC1050.

Did you check that the pinouts are the same? Fritzing diagrams are almost completely useless for detecting such wiring problems, which is why we STRONGLY discourage people to post them.

Edit: I checked. The LTC1050 and MCP6022 are completely different, both internally and externally.

Bypass capacitors across the power pins (typically 100 nF) are absolutely required for op amp circuits. Another negative for the linked tutorial.

Post a hand drawn wiring diagram, showing the pin identifications instead.

Here's the wiring diagram.

I looked up both the op amps and compared them to see what the differences were before wiring it. I think I wired it up correctly on the MCP6022 taking in account of the different layout but I might be wrong.

Thanks for pointing out the capacitor issue. I don't have any picoFarads to hand but will order some.

Looks like the wiring diagram doesn't have the op amp OUT going to A0 or the power from 5v going to V+.. They are on the board and in the Fritzing though. I'll see if I can make a manual drawing which represents it better. The Tinkercad wiring diagram doesn't look right.

This seems rather complicated and uses devices that are external to the Arduino and I think unnecessary. It complicates the basic design.


I use this with a photo transistor to change the display intensity...

Read it into the a/d pin, do the conversion, compute the values and reload the pwm generator.

The r/c network controls the slew rate. In this case, turn the room light off, and it slowly dims...

Screenshot from 2022-09-15 13-24-37


All you would need to do is calibrate it for your purposes.


The cap in the article is specified as "100 nanofarad ceramic (non-polarized) capacitor"


Might want to draw your schematics in a more 'orderly' way... You have an r/c network... draw it that way... it's also much more clear to someone trying to figure out what you're up to...

As an example, I took the easy part and skipped the mess with the opamp :crazy_face:

Screenshot from 2022-09-15 14-00-08

If you use a standard cad program you can get the 'footprint' for your software and it includes information about what a pin does and the pin number... your pin number are missing, so I have to find and pull those documents to determine how you wired it... The article does just the opposite and has pin numbers you have to count...

This was a standard footprint for Eagle cad, notice how much more information is there..

Screenshot from 2022-09-15 14-18-56

If it was cleaned up, you'd probably see that you have the Vcc for the opamp wired to the analog input of the Arduino, so no power to the opamp. The output of the opamp is not connected to anything... I'm sure this is probably incorrect...

I suspect this is not the schematic... since this won't work and is probably why you read the wrong data all the time, light or dark... you have effectively disabled the opamp ...


You are doing great, these are improvements you can make as you go...

It also points out the failure of these videos that don't include a schematic. They want to teach you in a way that in itself limits your ability to move forward.

If you don't see them, it's much more difficult to see what they are doing...

Good luck

:smiley_cat:

Photodiodes are tricky because they put-out a tiny current. That means you need a high-gain amplifier which can be unstable and it will be sensitive to electrical noise.

A phototransistor or a light dependent resistor (LDR) is easier to use.

No, several errors. As mentioned, wrong size feedback cap, no bypass cap, feedback resistor is probably too low, the schematic shows no connection to Vout, photodiode appears to be backwards, etc.

Below is a typical wiring diagram, but the feedback resistors are very high and intended for very low light levels. I would suggest doing away with the second stage, and changing R32 to 1Meg.

Keep in mind that in a photodiode, the light-induced current flows in the opposite direction to the diode arrow symbol.

Thanks for the encouraging words. It's a totally new area for me so I find it a little overwhelming.

The cap in the article is specified as "100 nanofarad ceramic (non -polarized) capacitor"

I completely missed that. Thanks for pointing it out. I ordered some of those last night and they have just arrived.

If you use a standard cad program..

I've not used any sort of CAD software before, let alone made an drawing electrical schematics. So I've spent a bit of time today getting my head around KiCAD and loaded in the footprint for the op amp.

I must admit, the logical layout of the schematic is a lot easier to follow for the small project that I'm working on. I prefer it much more than the Fritzing diagrams. However, I'm still struggling to really understand if my breadboard matches the drawing..

Here's my first attempt at trying to draw a schematic for what I'm attempting to make:

One of the things I noticed while looking back over at the MCP6022 layout was that the Vout for the inputs I was using was on the same side (pin 1, VoutA). I had my Arduino wired up to the MCP6022 pin 7 which is the VoutB.

With things rewired to VoutA now and with the 10nF and 100nF (based on
jremington post), in place now, I'm now getting a constant reading of 0.00. So something is still a miss..

The schematic is still wrong. The photodiode anode connects to GND, not VinA-. The junction with the photodiode and the feedback components connects to VinA-.

Study the left hand portion of the schematic in post #7 more carefully (you can consider GND and "0V" to be the same in that diagram).

10K feedback is almost certainly too small.

Thanks for this. I just replied to jkwilborn with a my first attempt at trying to make a proper schematic. I also ordered some new capacitors and have swapped out the 100uF with a 10nF. Additionally, I also put in a 100nF as per C46 in your example diagram. Though I'm not entirely sure what that does in that part of the circuit?

Look up "IC decoupling capacitor". It is essential to reduce noise and signals carried in the power supply leads and should be placed directly across the Vcc (Vdd) and GND power pins of each IC.

BTW this design is called a "transimpedance amplifier" and there are many tutorials on that topic, on line.

OK, thanks. I'll have a look and try and get my head around it. I don't have a 1Meg resistor to hand so will get an assortment of sizes on order. I forgot you mentioned that in a previous post.

I had anode and cathode confused in my head. Updated the diagram.

I also found a 330k resistor which I have put in place until the 1Meg (and assortment) arrives.

I'm now getting different results output to the serial monitor. Anything between 0.5 and 1.7. Although it doesn't appear to make much difference if I shine a light on it or not. The values never go much (+/- 0.2) above or below that range.

Post the code, using code tags, and some examples of the serial monitor output, using cut and paste.

How do you know which is the anode and the cathode on your photodiode? If you are not certain, try reversing the connections (which won't damage anything), but the circuit will work properly only if the orientation is correct.

I'm going by the photodiode guide:

I'm using the notch as an indicator to +

Tried swapping it around but it hasn't made a difference.

Here's a excerpt of the output:

0.59
0.63
0.66
0.67
0.47
0.63
0.64
0.62
0.65
0.64
0.59
0.64
0.66
0.64
0.63
1.08
0.67
0.64
0.58
0.73
0.63
0.62
0.61
0.65
0.68
0.63

Please post the code, using code tags, and a photo of your wiring. Something is very wrong.

Use your multimeter to verify that the photodiode and the op amp are working properly. The photodiode will generate up to 0.7V in full sunlight.

Hi. Here is the code I'm using. It is lifted straight from the guide I linked to in the initial post with the only exception being that I changed the delay from 100 to 500.

#define inPin0 A0
 
void setup(void) {
 
  Serial.begin(9600);
  Serial.println();
     
}
 
void loop(void) {
  int pinRead0 = 0;
  float pVolt0 = 0;
  pinRead0 = analogRead(inPin0);
  pVolt0 = pinRead0 / 1024.0 * 5.0;
  Serial.print(pVolt0);
  Serial.println();
   
  delay(500);
   
}

And here are photos of the wiring:

Close up of the breadboard:

Top view of the whole setup:

Close up of the Arduino:

I used my Owon multimeter on the photodiode and get 0.57 with a bit of sunlight coming into the room.

Connect the multimeter probes to pin 4 (Vss) and pin 1 (VoutA) I get a reading of 0.36.

I suspect my problem might be with me not fully understanding how to convert the schematic into the breadboard wiring. That's a total guess though.

Thanks for having a look.

Hi,
What readings do you get if you completely cover the sensor?
What readings do you get if you shine a bright light (torch/flashlight) at the sensor?

Tom.... :smiley: :+1: :coffee: :australia:

Hi,
Just humour me, try;

#define inPin0 A0

void setup(void)
{
  Serial.begin(9600);
  Serial.println();
}

void loop(void)
{
  int pinRead0 = 0;
  float pVolt0 = 0;
  pinRead0 = analogRead(inPin0);
  pVolt0 = (float)pinRead0 * 5.0 / 1024.0;
  Serial.print("rawA0 = ");
  Serial.print(pinRead0);
  Serial.print("  A0 volts = ");
  Serial.print(pVolt0);
  Serial.println();
  delay(500);
}

I have added some diagnostic output and a different way of expressing the equation.

Tom... :smiley: :+1: :coffee: :australia:

Hi Tom

I’ll try this when I get home later along with getting the readings. Thanks for the suggestion.

Will