Go Down

Topic: IR Sensor Help (Read 1 time) previous topic - next topic

17asleep

Hello

I am trying to repurpose an IR sensor that I dug out of an old Zerox machine, but I am having a hard time understanding the results that I am getting with it. The sensor is an Omron Photomicrosensor (Transmissive)
EE-SX4009-P10. I have attached the spec sheet for it. IO have it wired up with a 9 volt battery on the positive and negative terminals and the output I have wired to A0 on my UNO. I have established that there is IR being generated by looking at the led through my camera. There is violet light visible when battery is attached. I am using the AnalogRead Serial Tutorial sketch to read what is coming off the output pin and that's where the confusion starts. It seems that there is always some sort of signal being sent, not matter if the sensor is blocked or not. the number being sent to the serial monitor drops slightly when I put something between the emitter and the sensor, but only very slightly. Nowhere near enough to be useful as a signal, an not even consistently. I have tried amplifying the signal with a transistor, but that just helps me prove the same thing on a larger scale. Can anyone point out anything that I am doing wrong here?

Paulcet

That is an "Open collector" output.  You need a pull-up resistor on the output. 

17asleep

Could you elaborate on that? I am pretty new to this stuff and I'm not sure what that means.

kuhny1

#3
Jan 19, 2016, 03:53 am Last Edit: Jan 19, 2016, 04:00 am by kuhny1
Meaning your going to have to have a resistor, with a value greater than or equal to 1k (On the same input pin you are reading on) going to the +5v rail on the arduino. This stops the arduino pin from floating and reading a hole bunch of noise. Any time you are using a input always count on having a pull up or pull down (a resistor going from the pin your reading to ground). Whether your using a pull up or pull down will depend on the signal. try each on and see.

Also make sure when using pull ups, NEVER connect to resistor to a rail greater than 5v, youll end up with a crispy atmega. This isnt always the case but you can damage something if our resistor value is too low.

I made a quick and messy diagram for you in the attatchments

OldSteve

#4
Jan 19, 2016, 04:35 am Last Edit: Jan 19, 2016, 04:36 am by OldSteve
@17asleep, you don't need to read the sensor output with 'analogRead()'. It's a digital signal, 'high' or 'low', so use 'digitalRead()'.
Also, depending on the distance to the sensor, you can probably use an internal pullup resistor and avoid connecting an external resistor. Just use an external resistor with lower resistance if you get unexpected results. Internal pullup resistors have a value of about 30K to 50K.
To enable an internal pullup:-
Code: [Select]
pinMode(pin,INPUT_PULLUP);
Please do not PM me for help. I am not a personal consultant.
And others will benefit as well if you post your question publicly on the forums.

17asleep

So I should be connected to a digital pin rather than analog?

OldSteve

So I should be connected to a digital pin rather than analog?
You could, or you could continue to use the analogue pin that you're already connecting to, and initialise it as a digital pin. All pins on a UNO are digital I/O by default, and can be used as digital inputs or outputs.
Just do it as I showed:-
Code: [Select]
pinMode(pin, INPUT_PULLUP);
Please do not PM me for help. I am not a personal consultant.
And others will benefit as well if you post your question publicly on the forums.

17asleep

Using INPUT_PULLUP, I get a solid stream of 1s to the serial monitor. Using a pulldown resistor I get a solid stream of 0s, no matter if the beam is blocked or not. Using neither INPUT_PULLUP or a resistor i get an unstable stream of 1s and 0s the don't seem to have any corelation to whether the beam is blocked or not.

Here is the code I am using, in case that might make a diference,


// the setup routine runs once when you press reset:
void setup() {
 // initialize serial communication at 9600 bits per second:
 Serial.begin(9600);
 pinMode(8, INPUT);
}

// the loop routine runs over and over again forever:
void loop() {
 // read the input on digital pin 8:
 int sensorValue = digitalRead(8);
 // print out the value you read:
 Serial.println(sensorValue);
 delay(750);        // delay in between reads for stability
}


I have also attached a photo of the cuircut.

Wawa

#8
Jan 19, 2016, 09:50 pm Last Edit: Jan 19, 2016, 09:54 pm by Wawa
I don't see a shared ground.
Sensor ground has to be connected to Arduino ground.
Leo..

17asleep

I don't see a shared ground.
Sensor ground has to be connected to Arduino ground.
Leo..
Should I be going to the arduino as well as the 9v battery?

Wawa

Yes.
Just add a wire between sensor ground and Arduino ground.
Leo..

17asleep

Yes.
Just add a wire between sensor ground and Arduino ground.
Leo..
Thanks to you and everyone else who contributed. I now get a rock solid signal exactly the way I need it. Here's hoping I can learn from this project and be here to help others in the future.

Go Up