HI, I got a problem with my circuit. I used 5 near infrared LEDs as the light source and opt101 as the detector. the LEDs should turn on one by one and I manage to get it. the problem that occurs is the sensor show an inaccurate reading, which is a maximum reading of opt101 but when I use only one LED I manage to get the accurate reading of the sensor.
Below is my coding.
int a;
int voltage_A2 = A2;
int actualvoltage;
int voltage;
void setup()
{
pinMode(8, OUTPUT); //LED 1
pinMode (9, OUTPUT); //LED 2
pinMode (10, OUTPUT); //LED 3
pinMode (11, OUTPUT); //LED 4
pinMode (12, OUTPUT); //LED 5
pinMode (A2, INPUT); //DETECTOR
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
while (! Serial); // Wait untilSerial is ready
Serial.println("Enter A To Start Take Reading");
Serial.print (" 1 = 780nm");
Serial.println();
Serial.print (" 2 = 850nm");
Serial.println();
Serial.print (" 3 = 870nm");
Serial.println();
Serial.print (" 4 = 910nm");
Serial.println();
Serial.print (" 5 = 940nm");
Serial.println();}
void loop()
{
if (Serial.available())
{
char ch = Serial.read();
if (ch == 'A')
for (a=0; a<5; a++)
{
//_____________________________________________________________________
// LED 1
//_____________________________________________________________________
digitalWrite(8, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
voltage = analogRead (A2);
Serial.print("LED1 :: ");
Serial.print (voltage);
Serial.print ("\t");
digitalWrite(8, LOW); // turn the LED off by making the voltage LOW
//_____________________________________________________________________
// LED 2
//_____________________________________________________________________
analogWrite (9, 255); //turn the LED on (voltage is High)
delay(1000); // wait for a second
voltage = analogRead (A2);
Serial.print("LED2 :: ");
Serial.print (voltage);
Serial.print ("\t");
analogWrite(9, 0); // turn the LED off by making the voltage LOW
//_____________________________________________________________________
// LED 3
//____________________________________________________________________
analogWrite (10, 255); // TURN THE LED ON (VOLTAGE IS HIGH)
delay(1000); // wait for a second
voltage = analogRead (A2);
Serial.print("LED3 :: ");
Serial.print (voltage);
Serial.print ("\t");
analogWrite(10, 0); // turn the LED off by making the voltage LOW
//_____________________________________________________________________
// LED 4
//_____________________________________________________________________
analogWrite (11, 255); // TURN THE LED ON (VOLTAGE IS HIGH)
delay(1000); // wait for a second
voltage = analogRead (A2);
Serial.print("LED4 :: ");
Serial.print (voltage);
Serial.print ("\t");
analogWrite(11, 0); // turn the LED off by making the voltage LOW
//_____________________________________________________________________
// LED 5
//_____________________________________________________________________
digitalWrite (12, HIGH); // TURN THE LED ON (VOLTAGE IS HIGH)
delay(1000); // wait for a second
voltage = analogRead (A2);
Serial.print("LED5 :: ");
Serial.print (voltage);
Serial.print ("\t");
digitalWrite(12, LOW); // turn the LED off by making the voltage LOW
Serial.println();
// return;
//}
}
}
else {
}
}
