Hey Guys,
I have an optical sensor and my simple circuit is shown in the attached image.
The red wire goes to the 5V pin on the 'Arduino' board.
The black wire goes to ground.
The blue wire is the digital output which goes to pin 2 on the board.
Code:
int opt = 2;
void setup() {
Serial.begin(9600);
pinMode (opt, INPUT);
}
void loop() {
int sensorValue = digitalRead(opt);
Serial.println(sensorValue);
delay(50);
}
The only output I am getting is 0 regardless if I am covering the sensor or not.
However if I use the yellow wire from the sensor, which is the analogue output, and connect it to one of the board's analogue inputs and rewrite the code, I will get an output from the sensor.
However when I find the output voltage = sensorAnalogOutput * 5.0/1023.0
I get a voltage that ranges from 0.03V when nothing is blocking the sensor and 1.3V when my finger is covering the sensor completely.
I am guessing that the output voltage is not high enough to give me a digital output of 1.
Is there anything I can do as I would much prefer to utilise the digital output. If it helps, I have been told that the sensor should not receive more than 7V.
Any help is greatly appreciated.