Subtracting 2 photodiodes or 2 LDR's using an opamp and feed the difference into an analog input on arduino

Hi I am a little new to this subject, i want to use 2 photo diodes or 2 ldr's and produce the difference in output for correction, i can easily do itusing 2 analog ports, but as i need to use more analog inputs i thought that i could use an opamp to subtract the signals and feed the difference to 1 Analog input. I have been searching high and low for some similar circuits, but i can only find examples of feeding 1 photodiode or LDR into 1 port.
I was hoping someone in here have done something similar, and could help me with a diagram on how to do it?

This is definitely possible. There are some decent tutorials for differential amplifiers on the web. For example:
https://www.electronics-tutorials.ws/opamp/opamp_5.html

Here, your photodiodes would connect to the V1 and V2 nodes. The equations listed in the article should help to estimate values for your resistors, just don't forget that op-amps have very high input impedance, so you can use fairly high value resistors on the input of the opamp. The output of the opamp can feed in to a single analog input, just as you are thinking.

I hope this helps!

How abut this?

This looks like a great reference too!

Try a Google of "differential amplifier circuit diagram" and you will get plenty of hits. I would use LDRs and each LDR has a series resistor. Try for getting the LDRs as close as possible and use 1% resistors so the same amount of light striking either produces an identical output. Those voltages run into a differential amplifier circuit which will output the difference. :slight_smile: That what you have in mind? You could use two analog channels and let the code do the math but if you want to only use a single analog channel I would be thinking differential amplifier.

I guess I was about 3 min too slow. :slight_smile:

Ron

Very good description, my problem is that the output would most likely fluctuate between -2.5 v and 2.5 v, should i use a summin amplifier to make the output voltage positive like having Vo from the the differtiator feed into another opamp where i then add 2.5 volts thus giving me a regular 0 to 5 volt input for A0 on the Arduino ?

Yes, that is going to be required in order to use the Analog In on the Arduino. Since the Analog In pin can only accept voltage between 0 and 5V, you will have to ensure that the output of your circuit is always positive.

You definitely have the right idea. If the difference between your sensors is definitely going to be limited to -2.5V to +2.5V, then just add +2.5V and the final signal will be between 0-5V, which is perfect.

However, if the sum of your sensors can be less than -2.5V, or if it can be more than +2.5V, you might want to consider adding a little bit of protection to make sure that never happens. For example, you can use a couple of zener diodes rated for 2.5V, connected in a way such that if your difference is ever lower than -2.5V, the rest of the voltage drops across the zener. Same thing for the positive range, connect the zener so that the voltage never goes above +2.5V. If you do this, then you can guarantee that your difference will always be in between -2.5 and +2.5, so you can safely add the additional +2.5V and know that you will never go over 5 or less than 0. Does this make sense?

I think that you can bias the differential amplifier +2.5V this way:


With R3=R4
(from here, at the bottom: https://fab.cba.mit.edu/classes/863.16/section.Architecture/people/Ge/bias_opamp.pdf )

Or if you have one opamp left in the IC, you can just do what you propose.

And maybe better add the protection diodes as suggested, just in case. Just 2 schottky diodes will work. One from GND pointing to the MCU input pin and the other one from the pin pointing to Vcc.

Yes and then we offset so you are always above 0.0 volts. Excellent examples given. :slight_smile:

Ron

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.