Author Topic: Switching a relay with 2N7000 and Arduino  (Read 19293 times)

0 Members and 1 Guest are viewing this topic.

Offline denemetorTopic starter

  • Newbie
  • Posts: 7
  • Country: au
Switching a relay with 2N7000 and Arduino
« on: June 25, 2016, 02:38:12 am »
Hi all,

I have recently started playing with Arduino and am hoping to learn a little bit about electronics. I have no formal background in electronics so if I sound clueless to you, that is probably why.

To learn about transistors and relays, I have decided to build a simple thermostat. I'm using a temperature sensor and an ADC chip to read the values from the sensor. That part of the circuit is complete. When ambient temperature drops below the set point, I would like to be able to energize the coil of the relay and turn on the heating element. For this purpose, I am using the parts below:


I haven't selected this parts purposefully. They are just what I have at the moment.

Here is the sketch of the circuit:



The problem is that this setup does not work. When I alter the state of the pin of the Arduino, I don't hear the relay clicking. I have tried the relay just by applying 5V to coil and it works. I have also confirmed that the transistor works fine simply by connecting to a LED. Any suggestions? What am I doing wrong? Thanks for your time.
« Last Edit: June 25, 2016, 02:42:58 am by denemetor »
 

Offline Rerouter

  • Super Contributor
  • ***
  • Posts: 4694
  • Country: au
  • Question Everything... Except This Statement
Re: Switching a relay with 2N7000 and Arduino
« Reply #1 on: June 25, 2016, 02:44:54 am »
I would say check that you dont have source and drain flipped, and that your arduino is outputting greater than 3V, (the gate threshold voltage)
 

Offline mariush

  • Super Contributor
  • ***
  • Posts: 4983
  • Country: ro
  • .
Re: Switching a relay with 2N7000 and Arduino
« Reply #2 on: June 25, 2016, 02:48:26 am »
There is always some voltage drop between drain and source, see datasheet page 2. See also the Rds (on) which is a bit high for this mosfet, at around 2 ohms
The relay seems to be with 12v coil but has pick-up at 9v... it says minimum 5v 10mA to work but I'm not sure, you say it works if you use 5v directly. The voltage drop through the mosfet may be enough to lower the voltage the relay sees thereby not triggering it.

And yeah, see gate threshold voltage, you need at least 2v but safe voltages would be above 3v.
 

Offline Rerouter

  • Super Contributor
  • ***
  • Posts: 4694
  • Country: au
  • Question Everything... Except This Statement
Re: Switching a relay with 2N7000 and Arduino
« Reply #3 on: June 25, 2016, 02:54:20 am »
OK that relay is not suited, it needs atleast 9V to latch on, then can be sustained all the way down to 0.6V so your 5V source can never pull it on,

The point about a 5V 10mA load is refering to what you connect across the contacts of the coil, there needs to be a certain amount of "wetting current" to ensure the contacts don't degrade
 

Offline denemetorTopic starter

  • Newbie
  • Posts: 7
  • Country: au
Re: Switching a relay with 2N7000 and Arduino
« Reply #4 on: June 25, 2016, 03:19:15 am »
Thanks for your answers.

I have checked that the source and drain are connected correctly. I have also confirmed that the Arduino pin output (digital high) is 5V by measuring it myself. I have tried 9.8V to trigger the relay instead of 5V but it still does not work.
 

Offline Tom45

  • Frequent Contributor
  • **
  • Posts: 555
  • Country: us
Re: Switching a relay with 2N7000 and Arduino
« Reply #5 on: June 25, 2016, 04:10:47 am »
What is the voltage at the gate and drain of the 2N7000 for each of the two states of your device?

I'm also suspicious about the relay's rated 9 V pickup voltage, but you said it activates with only 5 volts, so it must be something else.
 

Offline Signal32

  • Frequent Contributor
  • **
  • Posts: 251
  • Country: us
Re: Switching a relay with 2N7000 and Arduino
« Reply #6 on: June 25, 2016, 04:19:33 am »
Maybe you installed the diode the other way around :) ?
Measure the voltages on the MOSFET Gate + Drain when the Arduino is outputting 0 and 1 and post the results here.
 

Offline denemetorTopic starter

  • Newbie
  • Posts: 7
  • Country: au
Re: Switching a relay with 2N7000 and Arduino
« Reply #7 on: June 25, 2016, 04:27:06 am »
Here are the voltages on the gate and drain with two different supply voltages to the relay.

