I am developing a program that will detect an IO state change on a GPIO pin from an industrial machine an Arduino is monitoring. The voltage from the industrial machine is considerably higher than can interface directly with the GPIO pins. It will be used on a number of different machines, and these machines send out a positive signal of different voltages: some send +5v, some up to +24v. The signals don't change with high frequency. I am hoping to have one solution that will work for all of those machines.
I was thinking that one way to handle this would be to use an NPN transistor, where the base is fed by the machine signal, and then the GPIO pin would be pulled to ground when the transistor is activated by the machine signal, so I can record the machine event. I'd have the emitter side connected to the GPIO pin (+3v) with pull up resistor and the collector side connected to ground.
I'm very new to this so wanted to see if this was a good way to do it? From what I am reading, it usually it seems transistors have a lower base voltage than emitter voltage; is using a higher base voltage than emitter voltage a bad idea?
The other approach I've seen recommended is a diode optocoupler. I think I'd use a resistor on the machine voltage / LED side of the optocoupler, and then just wire the pull up resistor on the Arduino side to the diode to ground, so it'd pull to ground when activated. Maybe this would be a better approach?
If you need to isolate the machine's electrical system from the Arduino then you need an opt-isolator. If you don't need the isolation then a potential divider will do the job. You could use, say, 10k Ohms as the bottom resistor and change the top resistor to suit the output voltage from the machine.
You don't need the transistor.
Similar questions appear here often, do some searching and some reading and you will probably find a solution that will do what you need.
Start with post # 2. Then go to post # 3.
If this is not enough, you can read on.
You definitely don't need a transistor. Moreover, the NPN transistor is not connected with the emitter to + Vcc, and the collector to the ground. Quite the opposite.
If you have an industrial machine where various interference is possible, use an optocoupler.
If interference is not a problem, use a voltage divider and a bypass capacitor at the controller input.
I would recommend that you use different resistor values for 5V and 24V signals anyway. This also applies to the opto-isolator and voltage divider.
If you are looking for a one solution fits all voltages then go with an opto isolator.
Pick a resistor value low enough to turn on the transistor, but high enough so that the maximum input voltage does not send too much current through the LED.
The only snag with these is the top frequency it will couple, is only about 300KHz or so depending on which one you have.
Thank you everyone - this is really helpful. Sounds like opto isolators might be best for this use case though I may try one with a voltage divider just to see how much noise there is. Mike - thank you for the notice on top frequency for the opto isolators, this signal is only occurring once every couple seconds so it sounds like it's a good choice for this application.
You won't see how much noise there is.
Just check if the industrial equipment is high current, or if there are long wires from the equipment to your Arduino board, it is better to use an optocoupler.
Hi,
If you are in an industrial situation, then please use industrial interfaces to isolate your system from the industrial process.
If it is digital the n google.
industrial digital isolation
Can you please tell us your electronics, programming, arduino, hardware experience?
What is the equipment and what signals are you going to read?
That is;
What voltage?
AC or DC?
Is it ON/OFF signals?
Are there signal that vary in level, 0-20mA, 4-20mA, 0-5V, 0-10V?
What will you be doing with the input data?
Display?
Control another device?
Log the data?
Agree that opto isolator is a great solution.
But let is not forget the humble relay. It might just be easier to use / wire up in the case of an industrial machine. Power the relay coil from the machine and connect the contacts to the arduino pi and GND (using INPUT_PULLUP).
If you select the correct relay, then you only need that relay. No opto chip, no resistors....
Where are you measuring? Between a wire and the machine frame or is there a separate ground wire for the signal?
What exactly is the "signal" and how long does it last?
Paul
Sorry gumpy_mike, that's a poor reading of the information available when I responded.
There is nothing in the OP's post that says the "industrial machine" is sending an electronic signal vulnerable to flyback. Quite the opposite. It looks like a power signal to me.
In fact, it may be that there is a 24v AC signal, and if you put a diode across that relay coil you can watch it (the diode) explode within about 10 milliseconds.
Regarding relay contact bounce, it is the simplest of coding issues to cope with a switch bounce. How about "delay(50);"
Re relay life span - there is nothing in the OP's post that says it will operate ever second. The comment says every couple of seconds. A quick read of a datasheet for a suitable relay typically indicates over 10 million operations: so an industrial machine which might operate the relay say every 5 seconds for 5 days a week over 8 hours a day should last a while. Probably over 6 years. There is also a tiny load (0.5mA perhaps) on the relay contacts, so maybe it will go even longer.
I accept that one relay model will not operate properly at both 5v and 24v, but the OP asked for a a "solution that would work for various voltages". A suitable relay will do that, rated at the correct voltage. It is unlikely that the machine will be sending out a random mix of voltages.
The relay option also has the benefit of keeping the (as the OP says) "considerably higher voltage" out of the arduino enclosure. Separating the arduino from the industrial machine is a good thing for all kinds of reasons, and the relay can be sited at the machine end of the link.
When I left school and got a job in electronics in the 60s, one of the first jobs I worked on was replacing the relay in a weaving machine with a solid state switch precisely because the relay only had a life of 6 about years. A failed relay sent the weft shuttle crashing into the machine and caused a bit of damage but a lot of down time on the machine.