Electronic – Sensor to distinguish between different types of pegs on a pegboard

sensor

I have a project that is essentially a pegboard with 4 different types of pegs. Each peg fits into every hole, but when one is inserted, I'd like to digitally record its type and position. There are a total of 120 pegs, 30 of each type. The board itself is a square grid, with at most 40mm between holes. The size and design of the pegs and holes hasn't been decided yet.

The simplest and cheapest idea I could come up with was a switch at the bottom of every hole and a separate input method to declare the type: eg. 4 buttons somewhere on the side, which you could push afterwards to tell the system that type A was just inserted. This has a large effect on the user interface, one I'd like to avoid.

I could design the hole to be asymmetrical, wire 4 switches to the bottom and have each peg have 4 prongs with one being longer than the others. That would mean soldering a lot of very tiny things together and a more delicate final product, though.

Cost is also an issue, as it's a hobby project.

Is there some sort of sensor I could use for this?

Edited to add: I should have probably said this to start off with, but I tried to slightly generalize the question to maybe make it more useful: the project is a board game. The idea is to have up to 4 players capture territory on a board and have the board itself handle all the necessary bookkeeping in real time.

Best Answer

Use a multi-pole jack plug.

enter image description here

Figure 1. Random 4-pole, 3.5 mm jack plugs from Wish.com.

schematic

simulate this circuit – Schematic created using CircuitLab

Figure 2. Plugs can be encoded by shorting out the tip, ring 1, ring 2 to sleeve pins in a binary code pattern.

You can't use code 0 as this will be the same as no plug inserted. That leaves you with seven possibilities and you only need four. Colour-coding the plugs to indicate their numerical value seems a good idea to me.

schematic

simulate this circuit

Figure 3. Preventing cross-feeds. 1N4148 diodes should be small enough to fit two into a plug.

As pointed out by @A.I.Breveleri the addition of diodes in the plug allows the use of a keyboard scanning solution. In this type of arrangement the diodes prevent cross-feeds when multiple keys are pressed. The same arrangement would work here.

enter image description here

Figure 4. Keyboard matrix example. Image source: Gammon.com.

See the linked article for an explanation.