I have a situation like the one below schematic

The GearN is either GND or not connected. I don't have control over those states (it's a motorcycle gearbox sensor). When the pin is not connected I reach 7.5V on the MCP-A0 point (it's a MCP23017 GPIO expander pin). Way more than I want to. I would like it to be in a low state when that happens.

Just wanted to ask how can I go about it?

enter image description here

Is this solution better? My reasoning: current flows constantly (that part worries me a bit) so the MCP23017 sees high state on it's pin (the GearN is in unconnected state). When GearN connects to GND current will flow directly to it and whole 12V will drop on R1 which will make MCP23017 read low state.

Is it sound? Is there any better way to do this? I don't feel comfortable having 6 lines (that's how many gears there are) constantly draw current (even though it can be minimal).

  • \$\begingroup\$ Does your extender have a +5V supply? Or 3.3 V? Where the D1-R1 arrangement came from? \$\endgroup\$ May 10, 2018 at 19:56
  • \$\begingroup\$ And is there not a dashboard indicator lamp or LED in the circuit to show that you are in neutral? \$\endgroup\$
    – Transistor
    May 10, 2018 at 20:14
  • \$\begingroup\$ Is D1 meant to be a zener diode? \$\endgroup\$
    – Hearth
    May 10, 2018 at 20:44
  • \$\begingroup\$ Would it be possible to invert the MCP-A0 signal (high = open, low = GND)? \$\endgroup\$
    – CL.
    May 11, 2018 at 7:16
  • \$\begingroup\$ @AliChen - It's powered through 5V. The D1-R1 arrangement is something I made. It splits the voltage so I can get a safe 4.7V on the MCP pin. \$\endgroup\$
    – MrOneTwo
    May 11, 2018 at 8:34

1 Answer 1


Let's analyse your two circuits.

enter image description here

Figure 1. Not good.

  • When GearN is connected to GND then MCP-A0 will be 4.7 V above GND as determined by R1 and D1. So far so good.
  • When not in neutral GearN will be open circuit so MCP-A0 will be pulled to +12 V by R1. Not good. The GPIO may not survive.

enter image description here

Figure 2. A bit better.

  • When GearN is grounded then MCP-A0 will be grounded.
  • When GearN is allowed to float MCP-A0 will be pulled towards +12 V by R1 but will be clamped at 4.7 V by D1. This should be adequate to provide a high to 5 V logic.


simulate this circuit – Schematic created using CircuitLab

Figure 3. Pulling up to the microcontroller's supply.

Using the microcontroller's supply is better as there is no risk of over-voltage on the input. Adding a capacitor to any of the circuits will help filter out any noise on the wiring. If the micro has internal pull-ups then you can omit R1.

I'm trying to make my own motorcycle gauge. I want to read 12V digital signals.

If you have disconnected the original lamps then you are only checking for continuity to chassis / ground. (That's why I asked.)

I'm using Zeber [Zener] diode as a voltage regulator (on motorcycle this 12V fluctuates a lot) to get reliable 4.7V so the MCP27013 can safely read the state.


simulate this circuit

Figure 4. Opto-isolation.

You might consider opto-isolating your inputs. This solves any problems with spikes on the 12 V bus.

  • \$\begingroup\$ Thank you. For some reason I was stuck in the mindset that 12V needs to go through the gearbox sensor... but since (as you pointed out) it's just detecting continiuty it can be done with regulated 5V. I was thinking about opto-isolators but I had problem finding ones working with 12V - a that point I thought that's necessary. Also I don't find them efficient when it comes to their size/packaging. I bought some DIP16 and those are only 4 channels. Once again - thank you :) \$\endgroup\$
    – MrOneTwo
    May 11, 2018 at 20:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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