Connecting photodiode and potentiometer to Arduino

Hi everyone,

I am trying to rebuild a device and have wired everything according to the schematic:

You can see that the output pin of the photodiode (pin 5) is connected to the ADC pin A0 of the Arduino. By adjusting the potentiometer, I should of course get values between 0 - 1023 (10 bit ADC). However, no matter how I adjust the potentiometer, I always get 1023, so I think the sensor is "overshooting" all the time. I have tested the potentiometer previously and it works fine. I suspect there is something wrong with the wiring diagram.

Any ideas? Thanks in advance.

Lea

Why do you think that? Light and dark will make a very large difference, but the pot can make only very minor changes in the op amp gain, changing the feedback resistance from 1.8M to 1.9M.

Table 1 (and Fig. 18) from the OPT101 data sheet shows why:

Also, since you have effectively removed the built in feedback cap, the op amp may be oscillating.

if you want 0-1023 from potentiometer - connect it to A1

Before wiring the circuit for variable gain, test the OPT101 function in its default configuration, connecting pin 4 to pin 5.

Capture

The potentiometer in your circuit adjusts the gain of the sensor over a narrow range. The output of the sensor is most influenced by the intensity of the light illuminating it. You will have to attenuate the light hitting the device to get the output out of saturation.

Saturation is the technical term for "overshooting" that you used.

What is the difference between A0 and A1? I thought I could basically use and analog pin.

Nope:


This means the output range is approx. 0.0075 to 3.85V with a 5V supply. If you want the full 0-5V range that coincides with your power supply, then you'd have to perform additional signal conditioning.

However, I wouldn't recommend doing this and instead limit the output voltage swing to the range of (ca.) 0 - 1.05 V with a resistor divider on the output - your pot meter can be the lower leg of this divider. This will bring the signal range within the 1.1V internal reference on your Arduino. The net result is much better accuracy especially because the output will no longer be dependent on variations in your voltage supply. It'll remove the possible problem of seeing significant difference in the readings depending whether you run the system from a computer USB port vs. an external power supply etc.

This is in addition to the comments you've already received. Please heed especially @jremington's reply #4 and initially use the chip/sensor in its default configuration. Tie pin 1 to your voltage supply, 8 and 3 to GND, and connect pins 4 and 5 to an analog input on your Arduino. See what you get that way. Then tie 4 & 5 to the upper leg of your pot meter VR2, with the lower leg to GND and the wiper to an analog pin if you want to reduce the overall range. Ultimately you can add one or two additional resistors in order to narrow the range that you can set with the pot meter to enhance its resolution.

Hi, @lerehmi

Can you please post your code.

Do you have a DMM? (Digital MultiMeter)
What DC voltage do you measure on A0?

Are you covering your sensor completely (dark) and then exposed to light to see if you get any changes?

Can you post some images of your project?
So we can see your component layout.

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

@jremington and @rsmls thank you both for the suggestions, I will definitely try this. Tbh I was blindly following the script for the device as I am not very experienced in things hardware and in the script it said that the wiring as in the schematic should allow 0 - 1023 range by adjusting the potentiometer.

@TomGeorge I do not have a DMM but I could organise one. :grinning:

If I cover the sensor completely, I get changes. Thing is, if the sensor is uncovered I don't want it to be fully saturated, but it would be nice, if the output would be ~ 1000 when uncovered and as close to 0 as possible when fully covered.

Here the code snippet I use for this part:

const int pin = A0; 
const int numReadings = 20; // Number of total sensor readings to take 
int rawReadingValue = 0; 

int takeMultipleReadings(int pin) {
  int totalReadings = 0;
  for (int i = 0; i < numReadings; ++i) {
    totalReadings += analogRead(pin);
    delay(10);  
  }
  return totalReadings / numReadings; // Averaging readings
}

void setup() {
  Serial.begin(9600);  
  pinMode(pin, INPUT);
  analogRead(pin);
}

void loop() {
  rawReadingValue = takeMultipleReadings(pin);
  Serial.println(String(rawReadingValue));
  delay(500);
}

A0 is already occupied by Photosensor, A1 is free

Going out on a limb, there are three possibilities that I see:
1: The guide you're following actually said something else, but you misunderstood/misinterpreted it.
2: The guide you're following is wrong (common with e.g. Instructables).
3: The guide you're following assumes a very specific light level range hitting the sensor with very (very!) limited variation, and the few percent of variation that the pot meter gives is an adequate adjustment range for the system.
In all three instances I'd be suspicious of the schematic as you've drawn it and redesign it from scratch, starting with the most simple connection as outlined in the chip's datasheet.

As I indicated before in #7, this isn't going to happen as long as you use your 5V supply as the analogReference (as default in Arduino) because the output of the sensor is limited to Vdd-1.3V. Which is one more reason to re-design the circuit.

@rsmls okay, I will try that. Thanks a lot. Just to be clear.. I didn't come up with the schematic myself but it was provided in the instructions thing :joy:

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