5
\$\begingroup\$

I am building an AVR-based diagnostic device for my old Mitsubishi car.

To perform diagnostics you must short pin 1 (diag) with pin 4 (ground) on the car diagnostics connector to start a session; no problem with a paper clip.

But do I do this with a transistor controlled by an AVR output pin?

A pseudo circuit:

schematic

simulate this circuit – Schematic created using CircuitLab

\$\endgroup\$
4
  • 5
    \$\begingroup\$ Just add a series resistor between the transistor base and AVR pin. Between 1K-5K should do it. \$\endgroup\$
    – DKNguyen
    Commented Dec 1, 2021 at 15:22
  • 1
    \$\begingroup\$ This will probably work but you have to limit the current into the base of that NPN. So add a resistor (any value between 1 k ohm and 10 kohm will do) between the base of the NPN and the AVR output. \$\endgroup\$ Commented Dec 1, 2021 at 15:23
  • \$\begingroup\$ As others said, add a 10k resistor in series with the base of Q1 \$\endgroup\$
    – 65Roadster
    Commented Dec 1, 2021 at 15:34
  • 2
    \$\begingroup\$ Also, recommend a 47K pull-down on I/O pin (not gate/base) for after power-up, while MCU is in reset and I/O pin is still configured as an input, until software sets it as output. \$\endgroup\$
    – TonyM
    Commented Dec 1, 2021 at 16:12

2 Answers 2

12
\$\begingroup\$

I recommend that you use an N-Channel MOSFET instead, with a logic level gate threshold.

schematic

simulate this circuit – Schematic created using CircuitLab

But, if you wish to use an NPN BJT, as you show, then add a 1 kOhm resistor between the AVR and the base of the transistor.

schematic

simulate this circuit

\$\endgroup\$
3
  • 3
    \$\begingroup\$ *logic level NMOS. This is where a BJT might win out because all BJTs will work here but most NMOS won't. \$\endgroup\$
    – DKNguyen
    Commented Dec 1, 2021 at 15:38
  • \$\begingroup\$ Edited, thank you. \$\endgroup\$ Commented Dec 1, 2021 at 15:39
  • 5
    \$\begingroup\$ You really should add a MOSFET series resistor for gate capacitance, suggest 1K. This stops any load transients being coupled back to the MCU. Also limits peak charge/discharge current through I/O pin when switched. Also, recommend a 47K pull-down on I/O pin (not gate/base) for after power-up, while MCU is in reset and I/O pin is still configured as an input, until software sets it as output. \$\endgroup\$
    – TonyM
    Commented Dec 1, 2021 at 16:12
13
\$\begingroup\$

I am building AVR based diagnostic device for my old Mitsubishi car

I'm going to recommend a photo-MOSFET and some may say that this is over the top but, automotive jobs can be prone to problems of earthing (mainly avoiding multiple earths and thus avoiding unholy currents passing down wires that are not expecting unholy currents). So, I recommend a photo-MOSFET like this device: -

enter image description here

It's basically an optical replacement for a standard mechanical relay and has an on resistance of 2 Ω, an open circuit maximum voltage of 200 volts (will not be bothered by automotive load dumps) and, can conduct 0.7 amps. It's also bidirectional on the output so, if you get it back to front, it will still work: -

enter image description here

It only needs 3 mA input current to activate this device too but, of course you'll need a series resistor from your IO line.

It also costs virtually nothing in Mouser for your peace of mind: -

enter image description here

And they have plenty in stock with plenty of alternatives.

Of course, if you are willing to have your AVR connected to automotive ground in multiple places then be prepared for tears and anguish. Isolation is an excellent way to overcome most automotive sins.

But do I do this with a transistor controlled by an AVR output pin?

Yes you can but, do it with a MOSFET and use optical isolation methods (as per the above) to avoid multiple connections to automotive ground.

\$\endgroup\$
14
  • 1
    \$\begingroup\$ @jay - he needs to be careful about that of course and, I'd definitely be considering using an isolated dc converter to avoid that through-going power connection to the AVR. But, that's another question as I see it. You can take a horse to water etc.. \$\endgroup\$
    – Andy aka
    Commented Dec 1, 2021 at 16:49
  • 2
    \$\begingroup\$ @user2120666 so your are perfectly content unrelated automotive ground currents won't flow from the grounding point you have close to the transistor in your question (on the diagnostic connector) via the AVR and back to ground at the other car ground? And, if you haven't got a local ground point back to the AVR for your gate/base drive signal, how can you be sure you won't get serious glitches between the two ground on your vehicle that might be turning on and off the transistor every 10 seconds or more when the engine is running.... \$\endgroup\$
    – Andy aka
    Commented Dec 1, 2021 at 20:08
  • 1
    \$\begingroup\$ ... Even worse, within a a short period of time, the ground bounce problems (that occur on any vehicle) might destroy the transistor or even your AVR. Have you ever heard of star-pointed wiring as a means of overcoming these issues. If not, good luck; I've tried my best to advise you but sometimes it takes real problems for disbelief to turn into acknowledgement. \$\endgroup\$
    – Andy aka
    Commented Dec 1, 2021 at 20:10
  • 2
    \$\begingroup\$ The very best of luck. \$\endgroup\$
    – Andy aka
    Commented Dec 2, 2021 at 8:02
  • 2
    \$\begingroup\$ @user2120666 What is called "ground" on a car is not the same voltage everywhere - when things like windscreen wipers or a heated screen, or anything else really, are switched on, there will be a difference in the ground between any two places. Those two places could be the ground connection of the transistor and the ground connection of the AVR, and the difference could easily be enough to break them. So you need to either isolate the transistor or make sure to use only one ground wire to the car for both the transistor and the AVR. \$\endgroup\$ Commented Dec 2, 2021 at 14:57

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.