Using an Arduino and Mosfet to control a switch (grounding question)

Hi,

I’m trying to use a p-channel mosfet and an Arduino nano as a switch to control a motor.

I’ve copied the example on this page:

http://garagelab.com/profiles/blogs/tutorial-know-and-use-mosfets

I want to use 2 batteries, (1) for the Arduino and (2) for the motor.

A diagram of my breadboard layout is below.

My question is when I power the Arduino nano from a USB the circuit works ok and the motor can be turned on/off. However, when I power the nano with a battery and use the pins Vin and ground, the circuit doesn’t work.

I think the issues is in relation to the grounding.

Would somebody know what I’m doing wrong?

Thanks

Input Voltage (recommended) 7-12 V
Input Voltage (limits) 6-20 V

Does your battery meet these specifications (from the Arduino Nano web page Nano page)

Hi,

Yes, the battery meets the specifications, sorry I couldn't find a 9volt battery image.

Does the wiring look ok?

Thanks

I can't tell from the stupid fritzing diagrams. Can you please draw it out so it matches what you have, rather than what fritzing parts you happen to to be able to find?

What batteries do you have? are there two batteries or one? What voltages are the batteries?

Are batteries powering the motor when the Nano is powered by USB?

Hi,

Here is my exact layout (attached).

I want one battery to power the motor and the other to power the nano. The nano is in sleep mode most of the time but wakes up periodically makes D pin 4 high, then the motor uses some energy from its battery and then the D4 goes low and the nano goes back asleep.

Here is my code:

#include "LowPower.h"
#define GatePin 4 // Defines the pin to receive the signal in the Gate of the MOS

void setup () {
pinMode (GatePin, OUTPUT); 
  

}

void loop () { 

  digitalWrite(GatePin, LOW);
  delay(20000);
  LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
  digitalWrite(GatePin, LOW);
  delay(20000);
   
}

It works ok when the nano is powered by USB i.e. the motor stops turning. But when I power the nano by batteries the motor turns slowly when it is supposed to be off which makes me think it is getting some power?

Thanks

You're using a P-channel MOSFET, then?

But in order for the P-channel MOSFET to be off, the voltage on the gate must equal the voltage on the source (which is ~9v), yet an Arduino "High" is +5v.

Ergo, it will never turn off.

You need a pullup to 9v on the gate, and an NPN BJT or small N-channel MOSFET to bring the gate low (since you can't let the 9v touch the arduino). Or use an N-channel MOSFET and switch the low side, which doesn't require such considerations.

  digitalWrite(GatePin, LOW);
  delay(20000);
  LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
  digitalWrite(GatePin, LOW);
  delay(20000);

Why not drive the output pin High if you want the motor off? Outputs hold their commanded state in sleep mode, they don't go to a floating level.

If you switch on the high-side of the load and the load voltage is not 5V, you need to level
shift the control signal up to the supply voltage - you cannot simply switch with a single p-MOSFET.

If you switch on the low-side (n-channel) then there is no such problem, you will need a logic-level
n-MOSFET as the control voltage is only 5V, not the 10V that most MOSFETs require.

If you are switching an inductive load like a motor or relay you need to add a free-wheel diode to prevent
inductive voltage spikes destroying the circuit.

Hi all, thanks for your replies - using a n-mosfet is what I required, thanks for all the helpful suggestions.