transmissive optical sensor always being HIGH

I have the tsct 2000 transmissive optical sensor, and with the following setup, I only receive 1's on the serial moniter, even thought I put something in between the sensor.

The code is quite simple:

const int sensor = 3;
int sensor_value;

void setup() {
  Serial.begin(9600);
  pinMode(sensor, INPUT);
}

void loop() {
  sensor_value = digitalRead(sensor);
  Serial.println(sensor_value);
}

Make a simple pencil drawing showing how you have everything connected and post a photo of the drawing. Please DO NOT use Fritzing.

...R

I already attached a pencil drawing of the circuit. And just out of curiosity, why shouldn't I use Fritzing?

220 ohms is way too low a value for a pullup. Try with 10K. Or remove the external pullup and use the internal pullup. Use pinMode(3, INPUT_PULLUP) to enable the internal pullup.

I tried both your suggestions, but to no avail. Still only 1's getting printed.

When you have a component that you are not familiar with, the first thing that you should do is take a look at its datasheet. There may seem to be a lot of complicated stuff inside, but there is usually simpler stuff that can help you - for example - example circuits for connecting the device up. The more datasheets you look at, the more you will begin to understand.

Take a look at the test circuit shown in the datasheet for the TCST2000 and you should quickly see what you are doing wrong.

Bassusour:
And just out of curiosity, why shouldn't I use Fritzing?

Forum consensus is that it can be difficult to impossible to be sure how things are really connected. Better just use a pencil.

groundFungus:
220 ohms is way too low a value for a pullup. Try with 10K. Or remove the external pullup and use the internal pullup. Use pinMode(3, INPUT_PULLUP) to enable the internal pullup.

That isn't going to fix it - look again.

Edit: That link was for a similar part, can't find the 2000 on the Vishay website, but here is a link from some random site.

Pin3 should be connected to the other side of the 220ohm resistor. The input will read HIGH when the sensor is not illuminated, and LOW, when illuminated.

Pin3 should be connected to the other side of the 220ohm resistor. The input will read HIGH when the sensor is not illuminated, and LOW, when illuminated.

When I tested your suggestion, the same problem persisted

Take a look at the test circuit shown in the datasheet for the TCST2000 and you should quickly see what you are doing wrong.

I saw a schematic, which I will attach, which I tried out. However, Now it was only showing 0's and didn't change when something was in the way

other circuit.PNG

Bassusour:
When I tested your suggestion, the same problem persisted
I saw a schematic, which I will attach, which I tried out. However, Now it was only showing 0's and didn't change when something was in the way

Can you just check again that you have the TCST connected up correctly. I notice that the layout in the datasheet's test circuit does not match the physical layout of the device as shown on the first page. The physical layout does not match your hand drawn schematic either.

Can you document how you have the four pins coming out of the bottom of the unit are connected. I can see in the data sheet that the terminal arrangement may be confusing.

As mentioned the sensor side resistor is far too small. Try 10k or larger, and connect the right point to pin3, the junction of
the phototransistor and the pull-up.

An optical sensor like this will have very low gain as it has a lossy optical path. So 20mA in the LED
might only lead to a fraction of a mA through the photo transistor.

You may also have to worry about ambient light getting in.

This is how I set it up. I assume I did it correct, but I'm a beginner.

That doesn't look right. You need to connect the + pin to 5v like you did with the LED side, and the D pin to the resistor/pin3. And take the other's advice about increasing the resistor; start with the 10k.
While you are at it, that 50 Ohm resistor for the LED is sailing far too close to the wind at 5v supply; 68 Ohm would be a safer choice.

Hmm, still only printing 0's. This is my new circuit.

Bassusour:
Hmm, still only printing 0's. This is my new circuit.

Circuit looks good now. For testing purposes, connect the pin 3 input to the analogue pin A0 instead and try the AnalogReadSerial example sketch in File->Examples->01 Basics->AnalogReadSerial.
Post your serial output.

With something in-between: 14-17
With nothing in-between: 67-70

Try increasing the resistor from 10k to 20k and higher. I imagine you'll need 120-150k.

Bassusour:
I already attached a pencil drawing of the circuit. And just out of curiosity, why shouldn't I use Fritzing?

Sorry, I don't know how I missed that.

The first wiring arrangement is wrong. The connection to pin 3 should come from the other side of the resistor (i.e between the resistor and the photo diode) and, as someone else has said it should be a 10k resistor.

I can't make sense of the diagram in Reply #13

This Sparkfun diagram for the QRE1113 should work. I have used it with several optical switches, Never mind the fact that they call it an analog circuit.

...R

I'm not sure why, but when I tested again, the results were varying from 970 - 1023 both when something were in-between or not. I didn't change a resistor. When i was wiggling the element between the sensors the results changed - permanently. Now the standard without something in-between is 885 - 891. When I did it again, the standard value changed to 352 - 356 without anything in between.

I can't make sense of the diagram in Reply #13

Check out the my_setup.jpg picture in one of my previous replies to get what I mean

Bassusour:
I'm not sure why, but when I tested again, the results were varying from 970 - 1023 both when something were in-between or not. I didn't change a resistor. When i was wiggling the element between the sensors the results changed - permanently. Now the standard without something in-between is 885 - 891. When I did it again, the standard value changed to 352 - 356 without anything in between.

Huh? They shouldn't just change like that. Check you don't have any short circuits or wobbly contacts.
Are you doing this on a solderless breadboard?