I'm trying to operate a classic ultrasonic sensor breakout board on my Arduino. I'm aiming for some ultra low power consumption and I have been trying to switch the ultra sonic sensor board via NPN transistor low-side switch. However because the ultra sonic sensor trig Pin is an output set to LOW when not measuring, the breakout board find itself a ground without being switched by the NPN. Any idea how to tackle this ? I was thinking to use a PNP high-side switch circuit, would this be the solution ? Or is there any thing in software side to avoid the trig pin to ground when not in use ?

const int trigPin = D6;
const int echoPin = D7;
const int enPin = DXX;

void setup() {
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

void loop() {

enter image description here

Thank you!

  • \$\begingroup\$ I believe Trigger pin is an input pin. \$\endgroup\$
    – Long Pham
    Commented May 18, 2018 at 14:32
  • \$\begingroup\$ trigger pin sends out the trigger, therefore in an output. But that's not my problem here. The ultrasonic sensor works perfectly fine. \$\endgroup\$
    – Waz
    Commented May 18, 2018 at 14:35
  • 2
    \$\begingroup\$ @Waz if you provide a schematic then it will stop the confusion. Long Pham probably it as you were talking about the trigger pin on the module, which is an input. By your comment on his answer shows you were referring to the output on your arduino. Providing schematics is a huge help when trying to get help with your circuits \$\endgroup\$
    – MCG
    Commented May 18, 2018 at 14:58
  • \$\begingroup\$ @MCG noted & edited \$\endgroup\$
    – Waz
    Commented May 18, 2018 at 15:05

2 Answers 2


You could configure the trigger pin as INPUT when it is not being used as OUTPUT (i.e. not taking measurements) and disabling the pull-up resistor. This gives the pin a state of high-impedance, and your grounding issue would be solved.

  • \$\begingroup\$ Thank you, I will try this now. I have already tried to leave the pin as HIGH when not use to avoid grounding. It did work but I'm still getting 0.06mA of current leakage somewhere ... \$\endgroup\$
    – Waz
    Commented May 18, 2018 at 14:53
  • \$\begingroup\$ Yes! Can confirm it did work and I'm now getting 0mA current when off state. Thank you for the quick tip. However, would this be the more elegant solution? It feels like a "hack" and I would like to know wether PNP high side switch wouldn't be a better option. What is your opinion ? \$\endgroup\$
    – Waz
    Commented May 18, 2018 at 14:57
  • \$\begingroup\$ I don't believe it to be a "hack". If it works and does not give you any issues, then it is a good solution. If you observe any negative consequence then you should consider an alternative. \$\endgroup\$ Commented May 18, 2018 at 19:31

According to this datasheet and as its name implies, Trigger pin is an input pin. And it reccommends that :

The module is not suggested to connect directly to electric, if connected electric, the GND terminal should be connected the module first, otherwise, it will affect the normal work of the module.

It is even worse : when the power is switched off, the circuit ends up being tied to its power supply “+” side, but disconnected from ground – this can cause all sorts of nasty problems when electricity finding its way through other connected pins. This mean that it's not adviced to use low-side switch.

I suggest using a cheapo mosfet as high-side switch as it is far more efficient than BJT.

A small note : to minimize power consumption, a microcontroller pin, while not in-use, should be config as an input pin.

  • \$\begingroup\$ input in breakout datasheet yes but it means output pin on MCU side \$\endgroup\$
    – Waz
    Commented May 18, 2018 at 14:51
  • \$\begingroup\$ It's much clearer now. I've edited. \$\endgroup\$
    – Long Pham
    Commented May 18, 2018 at 14:59
  • \$\begingroup\$ I'm using a deep sleep function via RTC on the MCU side. So the low power is all tackled and fine. If I can get the Ultrasonic sensor to properly switch off while not in use. \$\endgroup\$
    – Waz
    Commented May 18, 2018 at 15:09
  • \$\begingroup\$ What is you opinion on the answer above vs. your solution ? I there any advantages using high side switch instead of low side switch + pinMode(INPUT) by default \$\endgroup\$
    – Waz
    Commented May 18, 2018 at 15:10
  • \$\begingroup\$ Advantage: maintaining common ground. The rest are disadvantages. \$\endgroup\$
    – Long Pham
    Commented May 18, 2018 at 15:15

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.