Arduino acting as a resistance based keyboard

Hello everyone :slight_smile:

I'm trying to integrate an Android head unit with my car, I want to be able to control volume etc. using factory installed steering wheel buttons. Some info:

Car steering wheel buttons use LINBUS, I already hooked up an arduino with MCP2004 and I'm able to read which button has been pressed and act on it.

Sidenote - the head unit does have USB but a USB keyboard with volume media keys cannot control volume (tried it with Arduino Pro Micro), it has to do with a separate built in amplifier and MCU controlling it.

Head unit does have a GND, KEY1 and KEY2 wires which are analog based, basically there is 5V between GND and KEY1 and 5V between GND and KEY2, if I connect KEY1 to GND through resistor it can detect different voltage. So I can map a 10 Ohm resistor to be volume up and 20 Ohm resistor be volume down.

I'm looking for a way to send different resistance or voltage itself to the head unit from an arduino. So far my idea was to use a digital potentiometer but those can be quite inaccurate also poteniometers dont change resistance instantly from one value to another, meaning if I want to go from 1 Ohm to 20 Ohm I have to get through 10 Ohm and possibly get some false positive button presses.

I'm also contemplating using relay/s with the digital pot or simple resistors, but maybe there is an even better way?

Yes, just use Arduino outputs and resistors, I would think.

Lets say you want to simulate 10R or 20R between KEY1 and ground. You would connect KEY1 to an Arduino output, e.g. Pin2, with a 10R. You would connect a second Arduino pin, say Pin3 to KEY1 with 20R.

Initially, both Arduino pins will be in INPUT mode and KEY1 will be at 5V. Make Pin2 OUTPUT and LOW and the unit will read that as Vol Down. Return Pin2 to INPUT and set Pin3 to OUTPUT and LOW and the unit will read Vol Up.

Make sure your code does not set both Pin2 and Pin3 to OUTPUT where one is HIGH and the other is LOW, because with only 30R resistance between them, a large, damaging current could flow. Always return the pins to INPUT mode before making one of them OUTPUT.

Of course, the head unit and the Arduino must share a common ground for this to work.

Thats interesting, so basically I should be able to use the pins themselves as relays of sort with no need for extra hardware? Are there any resistor values that might be safer than 10-20 Ohm?

An Arduino digital pin is, in effect, a switch. It can connect to 5V (OUTPUT/HIGH) or 0V (OUTPUT/LOW) or neither (INPUT).

Thinking more about it, you need to check something before you use this technique. With the 10R resistor connected between KEY1 and ground, measure the current flowing there. If it's more than around 30mA, you will need to modify the circuit a little, using basic npn transistors or perhaps a ULN2003 chip.