Pin state - 5V supply - 9V supply
Low4.538.39
High0.003.57
 

Offline Signal32

  • Frequent Contributor
  • **
  • Posts: 251
  • Country: us
Re: Switching a relay with 2N7000 and Arduino
« Reply #8 on: June 25, 2016, 04:54:08 am »
Here are the voltages on the gate and drain with two different supply voltages to the relay.
I don't really understand which voltage is which O.o
Perhaps fill in this table:


Pin state|  5V supply - Gate  ||  9V supply - Gate  ||  5V supply - Drain  ||  9V supply - Drain  |
Low         =         =         =         =
High         =         =         =         =
 

Offline bitseeker

  • Super Contributor
  • ***
  • Posts: 9057
  • Country: us
  • Lots of engineer-tweakable parts inside!
Re: Switching a relay with 2N7000 and Arduino
« Reply #9 on: June 25, 2016, 04:57:48 am »
I'm using a temperature sensor and an ADC chip to read the values from the sensor.

Just a side note that the Arduino has ADC pins to read analog signals. You may need to scale the sensor's output to utilize the full range of the ADC.
TEA is the way. | TEA Time channel
 

Offline denemetorTopic starter

  • Newbie
  • Posts: 7
  • Country: au
Re: Switching a relay with 2N7000 and Arduino
« Reply #10 on: June 25, 2016, 05:26:04 am »
My bad, sorry. I thought you were asking the voltage between drain and gate.

Pin state|  5V supply - Gate  ||  9V supply - Gate  ||  5V supply - Drain  ||  9V supply - Drain  |
Low         0.14         0.19         4.67         8.53
High         5.01         5.16         4.98         8.70

Just a side note that the Arduino has ADC pins to read analog signals. You may need to scale the sensor's output to utilize the full range of the ADC.

Thanks. Arduino's ADC is 10 bit, which is more than enough for me but I wanted to play with 3201-C (12 bit) just to see how it is connected to a circuit (SPI serial interface).

« Last Edit: June 25, 2016, 05:31:40 am by denemetor »
 

Offline Rerouter

  • Super Contributor
  • ***
  • Posts: 4694
  • Country: au
  • Question Everything... Except This Statement
Re: Switching a relay with 2N7000 and Arduino
« Reply #11 on: June 25, 2016, 05:36:29 am »
so in otherwords the mosfet is doing nothing, check the datasheet that you have it wired correctly,
 

Offline denemetorTopic starter

  • Newbie
  • Posts: 7
  • Country: au
Re: Switching a relay with 2N7000 and Arduino
« Reply #12 on: June 25, 2016, 05:48:41 am »
When I remove the relay and placed a LED it starts blinking and the drain voltage changes between 2.4V and 5V. Does this mean that the MOSFET is wired correctly?
 

Offline Signal32

  • Frequent Contributor
  • **
  • Posts: 251
  • Country: us
Re: Switching a relay with 2N7000 and Arduino
« Reply #13 on: June 25, 2016, 05:51:34 am »
My bad, sorry. I thought you were asking the voltage between drain and gate.
OK, seems like the MOSFET is damaged / wired incorrectly. But in that case, replacing the relay with an LED shouldn't work either.
Can you replace just the relay with the LED + resistor, leave the diode in place, and re-populate the table ? See if the LED lights up.
If the LED works the next step would be to put the relay in parallel with the LED + resistor.
How were you hooking up the LED when it lit up, what resistor were you using, what supply voltage and was the diode there ?
« Last Edit: June 25, 2016, 05:53:13 am by Signal32 »
 

Offline Rerouter

  • Super Contributor
  • ***
  • Posts: 4694
  • Country: au
  • Question Everything... Except This Statement
Re: Switching a relay with 2N7000 and Arduino
« Reply #14 on: June 25, 2016, 05:54:51 am »
not really, better to use a resistor e.g. 100-1000 ohm (quarter watt resistor), LED's can turn on with extremely tiny currents, and in a dark workshop most people can see LED's illuminated at 1-2 uA.

Equally i would see about measuring the resistance of your relay coil, just to make sure its not open circuit or something silly,
 

Offline bitseeker

  • Super Contributor
  • ***
  • Posts: 9057
  • Country: us
  • Lots of engineer-tweakable parts inside!
Re: Switching a relay with 2N7000 and Arduino
« Reply #15 on: June 25, 2016, 05:57:51 am »
Thanks. Arduino's ADC is 10 bit, which is more than enough for me but I wanted to play with 3201-C (12 bit) just to see how it is connected to a circuit (SPI serial interface).

