# Grounding issue ultrasonic sensor

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);
pinMode(enPin,OUTPUT);
digitalWrite(enPin,LOW);
}

void loop() {
digitalWrite(enPin,HIGH);
getDistance();
digitalWrite(enPin,LOW);
}


Thank you!

• I believe Trigger pin is an input pin. – Long Pham May 18 '18 at 14:32
• trigger pin sends out the trigger, therefore in an output. But that's not my problem here. The ultrasonic sensor works perfectly fine. – Waz May 18 '18 at 14:35
• @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 – MCG May 18 '18 at 14:58
• @MCG noted & edited – Waz May 18 '18 at 15:05

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.

• 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 ... – Waz May 18 '18 at 14:53
• 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 ? – Waz May 18 '18 at 14:57
• 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. – Vicente Cunha May 18 '18 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.

• input in breakout datasheet yes but it means output pin on MCU side – Waz May 18 '18 at 14:51
• It's much clearer now. I've edited. – Long Pham May 18 '18 at 14:59
• 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. – Waz May 18 '18 at 15:09
• 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 – Waz May 18 '18 at 15:10
• Advantage: maintaining common ground. The rest are disadvantages. – Long Pham May 18 '18 at 15:15