One suggestion is the following, using the smart pegboard below as an example illustration:
(1) "Load" the 4 types of peg with different weights, eg, Type 1 peg = 10 grams, Type 2 = 20 grams,
(2) Buy 102 cheapy weight sensors (US$5 for 5 pieces, see Appendix A below for more details),
(3) Put each sensor at the bottom of the hole, and connect it with a fixed value resistor to form a voltage divider.
(4) Now when a peg is inserted, the weight changes resistance of the weight sensor and therefore the voltage of the voltage divider,
(5) Arduino ADC pins can be used to measure the voltage and therefore know which type of peg is inserted.
(6) To determine the position of the peg, there are many method, as briefly described below:
(6.1) Matrix keypad with keys pressed or released
The common method is to use 12 x 12 GPIO pins wired as a matrix. As soon as a key is pressed, Arduino will be notified. Arduino will "scan" the keys row by row, and if the row with a key pressed, Arduino will then scan the keys.
(6.2) Matrix keypad with keys pressed with different pressure levels
The approach is similar to the digital on/off keypad above. But now the Arduino uses its ADC (Analog to Digital Conversion) pins to measure the pressure level of the keys.
(7) Combinations of matrix keypad and multiplexed ADC devices
Since Arduino or Raspberry do not have enough GPIO/ADC pins to go around, we can use 16 channel GPIO expanders. Two MCP23017 can make a 16 x 16 matrix and so can scan up to 256 keys.
Arduino's ADC pin is only 8 bit resolution. If using 10/12/16/24 bit resolution ADCs (evan a 10 bit ADC can detect 2^10 = 1024 values or 0.1%), it is easy to differentiate among pegs with as little as less than 1 gram difference. So if 120 pegs have unique weights differ by small quantity not noticeable by humans, Arduino can actually tell which one of the 120 holes/pegs is inserted (but of course in this case it is which hole, not which peg we need to know.
(8) Combination of ADC and Analog multiplexors.
Popular but cheap 10/12/16 bit ADCs such as MCP3008, MCP3208, ADS1115 has 8 channels. There are also unidirectional/bidirectional analog multiplexors to make the matrix wiring much simplified
References
(1) High Accuracy Resistive Weighing/Pressure Sensor - US$3.15 (5 pieces)
(2) A Futuristic Pegboard, Turns Boring Rehab Into a Game - Rapael,2018jan17
(3) Smart Pegboard Video - Rapael,2018jan17
(4) A peg board with 24 colorful cylinder pegs and removable inner pegs helps children with perceptual motor development and finger dexterity.
(5) Haljia 5Pcs BX120-3AA High Precision Resistance Strain Gage Strain Gauge GAGE Full Bridge Used for Pressure Weighing Sensor
(6) Adafruit TCS34725 RGB Sensor Demo - 2018mar25
(7) Adafruit Color Sensors
(8) AliExpress Hall Effect IC and Module Catalog (A3144E, SS49E etc)
(9) AliExpress Tiny Magnets Catalog
(10) SS49e Magnetoresistive Linear Hall Effect Sensor Datasheet - Honeywell
(11) Allegro A3144 Datasheet
(12) TCS230 TCS3200 Color recognition module Color sensor module - US$4.6
(13) MCP3008/MCP3208 10/12 bit ADC Testing and Programming - EESE, tlfong01
Appendices
Appendix A - Pressor Sensor Spec
HALJIA 5Pcs BX120-3AA High Precision Resistance Strain Gage Strain Gauge GAGE Full Bridge Used for Pressure Weighing Sensor
Price: £6.99 (£1.40 / Item)
Made of constantan foil, fully enclosed structure.
Temperature self-compensation and creep self-compensation can be realized simultaneously.
The strain gauge is attached to the measured object to make it expand with the strain of the measured object, so that the metal foil inside the strain gauge can extend or shorten with the strain.
The resistance of many metals changes when they are mechanically elongated or shortened. The strain gauge is used to measure the strain by measuring the change of resistance.
In general, the sensitive grid of strain gauge is made of copper-chromium alloy, whose resistance variation rate is constant and proportional to strain.
Specifications for this item
Brand Name HALJIA
Item Weight 5.00 grams
Feature:
Made of constantan foil, fully enclosed structure.
Temperature self-compensation and creep self-compensation can be realized simultaneously.
The strain gauge is attached to the measured object to make it expand with the strain of the measured object, so that the metal foil inside the strain gauge can extend or shorten with the strain.
The resistance of many metals changes when they are mechanically elongated or shortened. The strain gauge is used to measure the strain by measuring the change of resistance.
In general, the sensitive grid of strain gauge is made of copper-chromium alloy, whose resistance variation rate is constant and proportional to strain.
Resistance Value(Ω): 1002Ω ± 0.1
Sensitivity Coefficient: 2.0±1%
Base Dimension: 7.3mm x 4mm x 1mm
Wire Grid Dimension: 3*3.1mm
Room Temperature Strain Limit: 20000um/m
Room Temperature Insulation Resistance: 10000MΩ
Backing Material: Modified Phenolic
Appendix B - Hall Effect Sensors and Tiny Magnets Specification
(1) AliExpress Hall Effect IC and Module Catalog (A3144E, SS49E etc)
(2) AliExpress Tiny Magnets Catalog
Appendix C - Using MCP3008/MCP3201/MCP3208 ADC to measure weight sensor and magnetic sensor output
MCP3008/MCP3208 10/12 bit ADC Testing and Programming - EESE, tlfong01
Arduino's 8 bit ADC pins might not be accurate to do ADC. Rpi has no ADC pins. So either way you need to use ADC chips/modules.
For this project's weight and magnetic sensor, I think 10/12 bit resolution (< 0.1%) is more than enough. For newbies, I usually recommend MCP3008/MCP3208 which is very popular and you can find through hole chip to play with bread board.
You might like to read my answer linked above to get a rough idea of how the ADC works, and if you are OK with python, try my demo program, fully debugged, just copy, paste, and run, without need to use any libraries. Or you can search for drivers that fits your computer.