Mosfet - not grounding the circuit

Hi,

I have this circuit:

http://www.hostingpics.net/viewer.php?id=726457Capture.jpg

AD1 is an Arduino logic output (I am using a analog pin as digital pin). When AD1 is ON (5V), I have 6V between Resistance 1 et 2, but when AD1 is OFF (0V), I have 3V between Resistance 1 et 2 (It is supposed to be 0V).

Can someone explain if I'm using the MOSFET in a wrong way?

Thanks in advance!

The circuit is correct, probably you have not wired yours like that. Ensure you have a common ground with the external supply and the Arduino. Then post a clear picture showing your wiring and say what type of FET you are using.

How about telling us what the mosfet is switching.

Well you're using the wrong MOSFET, the IRF540 is not logic level...

Well you’re using the wrong MOSFET, the IRF540 is not logic level…

What Mark is telling you is that without a mosfet driver to apply -12V to the gate of the mosfet it is not going to turn off. Read the datasheet.

THIS:

Can someone explain if I’m using the MOSFET in a wrong way?

Answer: (as already stated)
YES, you are using it in the wrong way.

raschemmel: What Mark is telling you is that without a mosfet driver to apply -12V to the gate of the mosfet it is not going to turn off. Read the datasheet.

I am not saying that at all, because its incorrect.

I don't think it's turning off, do you ?

What does this mean ? (if not the above )

Well you're using the wrong MOSFET, the IRF540 is not logic level...

What is the current shunt resistance ? (between 1 & 2)

raschemmel: Answer: (as already stated) YES, you are using it in the wrong way. It requires +12V to turn on and -12V to turn off. (because it is not a logic level mosfet)

According to the datasheet it needs 10V to turn on and 0V to turn off - it is an enhancement mode MOSFET.

Include a 10k resistor from AD1 to ground - this pull-down resistor will ensure that the MOSFET is off while the pin is tristated.

The IRF540 is inappropriate for use with Arduino, as it requires 10v on the gate - there exist several types of mosfet drivers that can control 10v fets with a 5v supply - but these are silly, since logic level MOSFETs are readily available. Use one of those instead.

According to the datasheet it needs 10V to turn on and 0V to turn off

Include a 10k resistor from AD1 to ground - this pull-down resistor will ensure that the MOSFET is off while the pin is tristated.

The OP says when he applies 0V to the gate it doesn’t turn off , so how would a 10k resistor to ground help ?
The UNO doesn’t have tri-state so how is that relevant ?
If it should be off and it isn’t then it must be shorted.

Turning it on does not appear to be an issue. It’s turning it off that seems to be the issue.
I realize that you or I could troubleshoot this in 30 seconds by simply removing the connection to the mosfet all together and switching it directly to ground . That would eliminate the mosfet as an issue.
If that has already been done and the voltage across the unknown resistance is 3V , then clearly it is not off.
We don’t have a voltage measurement from DRAIN to SOURCE but if we are to believe what we are told it 3V since turning on the mosfet measures 6V across the current shunt when Vcc = 6V. That means the VDS must be effectively 0V when it is ON. If the voltage V1 to 2 is 3V when it is off , with Vcc = 6V, then VDS= 3V, ergo the mosfet is not OFF.

We still don’t know the current shunt resistance between 1 & 2.

raschemmel: The OP says when he applies 0V to the gate it doesn't turn off , so how would a 10k resistor to ground help ?

Well he'll need it anyway, and maybe what he was actually doing when he said it was at 0V was not setting the pin at all, or digitalWrite(pin,LOW) while the pin was set as an input (which would leave it tristated). The pin would thus be floating and the actual voltage on the gate could be anything from 0~5v, likely resulting in the mosfet being partly-on. Actually, if he forgot to set the pin to OUTPUT, and just started digitalWrite()ing it, and didn't actually measure the voltage on the gate (trusting that it was 0v after writing it low), he'd get the sort of behavior described above... (assuming the load was small, since otherwise the mosfet would not be able to switch it since it's not a logic level mosfet and will only turn on part-way)