Sounds good. :-+
TEA is the way. | TEA Time channel
 

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
Re: Switching a relay with 2N7000 and Arduino
« Reply #16 on: June 25, 2016, 06:09:07 am »
The 2n7000 is not well-suited to this application. With 5V to the Gate it will just barely be turning on, still in the linear operation region, and its Drain-Source resistance will be high. Even when fully On the resistance could be as high as 5 ohms. This might work OK driving an LED from a 5 volt supply (and might not even need a current-limiting resistor for the LED!) but trying to drive a 12 volt relay from a 5 volt supply, through a partially on 2n7000, is not going to work. It might work with the 9 volt supply but the measurements seem to show that it is not working even then.

Let's be sure we know what we are measuring here. The voltage on the mosfet Drain pin should be measured with reference to the Source pin. This voltage should be near the relay coil supply voltage when the mosfet is OFF and should drop quite a bit when the mosfet is ON -- if the relay coil has continuity, etc. The measurements with the 9V supply seem to show that this isn't happening.

So something is wrong somewhere. It's possible that the 2n7000 is not working properly for some reason. (fake? blown? not connected properly?) It is possible that the parallel diode is backwards, shorting out the relay coil. It is possible that the 2n7000 is just one of those that doesn't turn on well at 5 volts to the gate, and is operating in the linear region enough to turn the LED on (with no dropping resistor!) but can't pass enough current, even with the 9v supply, to actuate the relay.

Can we see a photograph of the setup (presumably on a breadboard?)
The easiest person to fool is yourself. -- Richard Feynman
 

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
Re: Switching a relay with 2N7000 and Arduino
« Reply #17 on: June 25, 2016, 06:16:30 am »
My bad, sorry. I thought you were asking the voltage between drain and gate.

Pin state|  5V supply - Gate  ||  9V supply - Gate  ||  5V supply - Drain  ||  9V supply - Drain  |
Low         0.14         0.19         4.67         8.53
High         5.01         5.16         4.98         8.70

Just a side note that the Arduino has ADC pins to read analog signals. You may need to scale the sensor's output to utilize the full range of the ADC.

Thanks. Arduino's ADC is 10 bit, which is more than enough for me but I wanted to play with 3201-C (12 bit) just to see how it is connected to a circuit (SPI serial interface).



Note that when the Pin State is HIGH, the mosfet Drain voltage is _higher_ than when the Pin State is LOW. This is exactly opposite of what it should be. When the mosfet is ON (gate drive pin state HIGH) the Drain-Source voltage should be _lower_, in fact it should be quite a bit lower than when the mosfet is OFF (gate drive pin state LOW).
So something is very wrong somewhere.
The easiest person to fool is yourself. -- Richard Feynman
 

Offline denemetorTopic starter

  • Newbie
  • Posts: 7
  • Country: au
Re: Switching a relay with 2N7000 and Arduino
« Reply #18 on: June 25, 2016, 06:25:30 am »
Can you replace just the relay with the LED + resistor, leave the diode in place, and re-populate the table ? See if the LED lights up.

Supply: 5V, LED + 330 ohm resistor, no diode, no relay:
Pin state: high, drain: 5V, gate: 5V, LED: off.
Pin state: low, drain: 1.6V, gate 0V, LED: on.

Supply: 5V, LED + 330 ohm resistor is in parallel with the diode, no relay:
Pin state: high, drain: 5V, gate: 5V, LED: off.
Pin state: low, drain: 1.6V, gate: 0V, LED: on.

Supply 5V, LED + 330 ohm resistor is in parallel with the relay, no diode:
Pin state: high, drain: 5V, gate: 5V, LED: off.
Pin state: low, drain: 3.2V, gate: 0.1V, LED: off.

Equally i would see about measuring the resistance of your relay coil, just to make sure its not open circuit or something silly,

Resistance of the relay coil: 55 ohm.

I am really confused. I have double checked the datasheet for the MOSFET and it is wired correctly.

@alsetalokin4017, I'll upload a photo of the setup in half an hour. Let me try to supply 9V to the gate.
 

Offline Signal32

  • Frequent Contributor
  • **
  • Posts: 251
  • Country: us
Re: Switching a relay with 2N7000 and Arduino
« Reply #19 on: June 25, 2016, 06:34:58 am »
Just to make sure, here is the pinout :
http://www.muzique.com/news/images/2N7000.gif

