[SOLVED]Using a MOSFET as a switch for sensors.

Hi,

I am building a low power application and want to switch a sensor or two off before I put an Arduino to sleep and switch the sensor back on after the Arduino has woken up.

I read that it is possible using for example a logic level MOSFET such as IRL520N, and thought to give it a try.

My sensor that I want to control is a Sonar Sensor

I built a circuit to test with using an Arduino Nano for example, and using the 5V as the source for the sensor.

The issue I am experiencing is that the sensors voltage between 5V and GND never drops to Zero. I can see the sensor voltage dropping between the times I apply voltage to the GATE but it never drops below +- 3.7V even if I remove the GND connector between DRAIN and the Sensors GND.

If I remove the TX and RX connections then the voltage drops to 0.9V which is similar to the voltage between GATE and DRAIN if the voltage to the GATE is removed.

I obviously have some feedback going on in this circuit and would like some advice. Can I maybe solve this by strategically placing diodes and resistors in some places?

Am I running up the wrong tree using MOSFETS?

My test circuit looks like the first attachment: CircuitTEST.jpg

While my final design will look something like the second attachment: Circuit.jpg

Code I am using:

#include <SoftwareSerial.h>

#define ECHOPIN 12// Pin to receive echo pulse
#define TRIGPIN 11// Pin to send trigger pulse
#define GATE 5

void setup() {

  Serial.begin(9600);
  pinMode(ECHOPIN, INPUT);
  pinMode(TRIGPIN, OUTPUT);
  digitalWrite(ECHOPIN, HIGH);

  pinMode(GATE, OUTPUT);
  digitalWrite(GATE, LOW);
}

int getDistance() {

  digitalWrite(GATE, HIGH);
  digitalWrite(ECHOPIN, HIGH);

  delay(3000);
  
  digitalWrite(TRIGPIN, LOW); 

  delayMicroseconds(2);

  digitalWrite(TRIGPIN, HIGH); 

  delayMicroseconds(10);

  digitalWrite(TRIGPIN, LOW); 

  int distance = pulseIn(ECHOPIN, HIGH,26000); 

  distance= distance/58;

  Serial.print("distance: ");
  Serial.println(distance);

  digitalWrite(ECHOPIN, LOW);
  digitalWrite(GATE, LOW);

  delay(6000);

  return distance;

}


void loop() {

 int distance = getDistance(); 
}

I know the circuit works because I tested with an LED and it works fine, but this sensor has its own breakout board and additional connections to other Arduino digital pins which makes it a bit more complicated.

Try making the trigger pin into an input before putting the Arduino to sleep to prevent parasitical powering the sensor.

If your sensor draws just a few mA of power you can consider powering it through an Arduino pin as well.

Thanks Grumpy_Mike, that worked just fine.

I will test the circuit tomorrow using the 3.3V circuit with step up, just need to get an FTDI programming cable.