controlling relay with gpio

Hi there,

Ok I am trying to get a 3 volt coil relay to complete a circuit using a 3 volt gpio pin. This apparently is not as easy as taking the pin high and activating the switch.

I have seen some diagrams that appear to use a diode and a resistor and from what I can see the 3.3volts comming from the gpio completes the ground … I don’t understand

What is happening is that I check the pin with my MM and it has a bit over 3 volts when pulled high. However if I touch this to the relay the switch doesn’t go and the voltage drops to around .45-.48.

If anyone knows and could explain what is going on and what and give me a circuits for dummies explanation for why this isn’t working that would be great.

It's not hard. You are trying to take more current than the I/O pin can source, which will lead to damage to the pin (perhaps already). What you need to do is use a transistor to switch the relay coil, but you need to post the specifics of what you have. What relay? What micro-controller?

Thanks for the reply,

I think I have saved myself a little time, I just got overnight delivery of a sainsmart 2 channel relay that appears to have the equipment built in.

However I would like to understand the problem and the fix if it's easy. I am using a synapses rf200p81 it runs on 3.3 volts and has 19 gpio pins.

the relay packaging says philmore 10amp relay spdt coil 3vdc/120 ma #86-103

the relay itself is blue and says goodsky on it (purchased at fry's electronics around 3 bucks)

Thanks
Mark

Can't drive a 120mA relay with a GPIO pin.
Datasheet lists GPIO currents up to 8mA for that processor.

Mechanical or solid state relay (link to the product).
How did you connect, and how did you power (if mechanical).
Some need 5volt.
Leo..

If you think about it, it’s not hard to understand. Every power supply on the planet has 2 factors (3 with phase) that is needed. First is voltage, and the second is current. The Voltage is defined. A 5v or 3V or 110VAC supply will always produce that voltage. The current however is variable, with the stated number being the maximum. Some might have a minimum requirement for regulation purposes. So for a 100mA supply, you can use 10mA, 30mA, 67mA, or even 100mA (not recommended to use max values), but you cannot use 200mA without expecting damage.

Your controller can supply 3V @ 8mA. That means you can hook up anything that requires 3V and uses less than 8mA, which isn’t a whole lot. Your relay requires 120mA. That is a whole lot more than 8mA, don’t you think?

That’s why it is important to know what the supply (microcontroller) can provide, and also what the load (relay) requires. For your uC, you need to get comfy with using transistors and logic level mosfets to perform any work. You can use outputs to control other chips, but again, you have to make sure of the requirements, like 3V or 5V, and how much current is required. Most leds are rated at 20mA, which can be comfortably run off an Arduino Uno I/O pin with a current limiting resistor. You see many posts about just throwing a 220ohm resistor on it and lighting it up. For you, you have to figure the resistor for 5mA If with leds that have a Vf of <3V.

I am not going to pretend to know much, however 3v 8ma makes sense and 8ma being less than 120ma makes sense too.

I have a couple of other relays one is a 12v coil and it only has 30ma instead of 120 I got the 3v thinking my chip was 3v but not sure if thats the ticket

I added links and attached images of the relay setup coming tomorrow. (haven’t used this forum before and didn’t know what worked best)

I watched a video this was using an uno. 5v to vcc, gnd to gnd, gpio pin to in1 should set up the switch and I understand the nc and no and pole.

I think you were telling me that the uno has a 20ma pin so will a I be able to use this setup with my measly 8ma pin.

My setup has a nodemcu 1.0(12e) esp8266 board also and I could use one of the pins off of that. It is just that I only have one of these in an installation and I could have several of the rf200p81 chips.

The synapses chips create a self healing mesh network on their own I then connect one of them serially to the nodemcu so I can control the entire setup from the net.

I have several RFP30N06LE 30A 60V N-Channel Mosfet TO-220 transistors coming tomorrow I got them because from what I read once I get this setup working I can use pwm and the mosfet to create a dimmer (in the end this whole thing runs 24v led light fixtures and strips)

So big question what else am I going to need tomorrow to get the gpio digital on/off (high/low) working on the relay.

and I am afraid to ask how difficult it is to use a pwm pin to limit the power on the high voltage side of the circuit

Thanks all for your help

Those relay boards only require 2mA drive current from the GPIO pin.

The coils need 5volt, and draw ~75mA each when active.

5volt is available on the USB/V-in/raw pin of the NodeMcu.

That relay board is active LOW.

Post a diagram of your setup, so we can check.
Leo..

I am afraid to ask how difficult it is to use a pwm pin to limit the power on the high voltage side of the circuit

Don't be. At first it might seem like rocket-science, but you will find out it is actually fairly basic and not hard to do. Big part of it is to know what your micro controller can supply and what the rest of the circuit requires. It might be a little easier with a 5v microcontroller rather than a 3V.

mtalent:
The synapses chips create a self healing mesh network on their own I then connect one of them serially to the nodemcu so I can control the entire setup from the net.

That does not make sense (to me).
Using a WiFi module to control a WiFi module?

ESP8266 modules/Arduinos should be able to do what that other module does, including mesh networks.
Leo..

Edit: Ahh, I see. One is a Zigbee module.

Yeah, "self healing" shouldn't be taken literally. If you smoke it, it's smoked. In order for the mesh network to work, you need many nodes so there IS a path to re-route. How complex a system are you doing?

Ok

I am at home getting ready to leave for work when I get there I will get the circuit design.

The synapses chips communicate fine with each other but you can't connect them to the internet. I am not a hundred percent sure why they are 2.4 ghz just like wifi but use different protocols I guess.

So I built a bridge by serially connecting a snap(short for synapses) chip to my nodemcu. Using an mqtt broker I send messages from a mobile app to the bridge. For example when the mobile app first fires up it sends a request to know what snap chips are in it's realm so to say. So the bridge snap chip sends a multi-cast message out to all the snap chips and they respond with their address.

Not to get too much into the application but I build a list with them and then I can very easily send commands and request information from each chip.

The setup is small, the self healing part is useful if someone adds a controller (chip) to the system on application startup it will respond to the application multi-cast message and will be added without any extra effort.

I should add that the snap chips were already being used by the company. I am building a remote control app for them and I had to use the snap chips.

It does however work as kind of a nice firewall since the only point of connection is the one wifi chip the rest of the network is safely on it's own.

After building this setup I have ideas for other applications but I think I am going to use xbee chips instead they are cheaper.

I have a picture of my prototype and I’ll give you a run down

ESHION® AC-DC 100-240V to 5V 1A 5W Step-Down Power Supply

using a 2 post terminal the houses AC power is connected to this. I can get the 5 volts from this to run to the switch also.

From there the power goes to the VIN port and a gnd on the nodemcu 1.0

The nodemcu has several 3v power pins and gnds

I connect the snap chip to one of the 3v and gnd pins on the nodemcu 1.0

then there are the serial connections

I cannot get the switch to flip.

jumper vcc - jdvcc

then vcc to 5v, gnd to gnd, in1 to gpio at first then directly to 5v and then to gnd (tried high and low)

nothing happening at the switch

OK ....................

I connect 5v to jdvcc and ground to ground of a separate power source which is how the setup will work the 5v and ground will come from the ac/5v step down.

then I connect 5v from the vin on the nodemcu to the vcc on the switch and gpio 19 from the snap chip in1 and it works.

I am going to try a few other hookups I'll let you know

I have the app turning the led on and off, this was the first hurdle

Now to figure out the mosfet and dimming.

Attached a video showing my results ..... (someone should see my success).

Thanks for all your help :slight_smile:

too big to attach I put it up on one of my servers

link to my video

So from what I have so far, I was thinking wrong. I thought the mosfet worked in conjunction with the switch now it appears the mosfet is a switch.

I am off to fry's to get a 10-100 ohm resistor that goes between gate and 5v.

And I am getting a 10k pull down resistor that goes between the micro-controllers ground and ground. (I think)

And I am not sure where I am going to get the 5v pins I need. I need a 3.3v mosfet

I have been looking at the power safety issues and it appears with this one led lamp it's drawing 350 ma so I should be cool

Any other advice would be great

.......EDIT......

Found this at sparkfun about this mosfet

This is a very common MOSFET with very low on-resistance and a control voltage (aka gate voltage) that is compatible with any 3-5V microcontroller

I don't know what I did, it seems everyone left.....anyhow I am a programmer not an electrician just so you can see where my thinking was..... I thought a pull down resistor was a type of resistor not just a resistor set up to pull the pin down. the logic makes sense it just would have been nice if you guys had climbed in my head and explained it to me

http://www.eeweb.com/blog/extreme_circuits/dimmer-with-a-mosfet

I am getting lost and need help

mtalent:
it just would have been nice if you guys had climbed in my head and explained it to me

Try to replace the long stories with schematic dagrams, images, code, links, and direct questions.
Leo..

You must understand, many of us are "ancient" but still work more than menial jobs. I don't know where you are located, but I'm in the central US and it was 7pm before I got home.

Like Wawa says, post a diagram of what you are trying to get going, along with any code you have (please use code tags). One at a time though, so you don't get lost . Once the relay is operating correctly, then tackle the led, which is a power led and requires different approaches than a plain ol 20mA red blinky led. Make sure you have the requirements for it, such as Vf and If, and how many in what configuration.

Resist the urge to just start connecting wires willy-nilly. You might eventually get it right, but you might also burn something up the try before that and never know it.

all good, I actually already have the 24 volt led working with the relay ... I linked a video. previous post

I don't know how to make a schematic I am sure I could figure it out but I might have this done by then

I am now trying to figure out how to implement the mosfet and at this point the pull down resistor is causing me trouble.

I have gpio 19 coming out of the snap chip that I am successfully activating the relay with pulling high and low.

now to adapt the mosfet

So 24v power source + (positive) to led positive

led - (negative) connected to source on mosfet

24v power source - (negative) connected to drain on mosfet

this is where the confusion is ------

without a pull down I would just connect my gpio 19 to gate high on low off

However this doesn't work somehow I have to connect a 10k resistor to gate along with gpio 19 ...??????

mtalent:
I don’t know how to make a schematic I am sure I could figure it out but I might have this done by then…

So 24v power source + (positive) to led positive

led - (negative) connected to source on mosfet
24v power source - (negative) connected to drain on mosfet

Running a marathon before learning to walk?

Yes.

No. Drain to LED negative, and source to ground.

Read this.
First image.
You can ignore the diode if the load is a LED.
I hope your “350mA LED lamp” has buildin or external current limiting.
Leo…

A diagram isn’t hard, don’t make it out to be more than it is. It’s just a simple block type diagram for the controller with lines (wires) connecting to resistors/capacitors/mosfets/ leds etc. Label the pins and make it readable. Try keeping power + on the left and goes across. Grounds go towards the bottom, and signals go from left to right. For yours, you would have a 3V supply on the left, power going to the right to the microcontroller (wifi chip or whatever you are using), number what pin it is. then a wire going to the right again (signal) to the rf chip. 3V would go to it as well. the gpio pin (numbered) goes to the right again to a resistor and the other end to the mosfet gate (labeled). The led would be above the mosfet source (labeled n-ch pn???). The top of the led would go to the + of the second supply.

It’s not hard for a simple circuit like this, but difficult to picture in your head by the text in your posts. You might catch some flak at your first attempt, but that goes with anything. I’m sure you got some with your first attempts at programming.

As for what you described, you only have 8mA to work with, so limiting the current to the gate is wise. The 10K is a pulldown, which is there to turn the mosfet off and keep it from being somewhere in the middle of on/off. Limiting current would be the smaller of the resistors, and grounds from both supplies would be connected together. Off the gpio pin, connect BOTH resistors. Connect the 10K to ground, and the other to the gate of the mosfet.

Draw the diagram and post it.