Electronic – Add a passive hardware token using a 3.5mm jack

hot-pluginputpassive-componentsplugraspberry pi

I have a box that I made for my niece, which allows her to exchange voice messages with me. It is powered by a Raspberry Pi and features two buttons, a LED, a microphone and a speaker.

the box

Now, for Christmas I want my niece to be able to exchange these voice messages with various friends (4, 8 or 16) and relatives by plugging in a hardware token to the device, featuring a picture of that person.

I am now looking for the most simple way to add this functionality.

  • Preferably using a 3.5mm jack socket because they are readily available from used devices / headphones
  • Preferable a passive device (Capacitors + Resistors)
  • Preferably by attaching it directly to the Raspberry Pi
  • Preferably without using a AD-converter, since the Raspberry Pi does not have this built-in.
  • Easy to use by a 3-year-old

So using a 3.5 mm plug with 3 pins I could add attach power to one pin and either connect or disconnect the other two from that pin, which would leave me with two bits, resulting in 4 people (in addition to me as the default, if the socket provides a switch when a plug is inserted).

If I had an analog-digital converter I could add a voltage-divider to the three pins and use the voltage as an indicator. However, the Raspberry Pi does not have that built-in so I am looking for a smart way to achieve this using one of the GPIO pins.

relatives-plug

Best Answer

Use 1-wire bus and any 1-wire chip inside the button. I wrote "any", because each 1-wire chip has its own, unique hardware address, so all that you need on RPi side is checking that the chip was detected, for example using bash command:

ls /sys/bus/w1/devices/

and checking it's output for existence of subdirectory named exactly as this hardware address.

On RPi HW side you need only connect additional jack socket to proper I/O pins (GND + DATA). There is no need to use any power connection here, so it looks to be safest for RPi than similar solution, which uses I2C (I2C needs to have dedicated power line, what makes risk of damage RPi in case of short-circuit).

EDIT: For reliable work you should add the pull-up resistor 4.7kOhm between DATA line and Vcc (3.3V).

You can use most popular and cheap DS18B20 chip, which additionaly provides possibility to measure the room temperature ;), or DS2401, which additionaly provides unique serial number.