Electronic – arduino – How to differentiate between multiple different connections connecting to a common socket

arduinodigital-logic

I'm working on a project that involves 9 female connections on the top of a box, and 4 male connections coming from the front of the box. The requirements of the project involves connecting these male connections to the female connections, however I need to be able to differentiate between these male connections. How do i differentiate between them?

I'm using an arduino as the "brains" of the project. My initial plan was to use 2 4051 multiplexers to extend the number of analog pins on an Arduino Uno to 9, and then use different signal strength on the male connectors to differentiate between them. Through talking to some colleagues, I've also thought of using logic gates.

I'm a novice when it comes to electronics, I apologize in advance if this question is confusing. I've attached an illustration to try to clarify things.

Diagram of project

Best Answer

Connect each of the male connections to an output GPIO pin. Connect each female to an input GPIO pin.

In a loop, cycle through each of the outputs, turning one on (high) at a time. While each output is high, check all the inputs to see which, if any, is high.

If you don't have enough GPIO pins (13 total), there are various options. The easiest is to use a multiplexer on the input pins (reduces 9 inputs to 1 input and 4 outputs). You can also use a one-hot decoder on the output pins (reduces 4 outputs to 2 outputs). As a last resort, you can consider an IO expander chip (replaces all 13 pins with a serial bus, such as I2C or SPI).