Go Down

Topic: Photo interrupter outputting erratic analog signal  (Read 254 times) previous topic - next topic

amachinetech

Oct 28, 2017, 06:27 am Last Edit: Oct 28, 2017, 06:34 am by amachinetech
Evening all I have an issue that I am at a loss to explain. I have a photo interrupter PT# EE-SX4235-P2 by Omeron.

link to data sheet :https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=3&ved=0ahUKEwjbwdbktZLXAhWJ6IMKHfe-CX8QFgg0MAI&url=http%3A%2F%2Fwww.omron.com%2Fecb%2Fproducts%2Fpdf%2Fen-ee_sx4235a_p2.pdf&usg=AOvVaw1uZekyDWXiiVuau0a3yEXN

According the data sheet "Photo IC output signals directly connect with C-MOS and TTL" which in my mind tells me that no outside components are needed to make this thing work. Will operate on up to 7 volts (sourcing power from arduino 5 volt pin)

I had the output pin previously connected to a digital pin and was attempting to digitalRead the pin when it was completely obstructed by a business card. My program was acting like I was in and out of the beam. I connected the output pin to an analog pin and read what I was getting out with no other programming operating.

IE analogRead A0 save to X then Serial.print X.

When beam is not obstructed I get a stream of 0s like I would expect. When I block the beam with a business card or anything else i get a stream that looks like this.


11
76
743
1
13
72
751
11
19
332
545
25
0
587
262
30
66
759
12
15
318
550
12
0


I disassembled the sensor looking for any other circuity inside. With the exception of a surface mount resistor value 271 , the led and the sensor there is no other parts inside. here is a copy of the actual code that I used to read this

Code: [Select]

int x = 0;
const int sensor = A0;

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
x = analogRead(A0);
Serial.println(x);

}


To the question ladies and gents, what am i missing. I have a basket of these sensors that I recovered from a large copy machine and was hoping I could do something interesting with them. Am I making a noob mistake? I read quite a few of the forum posts looking for a symptom like this. Found something close but that sensor was outputting opposite to mine (high when clear and low when obstructed) so a INPUT_PULLUP wouldn't work here like in that case. Your help would be greatly appreciated

a machine tech

edit: just for grins I tried 4 other sensors and got similar results so at least thats consistent.

Wawa

Two things.

1) This is a digital device, so the output should be connected to a digital pin.

2) It has an open collector output, so it needs a pull up resistor to 5volt.

Or, easier, enable the internal pull up resistor on the pin in setup().

pinMode(PhotoPin, INPUT_PULLUP);

Leo..

wvmarle

Found something close but that sensor was outputting opposite to mine (high when clear and low when obstructed) so a INPUT_PULLUP wouldn't work here like in that case. Your help would be greatly appreciated
That's not true. It doesn't matter WHEN the sensor pulls low the signal, what matters is that it's an open drain (aka open collector) output, so the sensor pulls low the signal, and relies on an external resistor to pull it up (and that external resistor may indeed be the internal pull-up of the Arduino). Whether it pulls low the output when it's blocked or when it's clear is irrelevant for this. That's just relevant to you when reading the output.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

MarkT

You definitely need to use a pinMode INPUT_PULLUP and digitalRead to sense it.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

amachinetech

So if I am wrapping my head around this correctly the sensor is pulling the pin low when it is clear and then letting the pin float when it is obstructed making an erattic reading. So by forcing the pin high with INPUT_PULLUP that makes the sensor act as a voltage divider. When the sensor is clear it drives the pin low actively by shorting to ground. When the sensor is blocked it no longer is shorted to ground and then the INPUT_PULLUP takes over and drives the pin HIGH. Well done gents thanks for the clarification. So the true answer is yes you ARE making a noob mistake. ;) Thanks for your assistance.   

amachinetech

wvmarle

Exactly, that's it! Good luck with your sensor, hope you can get good results with it.

Just one thing: you better read it using a digitalRead() rather than analogRead(). It's just cleaner code, and after all it's a digital signal.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Go Up