Switch a lot of external I/O's with Arduino

Hi, this is my first post on this form. I hope I didn't miss any rules or anything, if so: please let me know :slight_smile: .

My problem:
I have a couple of devices each using a I/O port which is basically a RJ12 connector (6pins), 1 pin is ground and the remaining pins are all 3.3V . Currently I am using a mechanical switch between each V and ground. When a button is pressed an action on the device happens.

I want to replace this with Arduino to bring in some logic. At the moment I'm doing this on a Arduino Nano.
I don't want to use relay's because that sounds like a bit overkill? I was looking into NPN transistors but run into some problems here. My wiring is as followed:
picture attached: pcd_01.png


So when I bring D2 HIGH I expect 3.3 going to ground.

I'm pretty sure this is not correct :slight_smile: ...please be gentle on me :stuck_out_tongue:

My questions:

  1. Is an NPN the correct choice here?
  2. Since there are 3 devices with each 5 I/O's (15 in total) I will run out of digital output on my Arduino. Is there a solution for this? (I dunno: an IC with a lot of outputs for example?)

  1. No, the base of a transistor needs a resistor. A NPN transistor is probably correct.
  2. No, you will not run out. Yes, there are many solutions to add more outputs.

You make "a couple of devices" sound very mysterious !
What kind of alien devices are they ? Do they all have separate power supplies, or long cables or heavy equipment ?

You want to connect the Arduino GND to the ground of those mysterious pieces of extraterrestrial hardware. I don't like that. It is better to use optocouplers for that (even miniature reed relays are possible).
A optocoupler has a led on one side and a opto-transistor on the other side. Use a resistor for the led and control it with an Arduino. The opto-transistor replaces the button.

The analog pins A6 and A7 are analog input only. The analog pins A0...A5 are both analog and digital. Is that enough ?

Thank you so much for your reply Koepel.

The arduino will need to control 3 devices (all having 5 I/O's and a ground.)

I work for a company making some kind of digital video receivers (4K over Ethernet/Fiber), the IO's are used to trigger actions on the video (f.e. rotate the view, change color, change output etc). Each device will have it's own power supply, yes. Each device is baiscally connected to it's own screen and I want to make this 'controller' for testing purposes.

Opto's: do you mean I can hook the "photo transistor" part of the Opto between 3.3v and GND of the device? (and control the 'led' part of the opto with the Arduino)

ps: your answer to my first question confuses me: you first say an NPN is not the correct choice and then say an NPN transistor? :stuck_out_tongue: (or did you mean PNP?)

thanks a lot! :slight_smile:

I had a look into the 'mini reed relay' and ordered them....they seem appropriate for this project.

Thanks for the hint!! :slight_smile:

A NPN transistor should be okay. The output of a optocoupler is often also a NPN transistor.
The led of the optocoupler takes 5mA to 20mA. There are also optocouplers that need only 1mA. That will reduce the currents in the Arduino Nano. If you plan to connect more devices or add a few leds to your Nano, then use those low-current optocouplers. The output (the transistor) can pull the 3.3V signal low without extra electronics.

Schematic: https://forum.arduino.cc/index.php?topic=488076.msg3330558#msg3330558.

I only mentioned the miniature reed relays to tell about the options you have :grin: Not something to take too serious. They are often 500 Ω. That means they draw 10mA per relay. 15 * 10mA = 150mA. It is possible, since the total current of the microcontroller can be 200mA. There will be a reverse current when the relay was actived and the Arduino is turned off. You could add a small 1N4148 diode over the relay.

The schematic you have is basically an open collector. The pin is either connected to GND or left floating, it is never connected to 3.3V. If that's what the connected device expects, it'll be fine, but the device may expect its inputs to be driven high/low. In that case you will have to connect the output to either 3.3V or GND.

Based on your schematic, you could add a pull-up (10k will likely be fine) between the collector of Q1 and the 3.3V output of the Arduino. Now the pin is pulled to 3.3V when the Arduino signal is low, and driven to GND when the Arduino signal is high (mind the signal reversing when programming).

Thanks for the input guys!

Just did a successful test with an opto I had laying arround. I will order extra Opto's

(I will order to low current once you suggested, Koepel, but since only 1 button can be pressed at a time I guess it will never draw a lot of current :slight_smile: )

str1p3z:
since only 1 button can be pressed at a time I guess it will never draw a lot of current :slight_smile:

That makes a big difference. Then any common optocoupler will be okay.

Can you measure the current that is required to pull such a signal low ? Then the resistor for the led of the optocoupler can be calculated. The datasheet of a optocoupler is full of numbers and graphs :stuck_out_tongue: Start a value of 470 Ω or 1k.

One of the numbers is the "transfer ratio". Suppose the transfer ratio is 50% and you need 2mA to pull that signal low. Then you can feed 4mA into the led and the opto-transistor can sink 2mA.

I'll try to measure the current later.

A.t.m. I'm using a 190ohm resistor on a PC817 opto (to protect the led of the OPTO). If the led is "off" the signal is pulled low, right? So does it make a difference to use a higher value resistor for the OPTO LED?

(sorry for my 'n00b' questions, I realy want to understand how everything is working... :slight_smile: )

str1p3z:
A.t.m. I'm using a 190ohm resistor on a PC817 opto (to protect the led of the OPTO). If the led is "off" the signal is pulled low, right? So does it make a difference to use a higher value resistor for the OPTO LED?

Depends on how your circuit is wired.

When the LED is off, the output side of the opto is also off and will not let current pass. In most situations 1-2 mA through the opto's LED is enough - this depends largely on the current the output has to be able to pass through when on.

I don't see anywhere how much current your switches need to pass. But if I were doing this I'd be thinking JFETs, something like a 2N7000. No base resistor is needed and the gate draws essentially no current. Or, if you're just switching signal levels, you might check into a multiplexer such as a CD4051. That will allow you to switch up to 8 pins using a 3-bit address from the uP (but only one at a time). Much depends on your specific needs and what is being switched.

Steve

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.