raschemmel: The UNO doesn't have tri-state so how is that relevant ? If it should be off and it isn't then it must be shorted.

Are getting that confused with some other concept? Tristate means high-impedance, ie, pinMode(pin,INPUT). All pins on the AVR chips are tristated at reset, and remain that way until you tell it otherwise with pinMode()

Are getting that confused with some other concept? Tristate means high-impedance, ie, pinMode(pin,INPUT). All pins on the AVR chips are tristated at reset, and remain that way until you tell it otherwise with pinMode()

Well, that would be stupid wouldn't it ? (if you need an output) I suppose I was giving the OP the benefit of the doubt but with newbies I guess anything is possible.

Assuming it isn't something stupid, how else would you explain the 3V from drain to source unless the mosfet wasn't off ?

Thank you all for your answers. I solved part of the problem by adding some DigitalWrites --> 0. I think the OUTPUT pin was floating in some parts of the code.

Now the problem is that when I connect a 5VDC motor (Load or "Resistance") it turns for half second and then it resets the arduino.

I use a button with attachinterrupt to activate the mosfet gate. Sometimes when I try to mesure with the voltmeter it activates the interruption and the motor starts... But when I try to activate the interruption using the button it turns for half second and resets the arduino as I said before.

This is the diagram

Do you think it's a short circuit? I verified all the points and it seems to be ok

I think the OUTPUT pin was floating in some parts of the code.

That can only happen if you use a pinMode(pin, INPUT) function call. Normally you set up the pins in the setup function and then you don’t call pinMode again.

Now the problem is that when I connect a 5VDC motor (Load or “Resistance”) it turns for half second and then it resets the arduino.

No surprise here. That is what happens when you don’t use any supply decoupling. It is caused by the interference from the motor brushes.

First read this:-
http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html
For the supply decoupling. Sometimes you have to use a different power supply for the motor, but remember to connect the negative of this supply to the ground of the Arduino.

This is the diagram

Sorry but it is very poor, it is not what a schematic should look like, it is almost impossible to follow.

Do you think it’s a short circuit?

No.

I don't see any information on the motors, the motor driver or the resistance value of "Resistance"

You're going to need to draw a complete schematic on a sheet of printer paper. Also post links for the motors and the drivers.

I solved part of the problem by adding some DigitalWrites --> 0. I think the OUTPUT pin was floating in some parts of the code.

Now the problem is that when I connect a 5VDC motor (Load or "Resistance") it turns for half second and then it resets the arduino.

I use a button with attachinterrupt to activate the mosfet gate. Sometimes when I try to mesure with the voltmeter it activates the interruption and the motor starts... But when I try to activate the interruption using the button it turns for half second and resets the arduino as I said before.

Post a schematic and your code.

Thanks all.

I unfortunately do not have all the info on the motor driver. I asked the constructor but did not get much. Moto driver / motor => this actuator is a pump I am using the DC30A-1230

Resistance: is a heating element. not much info either on this one... 24V, 0.8A

I am posting the code in a minute.

Thanks!

here is the code


#include <OneWire.h>    // imports the wire library for talking over I2C

int DS18S20_Pin = 5; //DS18S20 Signal pin 
//Temperature chip i/o
OneWire ds(DS18S20_Pin); 

float tempC=0;  // Variable for holding temp in C
int tempCint=0;
float tempInterventionUser =0;

int pinPompe=A0;
int pinResistance=A1;
int buttonChaudInput = 2;
int buttonFroidInput = 3;
int etatPompe = 0;
int etatResistance = 0;

float temperatureMax = 27;
float temperatureMin = 20;
float nb_minutes = 0.0;
int secondes_enregistrement = 0;

volatile int state; // interruption

void setup() 
{  
  pinMode(buttonFroidInput,INPUT);
  pinMode(buttonChaudInput,INPUT);
  digitalWrite(buttonFroidInput, HIGH);
  digitalWrite(buttonChaudInput, HIGH);
  pinMode(pinPompe,OUTPUT);
  pinMode(pinResistance,OUTPUT);

  delay(1500);
  
  attachInterrupt(digitalPinToInterrupt(3), decreaseTemp, FALLING);
  attachInterrupt(digitalPinToInterrupt(2), increaseTemp, FALLING); 

  delay(1500);
  digitalWrite(pinPompe,0);
  digitalWrite(pinResistance,0);
  state = 0;
}

