Hello,
I am working in an industrial environment that uses an encoder mounted to a conveyor shaft. I would like to get a pulse count from the encoder via an Arduino Uno. The encoder is incremental with one output (NPN open collector), powered by 24V (8-30VDC capable). The encoder output signal is currently connected to an industrial camera relaying belt speed information to a computer application, as well as a PLC. Since arduino uses 5V I am using two of these switching regulators, one for the 24V to power the arduino and the other to drop the 24V pulses to 5V before they go into the arduino input. I am essentially trying to tap into the pulse signal already being fed into the above devices.
I can power the arduino just fine with the regulator from 24V but as soon as I connect the encoder output signal to the input of the other regulator (to generate a 5V pulse) I cannot get a pulse to the arduino and the other two systems (camera and PLC) sharing the same encoder output lose belt speed. I believe the signal goes constant. So basically I am giving power and the output signal of the encoder to the arduino through these two regulators.
My research tells me that because its an open collector output, I need a pull-up resistor somewhere, probably before the regulator on the pulse signal. I'm just wondering how big it should be and how it would affect the other two systems sharing the same output signal. If they already have one, why does the signal cut out? Also, is there anything I can do that will definitely fry a component (I'd rather not make an ass of myself at work).
If anyone knows whats going on here and can offer a solution I would greatly appreciate it.
Thanks!
Wiring Diagram
can you show us a circuit?
have you tried attaching the 24v pulse to the arduino via an opto isolator
have you looked at the signals using an oscilloscope?
For an open collector output, all you really need is two wires. One to connect the grounds, the other to connect the output with an Arduino pin. Then enable the built-in pull-up resistor on the pin (so yes, your research is correct - but you don't need to add an extra part as it's built into the Arduino already) and you're set. That's the beauty of such outputs.
This kind of output only ever pulls low the output (i.e. connects it to GND), otherwise it's left floating (which is where the pull-up comes into play).
If you want to be extra safe, add a diode pointing away from the Arduino. This prevents any higher voltages from reaching the Arduino pin, just in case there's something wired wrong or another connection to the same output pulls it to a higher voltage.
For an open collector output, all you really need is two wires. One to connect the grounds, the other to connect the output with an Arduino pin. Then enable the built-in pull-up resistor on the pin (so yes, your research is correct - but you don't need to add an extra part as it's built into the Arduino already) and you're set. That's the beauty of such outputs.
This kind of output only ever pulls low the output (i.e. connects it to GND), otherwise it's left floating (which is where the pull-up comes into play).
Can an internal pull-up be used on an interrupt pin, which is what the pulse signal is connected to?. Also, is the built in resistor large enough to handle a 24V input (5v after the regulator)? And how is the output floating when it's connected to the two other devices, they should have pull-ups right.
Thanks for your help.
horace:
can you show us a circuit?
have you tried attaching the 24v pulse to the arduino via an opto isolator
have you looked at the signals using an oscilloscope?
horace:
can you show us a circuit?
have you tried attaching the 24v pulse to the arduino via an opto isolator
have you looked at the signals using an oscilloscope?
I've added a wiring diagram. I have not tried an opto isolator, not really sure what that is tbh. I don't have an oscilloscope available but I used the serial plotter on the arduino to look at the pulse and it appears to be a constant 5V if i'm using it correctly.
I used the serial plotter on the arduino to look at the pulse and it appears to be a constant 5V if i'm using it correctly.
I think that there must be an internal pullup to 24v inside the encoder. Therefore, the voltage on the wire going to the regulator will be 24v when there is no pulse, and then briefly GND when there is a pulse. You are probably not seeing the pulses through the regulator.
You could put the encoder output across a voltage divider to bring is down to 5v for the arduino.
OP's wiring diagram
cattledog:
I think that there must be an internal pullup to 24v inside the encoder. Therefore, the voltage on the wire going to the regulator will be 24v when there is no pulse, and then briefly GND when there is a pulse. You are probably not seeing the pulses through the regulator.
You could put the encoder output across a voltage divider to bring is down to 5v for the arduino.
OP's wiring diagram
Thanks for the reply,
I think the pull-up resistors are on the other two devices, not the encoder. As far as I can tell the output is a true open-collector. I think I will try a voltage divider.
A voltage divider may be influenced by the other resistors. Safer is a diode (pointing away from the Arduino) and using the internal pull-up. No chance for other components messing up the voltage at the pin, and it can still be drawn low.
You know the UNOs VIN pin needs at least 7V (7 to 12), don't you? And follow @wvmarle's advice on the pulse input.
RedBlu92:
I've added a wiring diagram. I have not tried an opto isolator, not really sure what that is tbh.
a optocoupler or opto isolator transfers electrical signals between two isolated circuits by using light.
If you do a web search for arduino optocoupler or arduino optoisolator you will get plenty of links using the devices for input and output
outsider:
You know the UNOs VIN pin needs at least 7V (7 to 12), don't you? And follow @wvmarle's advice on the pulse input.
I had not known this...I assumed the arduino operated on 5V.
wvmarle:
A voltage divider may be influenced by the other resistors. Safer is a diode (pointing away from the Arduino) and using the internal pull-up. No chance for other components messing up the voltage at the pin, and it can still be drawn low.
So the diode would drop 24V to 5V? Can you recommend a diode I can use for this?
Thank You
RedBlu92:
I had not known this...I assumed the arduino operated on 5V.
Vin goes through a regulator. That's why it can take higher voltages.
Vcc/5V/RAW (name varies) is where you can connect a regulated 5V supply.
RedBlu92:
So the diode would drop 24V to 5V? Can you recommend a diode I can use for this?
No. It stops any higher voltage from reaching the Arduino (do look up how a diode works!). Just about any regular diode will do, as long as the reverse voltage is >24V.
wvmarle:
Vin goes through a regulator. That's why it can take higher voltages.
Vcc/5V/RAW (name varies) is where you can connect a regulated 5V supply.
No. It stops any higher voltage from reaching the Arduino (do look up how a diode works!). Just about any regular diode will do, as long as the reverse voltage is >24V.
So what's the issue with giving the regulator 5V? The reason I ask is because I need the 5V pin to power another sensor.
Also I just re-read your replies. Are you saying I can directly connect the encoder output to the arduino if I activate the internal pull-up resistor, without dropping down the 24V to 5V? Won't that affect the other two systems connected to that pulse signal? Like if they have pull ups and the arduino also does, what voltage will it be pulled up to?
The minimum drop of about 1.3V for this regulator...
And what's stopping you to connect multiple wires to one power pin?
RedBlu92:
Also I just re-read your replies. Are you saying I can directly connect the encoder output to the arduino if I activate the internal pull-up resistor, without dropping down the 24V to 5V? Won't that affect the other two systems connected to that pulse signal? Like if they have pull ups and the arduino also does, what voltage will it be pulled up to?
Only if you add the diode, as otherwise you will mess up the other inputs (due to the clamping diodes on the Arduino's pins bringing the voltage down to 5.5V), the Arduino (the clamping diodes burning out due to too much current), or all of the above.
Your diagram shows 24 volts going to a regulator then a wire from the regulator to the Arduino VIN pin, if that regulator is outputting 5V then the Arduino will not get 5V from its regulator, it needs at least 6.5 volts on the VIN pin.
If you put a diode from pin 2 to the 24V signal wire with the diode cathode connected to the signal and the anode connected to pin2 and pin 2 internal pullup enabled, then pin 2 will see 5V when the signal is at 24V and 0V when the signal is at 0V, so pin 2 is following the HIGH / LOW pulses on the signal wire. Understand?
wvmarle:
The minimum drop of about 1.3V for this regulator...
And what's stopping you to connect multiple wires to one power pin?
I guess I don't really understand how the same pin can act as a supply for the arduino and a power source for a sensor at the same time. I am thinking of it as an output.
I followed Cattledogs advice and used a voltage divider, works well so far. It seems the line was already pulled up to 24V (showing as 12V DC on a multimeter) by a pull-up resistor in another component. Since it's a signal line and the arduino input is high impedance, I think it shouldn't be a problem.
Thank you for your input!
outsider:
Your diagram shows 24 volts going to a regulator then a wire from the regulator to the Arduino VIN pin, if that regulator is outputting 5V then the Arduino will not get 5V from its regulator, it needs at least 6.5 volts on the VIN pin.
That makes sense now, thanks.
outsider:
If you put a diode from pin 2 to the 24V signal wire with the diode cathode connected to the signal and the anode connected to pin2 and pin 2 internal pullup enabled, then pin 2 will see 5V when the signal is at 24V and 0V when the signal is at 0V, so pin 2 is following the HIGH / LOW pulses on the signal wire. Understand?
I actually used a voltage divider and it's working well(getting a pulse count and other devices don't get interference). Apparently the signal was already being pulled up to 24V so I dropped it to 5V. I understand the diode approach but do you think it's still the better choice knowing the signal is already pulled up to 24V?
I understand the diode approach but do you think it's still the better choice knowing the signal is already pulled up to 24V?
Yes.
What resistors did you use for your dividers? Because of the existing pullups, the divider network must take them into account. They were unknown, and the choice of your resistors is interactive with them. Once you tune it to 5v at the input you are OK, but getting there is somewhat of a trial and error with two unknown pullups.
The diode is also more efficient and no current is drawn when the signal is high. With the voltage divider the 24v is always going to ground and some current is flowing.
RedBlu92:
I guess I don't really understand how the same pin can act as a supply for the arduino and a power source for a sensor at the same time. I am thinking of it as an output.
If you use the Vin pin, the Arduino's regulator becomes the power supply, supplying power to the Arduino itself and able of delivering a small amount of current (100-200 mA) to something else.
If you connect a 5V power supply to the Vcc pin, it supplies power to the Arduino, while still able to also supply power to something else - up to whatever much the power supply can deliver.
The pin is not the power source, it's simply connected to a power source
It seems the line was already pulled up to 24V (showing as 12V DC on a multimeter) by a pull-up resistor in another component.
This is not right. Either your multimeter is faulty, or the line is pulled up to 12V instead of 24V, or your voltage divider pulls the whole thing down to 12V.
Since it's a signal line and the arduino input is high impedance, I think it shouldn't be a problem.
The total resistance of your voltage divider is now the actual input impedance, so if you choose those values too low, it can pull down the whole line. The input impedance of the pin itself is so high it can normally be neglected.