It does seem that the MOSFET is damaged, the LED is on when the gate is low, exactly opposite to how it's suppose to be.
Supplying 9v to the gate won't do much different, the difference between 5v and 9v is very tiny for this MOSFET.
Are you sure you've got a 2n7000 ? What is the marking, do you have another N-CH mosfet to swap with it ?
 

Offline denemetorTopic starter

  • Newbie
  • Posts: 7
  • Country: au
Re: Switching a relay with 2N7000 and Arduino
« Reply #20 on: June 25, 2016, 06:52:38 am »
Here's a link to the breadboard photo.


Just to make sure, here is the pinout :
http://www.muzique.com/news/images/2N7000.gif

It does seem that the MOSFET is damaged, the LED is on when the gate is low, exactly opposite to how it's suppose to be.
Supplying 9v to the gate won't do much different, the difference between 5v and 9v is very tiny for this MOSFET.
Are you sure you've got a 2n7000 ? What is the marking, do you have another N-CH mosfet to swap with it ?

Maybe I somehow damaged the MOSFET. It is the only one I have at the moment but I will definitely try with some other transistors Monday morning. The exact marking on it is "2N7000 - E20".
 

Online newbrain

  • Super Contributor
  • ***
  • Posts: 1714
  • Country: se
Re: Switching a relay with 2N7000 and Arduino
« Reply #21 on: June 25, 2016, 09:18:02 am »
Maybe I somehow damaged the MOSFET. It is the only one I have at the moment but I will definitely try with some other transistors Monday morning. The exact marking on it is "2N7000 - E20".
Since it appears you have a DMM, you can easily check if MOSFET works:
Nandemo wa shiranai wa yo, shitteru koto dake.
 

Offline batteksystem

  • Regular Contributor
  • *
  • Posts: 167
  • Country: hk
    • My ebay store
Re: Switching a relay with 2N7000 and Arduino
« Reply #22 on: June 25, 2016, 10:07:31 am »
Thanks for your answers.

I have checked that the source and drain are connected correctly. I have also confirmed that the Arduino pin output (digital high) is 5V by measuring it myself. I have tried 9.8V to trigger the relay instead of 5V but it still does not work.

have you checked if the relay can be turned on if directly connect to 9V (not controlled by MOSFET but by a DC voltage)?

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
Re: Switching a relay with 2N7000 and Arduino
« Reply #23 on: June 25, 2016, 05:05:26 pm »
Can you replace just the relay with the LED + resistor, leave the diode in place, and re-populate the table ? See if the LED lights up.

Supply: 5V, LED + 330 ohm resistor, no diode, no relay:
Pin state: high, drain: 5V, gate: 5V, LED: off.
Pin state: low, drain: 1.6V, gate 0V, LED: on.

Supply: 5V, LED + 330 ohm resistor is in parallel with the diode, no relay:
Pin state: high, drain: 5V, gate: 5V, LED: off.
Pin state: low, drain: 1.6V, gate: 0V, LED: on.

Supply 5V, LED + 330 ohm resistor is in parallel with the relay, no diode:
Pin state: high, drain: 5V, gate: 5V, LED: off.
Pin state: low, drain: 3.2V, gate: 0.1V, LED: off.

These data would seem to indicate that the component is acting like a PNP transistor, rather than an N-channel mosfet.
With any N-channel mosfet the LED should be ON when the Gate voltage is HIGH, and the LED should be OFF when the Gate voltage is LOW.

At this point -- always presuming your measurements are correct -- I think you may have a non-genuine or mislabelled 2n7000.

Quote

Equally i would see about measuring the resistance of your relay coil, just to make sure its not open circuit or something silly,

Resistance of the relay coil: 55 ohm.

I am really confused. I have double checked the datasheet for the MOSFET and it is wired correctly.

Yes, from what I can see on your breadboard photo, the item is correctly connected IF it is indeed actually a 2n7000.

Quote

@alsetalokin4017, I'll upload a photo of the setup in half an hour. Let me try to supply 9V to the gate.

According to the data sheet you posted for the 12 volt relay, the coil resistance should be 320 ohms.

Don't attempt to supply 9V to the transistor Gate while your Arduino Pin 7 is still connected !!

Could you also please post your Arduino code so we can check it for anything that could be wrong there. Although if you are getting Pin 7 to go from +5 to 0 and back again as expected it's hard to imagine anything wrong in the code that could be causing the problem. But post it anyhow, please.

The easiest person to fool is yourself. -- Richard Feynman
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf