Switching a relay with 2N7000 and Arduino - Page 1
Forum section: electronics / beginners

author: denemetor
author_rank: Newbie
timestamp: June 25, 2016, 02:38:12 am
content: 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:2N7000 transistor -Datasheet (.pdf)1N4007 diode -Datasheet (.pdf)JZC-11F relay -Datasheet (.pdf)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.

author: Rerouter
author_rank: Super Contributor
timestamp: June 25, 2016, 02:44:54 am
content: 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)

author: mariush
author_rank: Super Contributor
timestamp: June 25, 2016, 02:48:26 am
content: 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 ohmsThe 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.

author: Rerouter
author_rank: Super Contributor
timestamp: June 25, 2016, 02:54:20 am
content: 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

author: denemetor
author_rank: Newbie
timestamp: June 25, 2016, 03:19:15 am
content: 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.

author: Tom45
author_rank: Frequent Contributor
timestamp: June 25, 2016, 04:10:47 am
content: 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.

author: Signal32
author_rank: Frequent Contributor
timestamp: June 25, 2016, 04:19:33 am
content: 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.

author: denemetor
author_rank: Newbie
timestamp: June 25, 2016, 04:27:06 am
content: Here are the voltages on the gate and drain with two different supply voltages to the relay.Pin state -5V supply -9V supplyLow4.538.39High0.003.57

author: Signal32
author_rank: Frequent Contributor
timestamp: June 25, 2016, 04:54:08 am
content: Quote from: denemetor on June 25, 2016, 04:27:06 amI don't really understand which voltage is which O.oPerhaps fill in this table:Pin state| 5V supply - Gate || 9V supply - Gate || 5V supply - Drain || 9V supply - Drain |Low====High====

author: bitseeker
author_rank: Super Contributor
timestamp: June 25, 2016, 04:57:48 am
content: Quote from: denemetor on June 25, 2016, 02:38:12 amJust 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.

author: denemetor
author_rank: Newbie
timestamp: June 25, 2016, 05:26:04 am
content: 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 |Low0.140.194.678.53High5.015.164.988.70Quote from: bitseeker on June 25, 2016, 04:57:48 amThanks. 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).

author: Rerouter
author_rank: Super Contributor
timestamp: June 25, 2016, 05:36:29 am
content: so in otherwords the mosfet is doing nothing, check the datasheet that you have it wired correctly,

author: denemetor
author_rank: Newbie
timestamp: June 25, 2016, 05:48:41 am
content: 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?

author: Signal32
author_rank: Frequent Contributor
timestamp: June 25, 2016, 05:51:34 am
content: Quote from: denemetor on June 25, 2016, 05:26:04 amOK, 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 ?

author: Rerouter
author_rank: Super Contributor
timestamp: June 25, 2016, 05:54:51 am
content: 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,

author: bitseeker
author_rank: Super Contributor
timestamp: June 25, 2016, 05:57:51 am
content: Quote from: denemetor on June 25, 2016, 05:26:04 amSounds good.

author: alsetalokin4017
author_rank: Super Contributor
timestamp: June 25, 2016, 06:09:07 am
content: 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?)

author: alsetalokin4017
author_rank: Super Contributor
timestamp: June 25, 2016, 06:16:30 am
content: Quote from: denemetor on June 25, 2016, 05:26:04 amNote 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.

author: denemetor
author_rank: Newbie
timestamp: June 25, 2016, 06:25:30 am
content: Quote from: Signal32 on June 25, 2016, 05:51:34 amSupply: 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.Quote from: Rerouter on June 25, 2016, 05:54:51 amResistance 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.

author: Signal32
author_rank: Frequent Contributor
timestamp: June 25, 2016, 06:34:58 am
content: Just to make sure, here is the pinout :http://www.muzique.com/news/images/2N7000.gifIt 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 ?

author: denemetor
author_rank: Newbie
timestamp: June 25, 2016, 06:52:38 am
content: Here's a link to the breadboard photo.Quote from: Signal32 on June 25, 2016, 06:34:58 amMaybe 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".

author: newbrain
author_rank: Super Contributor
timestamp: June 25, 2016, 09:18:02 am
content: Quote from: denemetor on June 25, 2016, 06:52:38 amSince it appears you have a DMM, you can easily check if MOSFET works:

author: batteksystem
author_rank: Regular Contributor
timestamp: June 25, 2016, 10:07:31 am
content: Quote from: denemetor on June 25, 2016, 03:19:15 amhave you checked if the relay can be turned on if directly connect to 9V (not controlled by MOSFET but by a DC voltage)?

author: alsetalokin4017
author_rank: Super Contributor
timestamp: June 25, 2016, 05:05:26 pm
content: Quote from: denemetor on June 25, 2016, 06:25:30 amThese 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.QuoteYes, from what I can see on your breadboard photo, the item is correctly connected IF it is indeed actually a 2n7000.QuoteAccording 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.