void loop() 
{
  tempC = getTemp();
  tempCint = tempC;

  if (state == 1)
  {
    tempInterventionUser = getTemp();
    while (getTemp()>tempInterventionUser - 1)
    {
      digitalWrite(pinPompe,1);
      digitalWrite(pinResistance,0);
      delay(1000);
    }
   state = 0;
  }
  else if (state == 2)
  {
    tempInterventionUser = getTemp();
    while (getTemp()<tempInterventionUser + 1)
    {
      digitalWrite(pinPompe,0);
      digitalWrite(pinResistance,1);
      
      delay(1000);
     
    }
   state = 0;
  }
  else
  {  
    
    //action froid ou chaud
    if (tempC < temperatureMin)
    {
      etatResistance = 1; // la resistance sera en etat marche
      etatPompe = 0;
      
    }
    else if(tempC > temperatureMax)
    {
     
      etatPompe = 1; // la pompe sera en etat marche
      etatResistance = 0;
      
    }
    else if( tempC >= temperatureMin  && tempC <= temperatureMax )
    {
      
      etatPompe = 0; // la pompe sera éteinte
      etatResistance = 0;
      
    }
    
    digitalWrite(pinPompe,etatPompe);
    digitalWrite(pinResistance,etatResistance);
    
    delay(1000);
    
  }
}

float getTemp(){
  //returns the temperature from one DS18S20 in DEG Celsius
 
  byte data[12];
  byte addr[8];
 
  if ( !ds.search(addr)) {
      //no more sensors on chain, reset search
      ds.reset_search();
      return -1000;
  }
 
  if ( OneWire::crc8( addr, 7) != addr[7]) {
      Serial.println("CRC is not valid!");
      return -1000;
  }
 
  if ( addr[0] != 0x10 && addr[0] != 0x28) {
      Serial.print("Device is not recognized");
      return -1000;
  }
 
  ds.reset();
  ds.select(addr);
  ds.write(0x44,1); // start conversion, with parasite power on at the end
 
  byte present = ds.reset();
  ds.select(addr);    
  ds.write(0xBE); // Read Scratchpad
 
 
  for (int i = 0; i < 9; i++) { // we need 9 bytes
    data = ds.read();
  }
 
  ds.reset_search();
 
  byte MSB = data[1];
  byte LSB = data[0];
 
  float tempRead = ((MSB << 8) | LSB); //using two's compliment
  float TemperatureSum = tempRead / 16;
 
  return TemperatureSum;
}

void decreaseTemp()
{
state = 1; // inverse l'état de la variable
}

void increaseTemp()
{
state = 2; // inverse l'état de la variable
}

DrAzzy: According to the datasheet it needs 10V to turn on and 0V to turn off - it is an enhancement mode MOSFET.

Include a 10k resistor from AD1 to ground - this pull-down resistor will ensure that the MOSFET is off while the pin is tristated.

The IRF540 is inappropriate for use with Arduino, as it requires 10v on the gate - there exist several types of mosfet drivers that can control 10v fets with a 5v supply - but these are silly, since logic level MOSFETs are readily available. Use one of those instead.

do you have any "logic level MOSFET" ref in mind?

just got some http://www.vishay.com/docs/91031/sihf630p.pdf any chance of those being better than IRF 540?

Thanks

colinej:
data = ds.read();

  • }*

  • ds.reset_search();*

  • byte MSB = data[1];*

  • byte LSB = data[0];*

  • float tempRead = ((MSB << 8) | LSB); //using two’s compliment*
    …[/quote]
    Cool smiley. I don’t think you meant to use italics either (and something is missing!) Edit your post and add code tags so people will see what you wrote.

Hi,
Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks… Tom… :slight_smile:

Motor is the last row , 350 mA @ 12V