Simple Optical Sensor however signal too small

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.

download.png

Do you have a link to a specification page or datasheet? That looks like maybe you have connected to the wrong pins on the sensor module.

Hey Morgan,
Thank you for the response, however I am quite certain that the connections to the sensor module are correct. I attached an image of the connections up close.

Which is not the information I asked for.

Connecting wires between an Arduino and a sensor does not guarantee that a good electrical connection is made.

Check the continuity of all the connections, and check the supply and output voltages at the sensor, using your multimeter.

You need to tell what specific optical detector you are using and you need to post a link to its datasheet.

Without the facts we are just guessing.

...R