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!
Best Answer
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.