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() {
PD1Voltage=analogRead(A0);
PD2Voltage=analogRead(A1);
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