I am trying to create controller for my car head unit as it lacks a volume knob amongst other things.

I have worked out that when tapping onto the control pin I can "send" commands by applying a resistor of specific value between two pins:

  • 1000Ω = Volume up
  • 3300Ω = Volume down

I can achieve this using a button or switch method simply by putting the resistors on those items however I would like to create a volume "knob".

Is a rotary encoder the thing I will need here? Could somebody provide a little more direction on how to achieve the above functionality? As it will need to change the resistance each click yet reset it before the next click, it will also need to continue to spin rather than reach a limit.

Picture (may help) wiring

Thanks again

  • \$\begingroup\$ Not too difficult with a micro-controller and a programmable resistor or an analog switch with fixed resistors. Without a micro-controller? You must be kidding. \$\endgroup\$ – Wouter van Ooijen Jun 25 '18 at 6:14
  • \$\begingroup\$ could use a few gates and flip-flops instead of a microcontroller. \$\endgroup\$ – Jasen Jun 25 '18 at 7:18
  • \$\begingroup\$ It is certainly possible with two mosfets, a D flip-flop and a few resistors. I could provide a complete circuit but for it to be really applicable to your specific case, I need to know if one of the input pins (21 or 23) is tied to ground to ground (or to the supply), or if they are both floating. Can you check this using a continuity tester? Also, how will the circuit be powered? Which supplies are available? \$\endgroup\$ – dim lost faith in SE Jun 25 '18 at 8:08
  • \$\begingroup\$ It's kind of interesting actually to consider how one might make a mechanical device to do this. Something where turning the device closes a momentary switch in one of two directions, just a spring-loaded contact deflected either direction by teeth connected to the knob... Of course, it doesn't really matter if it can be done so much as whether you can actually buy this, because I doubt you want to build your own rotary switch thing. \$\endgroup\$ – Hearth Jun 25 '18 at 13:33
  • \$\begingroup\$ Thanks for the information guys, sounds like a mechanical device might not be the approach here. @dim the pin 23 is the common wire and goes back into the unit which provides ground. I have a spare pro micro that I was given at a an event, however not too sure what the approach would be to achieve the above. How can I go about learning, or creating an MVP? \$\endgroup\$ – user857359 Jun 26 '18 at 0:37

It is possible with an incremental encoder, a D flip-flop, two mosfets and a few passives.

An incremental encoder will give you pulses for each "click". There are two out-of-phase pulse outputs, so that you can guess the direction in which the encoder is turned:

enter image description here

(the "D" dashed line is when the detent happen on the knob)

You see that when the knob is turned clockwise, the rising edge of the B signal will happen while the A signal is high. When turning couter-clockwise, the rising edge of the B signal will happen while the A signal is low (read the above timing diagram respectively from right to left or from left to right). This is the principle.

Therefore, using a simple D flip-flop, you can register the direction is which the knob is turned. Wiring one of the encoder output to the D input, and the other to the CLK input, the flip-flop will have its output kept at 1 if the knob is turned clockwise, and 0 if it was turned counter-clockwise. You can also use the CLK pulses to trigger the required action for each click.

As we now have a signal indicating the direction and a signal indicating the click action, it is just a matter of correctly triggering a combination of resistors and fets to connect the appropriate resistors. Basically, when a click occurs, a 3.3k resistor must be connected between your two pins, and, if the direction was clockwise, we add a 1.5k resistor in parallel so the total equivalent resistance is roughly 1k, as per the spec.

Here is a basic schematic (assuming pin 23 is a common ground, that a 3.3V to 5V supply is available, and that pin 21 is not below the ground potential):


simulate this circuit – Schematic created using CircuitLab

You need R1 and R2 to pull down the encoder output signals. Also, even if it is not shown, you'll need some decoupling capacitor across the D flip-flop supplies (100nF is typically fine)

The choice of the D flip-flop is up to you. 74LVC1G79 is a perfect fit, but it is tiny (hard to solder by hand, and inappropriate for a breadboard). You could use a 74HC74, CD4013, etc... Be sure to read the datasheet and appropriately connect the unused inputs (set/reset) to the inactive level. Also check that your available supply is within the recommended supply voltage range of the component you choose.

  • \$\begingroup\$ This is amazing, I am not sure if I mark it as the solution or not given I do not have the experience to re-create this in person (yet). \$\endgroup\$ – user857359 Jun 29 '18 at 0:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.