Two seperate In- and Outputs

Hi, i am currently working on a code where the Arduino shows me, if an Input Voltage (generated by a Photodiode ("PD")) occurs - or not.
If there is an Input Voltage ("analogRead"), a LED has to turn ON ("digitalWrite(2, HIGH)")
If the Input Voltage is below a certain value, the LED has to stay off ("digitalWrite(2,LOW)")

I have two Photodiodes and two LEDs.
If Input 1 & 2 detect no voltage, no LED should light up.
If Input 1 detects a voltage and Input 2 doesn't, only LED1 should light up.
If Input 2 detects a voltage and Input 1 doesn't, only LED 2 should light up.
If Input 1 & 2 have a voltage, LEDs 1 & 2 should light up.

I came up with the following Code, which isnt't working:

int PD1Voltage;
int PD2Voltage;

void setup() {
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);

void loop() {


if (PD1Voltage>205) digitalWrite(2, HIGH);
else digitalWrite(2, LOW);

if (PD2Voltage>205) digitalWrite(3, HIGH);
else digitalWrite(3, LOW);


If either Input 1 (A0) or Input 2 (A1) detect a voltage, both LEDs turn on.

Any ideas are highly appreciated :slight_smile:

Put in some serial prints so you can see what the analogReads are getting.

Also, remember that the Arduino only has one ADC and readings can be influenced by prior ones. A common fix for this is to read each one twice.

void setup() 
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);

void loop() 
  int PD1Voltage=analogRead(A0);
  int PD2Voltage=analogRead(A1);
  digitalWrite(2,  PD1Voltage > 205 ? HIGH : LOW);
  digitalWrite(3,  PD2Voltage > 205 ? HIGH : LOW);

I assume you have worked out the circuitry around the photodiodes before you started programming...right?
A photodiode is a very high impedance device. You need an opamp or at the very least a simple NPN transistor to amplify its signal to something that the Arduino can work with. Can you show a schematic of your circuitry?

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