Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

5V relay with ND+


  • Please log in to reply
24 replies to this topic

#1 Cabadam

Cabadam

    Advanced Member

  • Members
  • PipPipPip
  • 90 posts

Posted 18 February 2012 - 05:39 PM

Prefacing this with - I'm a software guy. Doing my best to read up and understand the circuitry side of things, and only partially following. I know the ND+ provides 3V3 out the digital output pins, not 5V. I currently have the following relay: http://www.amazon.co...s00_i00_details My goal is to drive 24VAC. When I first got it, I had some trouble getting it switch on and off. If I connected the relay to the 5V output from the ND+, as soon as I powered on the ND+, all of the relays (that were wired up to digital pins) switched on (on = LED lit up). Then, no matter what state I set the digital output pins, the LEDs stay on. Thinking it might be more beneficial to have the signal/control voltage at the same as the power voltage, I moved the relay's power over to the 3V3 pin. With that configuration, only the green power LED turns on when the ND+ power on. The individual relay LEDs stay off on startup (so I am guessing it is active-low, since I read the ND+ sends high by default when it powers up). Working with that, I initialized my output pins as initial state = true. By then writing 'false', I can switch the individual relays on, true switches them back off. It "seems" to work. Presumably due to the lower voltage in play, none of the LEDs on the relay are as bright as they were when connected to the 5V. I recently realized... I actually need 9 relays to accomplish my project (sprinkler system controller), not 8 (forgot about that darn master valve). Ultimately, I'm hoping to also connect in an LCD (something like http://www.sparkfun.com/products/9067). That should leave me with enough I/O pins for both the relays and the LCD. All the wiring is "direct" between the ND+ and the relay board - no breadboard involved (I don't even own one at this point, although I think I'm going to need one to get power to both the relay and the LCD). Anyway, before I buy any more relay hardware, I wanted to get feedback on whether running at this lower voltage would actually cause any problems. I looked around and pretty much the smallest relay that is common seems to be 5V. I just want to make sure I'm buying the right stuff. Thoughts/suggestions/OMGWhatAreYouDoing are all welcome!

#2 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 18 February 2012 - 07:05 PM

Hi Adam,

For those who have not followed the link Adam gave, this relay card is designed to be driven by a micro controller like the Netduino, it does not require transistors, inductors or resistors.

Following your link, there is no circuit diagram, but someone has added details of the signal voltages needed to drive the logic inputs of the relay board. The voltages stated: 0 to 0.5V (Relay ON), and 2.5 to 5V (Relay OFF), are compatible with the 0V and 3.3V that the Netduino will output on its pins. Without seeing a real circuit diagram I can't see why you would be having a problem with the supply voltage set to 5V.

It might be worth taking the connections apart and then reconnecting from scratch - just in case you made a mistake the first time when trying 5V.

Following the link to the two relay board, there was a comment that a buyer had been supplied a board different from the picture on Amazon. Maybe they have changed the design so that it is not compatible with 3.3V logic unless the supply is set to 3.3V....

Possible design changes aside; to ensure correct operation of the relay coils, I believe the relay board should be powered with 5V not 3.3V. At 3.3V you may find issues turning on the relays reliably.

The negative logic behaviour you found when running at 3.3V is correct - the Netduino pulls all the digital pins high at reset/power on, and this will turn the relays OFF. Pulling an output to ground (logic zero) turns the relays ON.

Assuming you find you can drive the relays reliably, you might consider buying the two way relay board to give you the extra relay plus a spare.

There should still be enough pins left over on the Netduino to drive the LCD you linked to with one of the Netduino COM ports. Someone is bound to have tried that particular model before and will have some driver code.

Hang in there software guy!

Paul

#3 Cabadam

Cabadam

    Advanced Member

  • Members
  • PipPipPip
  • 90 posts

Posted 18 February 2012 - 07:21 PM

You say the comment about the different "variant" actually being shipped was in the 2-relay one? Looked at the two and four, couldn't find it. That said - I took a closer look at the one Amazon says I previously bought. That is NOT what mine looks like. It is very similar, but not an exact match. Possibly most relevant, all of their pictures show an extra set of pins off to the side. My board does not have this. It only has the main 10-pin connector (VCC, IN1-8, GND). I notice in the 8-relay picture, it appears there is a jumper across two of them. I wonder if the newer revisions with that extra set are what that user was referring to by "the supply is set to 3.3V." EDIT: In answer to your suggestion to reconnect things - yes, I have tried moving the connections back and forth a number of times (including against just now to make sure I'm not crazy). When I first got it and I couldn't get it to work at all, I had taken it to work with me and a coworker who is a bit more familiar with electronics took a look at it. When he read that the signal pins are putting out 3V3, it was his suggestion to try moving the power connection to 3V3 instead of 5V.

#4 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 18 February 2012 - 08:52 PM

You say the comment about the different "variant" actually being shipped was in the 2-relay one? Looked at the two and four, couldn't find it.

Sorry - my mistake.
The comment was actually on the eight relay board that you bought - not the two relay!
Comment:
The board I received appears to be a newer revision than the one pictured: the LEDs are surface-mount instead of thru-hole and are next to their corresponding relay, and the control headers are centered instead of in one corner.


Possibly most relevant, all of their pictures show an extra set of pins off to the side. My board does not have this. It only has the main 10-pin connector (VCC, IN1-8, GND). I notice in the 8-relay picture, it appears there is a jumper across two of them. I wonder if the newer revisions with that extra set are what that user was referring to by "the supply is set to 3.3V."

I saw the extra pins in the picture too. On the two relay board, it is a little easier to see the labelling of the pins:JD-VCC, VCC, Gnd. Not very helpful labelling!
If I am reading it correctly, the 8 relay review says that JD-VCC is the supply for the relays, and VCC is the logic supply. In the picture these are linked by a jumper.
Its not unusual to give separate supply connections, it allows the supply lines for noisy motors and relays to be kept isolated from the supply for digital logic components.

It does sound like the logic on your board works best with 3.3V. It might be possible to supply 5V for the relays (JD-VCC) and 3.3V for the logic (VCC) - but only if you had been sent that version of the board :( I think it would be worth asking the supplier for the schematics - ideally for both versions of the board so we can play spot the difference.

Try experimenting with the relay board to check how reliable it is running at 3.3V - you might find it is OK for you. You could try some simple tests like turning on all the relays at the same time and verifying that they all come on. (The large current drawn by all relays being on together might make the power supply reduce such that some of them don't turn on fully.) When checking, don't trust the LEDs, check that the relay contacts have really closed.


Paul

#5 Cabadam

Cabadam

    Advanced Member

  • Members
  • PipPipPip
  • 90 posts

Posted 18 February 2012 - 11:19 PM

I saw the extra pins in the picture too. On the two relay board, it is a little easier to see the labelling of the pins:JD-VCC, VCC, Gnd. Not very helpful labelling!
If I am reading it correctly, the 8 relay review says that JD-VCC is the supply for the relays, and VCC is the logic supply. In the picture these are linked by a jumper.
Its not unusual to give separate supply connections, it allows the supply lines for noisy motors and relays to be kept isolated from the supply for digital logic components.

Well, I've got the smaller 2-relay board on order. Hopefully it will come in the new variety, and I'll see if it responds any differently.

It does sound like the logic on your board works best with 3.3V. It might be possible to supply 5V for the relays (JD-VCC) and 3.3V for the logic (VCC) - but only if you had been sent that version of the board :( I think it would be worth asking the supplier for the schematics - ideally for both versions of the board so we can play spot the difference.

I shot off an email to them indicating when I got the old board and asked for the schematics on both. I also explained what I was seeing with the "mixed" 5V power + 3V3 signal, just in case they immediately know if that's just the way it is or not.

Try experimenting with the relay board to check how reliable it is running at 3.3V - you might find it is OK for you. You could try some simple tests like turning on all the relays at the same time and verifying that they all come on. (The large current drawn by all relays being on together might make the power supply reduce such that some of them don't turn on fully.) When checking, don't trust the LEDs, check that the relay contacts have really closed.


Well, it made it through the first 3 no problem. Then it started acting strangely. Note that I do not have anything else actually hooked up to the relay - I'm 1) looking at the LEDs and 2) listening for the very noticable "click" when it toggles on and off.

Turning on the 4th one - it still clicked, but it was a much softer click. Turning on the 5th got no click at all (the LED turned on though). Strangely, turning on the 6th yielded a "strong" click again. The 7th was a "weak" click, then the 8th was strong again.



Actually, did some more testing as I was writing this. It turns out that 5th one doesn't seem to turn on at all (even if I turn off most of the others). I wonder if that relay is bad. That or it just isn't responding well to the 3V3.

The other side of this - my application is a irrigation controller. I don't have enough water pressure to turn them all on at once anyway!

#6 Cabadam

Cabadam

    Advanced Member

  • Members
  • PipPipPip
  • 90 posts

Posted 18 February 2012 - 11:50 PM

So I went down the row testing all of the relays individually (rather than trying to turn all of them on at the same time). I connected gnd/vcc (3V3), set digital output 0 to false, and went down the row touching each relay "IN" pin. IN4 and IN7 do nothing. The others all toggle (some louder than others). I moved the VCC over to 5V and repeated the test. This time all 8 toggled (including IN4 and IN7). Let me see if I understand this right. The relay is expected that anything near 5V is "off". Or more specifically, anything near the VCC voltage. But when that is 5V, the 3V3 isn't high enough for whatever the mechanical threshold is, so as far as the relay is concerned, 3V3 might as well be 0 (or is it -5? Knew I should have paid more attention in my electrical engineering class...)? So they just get 'stuck on' when I provide 5V.

#7 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 19 February 2012 - 05:22 PM

Sorry its taken so long to answer Adam.

I just did a Google search for "SainSmart + schematic" and I found this page that has a schematic for a four channel relay board. The picture is different from the one you linked to on Amazon, but I think it explains what is going on:
http://www.hoyasourc...92p9eaa2pt55p32

This schematic only has one Vcc connection (+5V).
Vcc is connected to the emitter of a PNP transistor (the leg with the arrow). When the base (the leg connected to the resistor) is pulled down by around 0.7V below the emitter, the transistor will turn on and allow current to flow from the emitter (Vcc) to the collector which is connected to the relay and LED.
If the base is left unconnected, or if it is pulled up close to 5V, the transistor will turn off and this will stop current flowing into the relay and LED.

If we assume that this is the same design as your board, I think the symptoms you reported would all be the same.
When the relay board Vcc is powered with 5V, setting any of the inputs to 3.3V (the maximum from the Netduino), the base of the transistor will see a voltage that is 2.7V less than the emitter, and this will turn on the transistor. So no voltage from the Netduino is high enough to turn off the transistor.

But, I think you can solve the problem by using a TristatePort instead of the normal OutputPort.
When you want to turn on a relay, set the pin to an output with logic zero - this will pull the output low and turn on the transistor as before.
When you want to turn off a relay, set the pin to an input (with ResistorMode.Disabled), this will cut off the path for the current and the transistor should turn off.

I'm afraid I have not used a TristatePort before, but from reading the class definition on the link above, it looks like you set port.Active = true to make the pin an output, and set it false to make it an input.
I am guessing that you can set the pin to logic zero as normal port.Write(false)

Doing this, I am hoping that it should be possible to run the relay board Vcc at either 5V or 3.3V, rather than just at 3.3V as you have been forced to do so far. Once you can use 5V, the relays will be much more reliable.

See if this helps - Paul

#8 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 19 February 2012 - 05:47 PM

I forgot to mention that the relays may still turn on unexpectedly when the Netduino resets or turns on. This is because it sets all IO pins to inputs and enables weak pullup resistors on them at reset/power on. Assuming that using TristatePort works, the reset problem would be solved by adding a pullup resistor between 5V and each relay input. something around 5K to 10K ohms should do the trick. Paul

#9 Cabadam

Cabadam

    Advanced Member

  • Members
  • PipPipPip
  • 90 posts

Posted 19 February 2012 - 05:59 PM

Haha, this is almost too simple (now that I see the answer anyway!). Almost any current coming out of the ND is considered "low" the relay, so it turns on. Cut the current (set the port to inactive) and it turns off. Seems simple enough. After moving to VCC to 5V that is.

I ran the following small test program in the debugger, stepping one line at a time:
TristatePort port = new TristatePort(Pins.GPIO_PIN_D0, false, false, Port.ResistorMode.Disabled);
port.Active = true;
port.Active = false;

Before the first line executes (as the ND boots up), as you suspected the relay turned on. Except... it didn't. The LED turned on, but there was no "click."

First line executes - apparently by default the TristatePort is set to be Active=false. Convenient for me! The LED turns off (still no click, confirming the relay really wasn't on).
Second line executes, port goes active. Relay LED turns on, very audible click.
Third line executes, port goes inactive. Relay LED turns off, very audible click.

I essentially just replace my port.Write calls with port.Active calls (after converting to TristatePort).

So on bootup, all the LEDs will turn on, but the relay won't actually do anything (I actually haven't tried with them all connected yet, will do shortly). I'll just consider it a status indicator on boot up that my ND is still wired correctly into the relay. If a light doesn't come on briefly on boot, I know I won't be turning that relay on.

The only part that makes me somewhat nervous is the LEDs on startup. Can I trust that it will "never" trigger the relays?

Comparing this behavior to the OutputPort with 5V:
On bootup the LED turned on (no click).
Create the output port, relay clicks (LED stays on). Stays in this state regardless of what I actually output (true/false).

#10 Cabadam

Cabadam

    Advanced Member

  • Members
  • PipPipPip
  • 90 posts

Posted 19 February 2012 - 06:15 PM

Wanted to update this after having tested with all the relays wired up. Behavior is the same as with just the one I tested with before. On startup, all the LEDs turn on, but the relays themselves do not actually power on. Creating the TristatePort turns off the LEDs. Setting the TristatePort active turns on the LED and relay. Setting the TristatePort to inactive turns off the LED and relay. Thanks so much for your help in getting this to the next step. The TristatePort was a great idea.

#11 Cabadam

Cabadam

    Advanced Member

  • Members
  • PipPipPip
  • 90 posts

Posted 19 February 2012 - 06:21 PM

And just to confirm - I've gone through a few reboots now, and randomly I can hear one of the relays actually trip on. Good thing I moved on with ordering that breadboard that I don't have yet. I'll get the resistors you mentioned and try introducing them into the mix. Thanks again!

#12 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 19 February 2012 - 07:44 PM

Before the first line executes (as the ND boots up), as you suspected the relay turned on. Except... it didn't. The LED turned on, but there was no "click."

Spooky :unsure:
Maybe the Netduino weak "pullup" resistor is not allowing enough current to flow through the transistor to power the relay coil on. The transistor is a current amplifier - so the more current that flows from the emitter to the base, the more that can flow between the emitter and the collector. When interfacing to large loads, we usually use them with a large base current that is guaranteed to turn the transistor fully on. Perhaps its a combination of the weak resistor in the Netduino limiting the current, and the fact that the voltage will be 3.3V not Gnd.

(I see that in you later post you found that the relays do sometimes come on - so this needs sorting.)

A lot of people have had an issue with the Netduino power on / reset behaviour causing connected devices to burst into life unexpectedly. (I'm not blaming the Netduino - it is only doing what is sensible.) I hope that the additional resistors solve the issue of the LEDs (and sometimes relays) coming on at power on.

Do consider adding a Wiki page with what you know - I think this family of relay boards will be useful to others.

Thanks so much for your help in getting this to the next step. The TristatePort was a great idea.

Your welcome - glad I could help.

#13 Cabadam

Cabadam

    Advanced Member

  • Members
  • PipPipPip
  • 90 posts

Posted 20 February 2012 - 03:32 AM

Do consider adding a Wiki page with what you know - I think this family of relay boards will be useful to others.


Definitely. I'll probably hold off though until I get the resistors into this and hopefully that resolves the remaining quirk.

Thanks,

#14 Arbiter

Arbiter

    Advanced Member

  • Members
  • PipPipPip
  • 132 posts
  • LocationBrisbane, Australia

Posted 20 February 2012 - 09:19 AM

I've been using the relay kit from Jaycar. Switching current is less than a milliamp, it's happy at 3.3V and it can switch up to 30A DC. For low power stuff I also use the 4-relay board from Little Bird Electronics with great success.
One day, all this too shall parse.

#15 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 20 February 2012 - 09:34 AM

Arbiter, do the relays on these boards all turn on when the Netduino reboots / powers on? Paul

#16 Arbiter

Arbiter

    Advanced Member

  • Members
  • PipPipPip
  • 132 posts
  • LocationBrisbane, Australia

Posted 20 February 2012 - 09:37 AM

we usually use them with a large base current that is guaranteed to turn the transistor fully on. Perhaps its a combination of the weak resistor in the Netduino limiting the current, and the fact that the voltage will be 3.3V not Gnd.

(I see that in you later post you found that the relays do sometimes come on - so this needs sorting.)

A lot of people have had an issue with the Netduino power on / reset behaviour causing connected devices to burst into life unexpectedly. (I'm not blaming the Netduino - it is only doing what is sensible.) I hope that the additional resistors solve the issue of the LEDs (and sometimes relays) coming on at power on.

Do consider adding a Wiki page with what you know - I think this family of relay boards will be useful to others.


Your welcome - glad I could help.


You could use an NPN transistor and a PNP transistor with appropriate biasing to get high trigger impedance and guaranteed saturation switching. It would certainly be educational. Or you could use an op-amp, if you don't want a high current. You also need protection from over-voltage and reverse voltage. Like many things, it's easy to do this badly and quite a bit harder to do it well. A good way to learn would be to get a kit like this http://www.jaycar.co...w.asp?ID=KC5434 and figure out what all the components do. That particular circuit is simple but thorough, with clever use of opto-isolation to achieve both protection and very low trigger current.
One day, all this too shall parse.

#17 Arbiter

Arbiter

    Advanced Member

  • Members
  • PipPipPip
  • 132 posts
  • LocationBrisbane, Australia

Posted 20 February 2012 - 09:42 AM

Arbiter, do the relays on these boards all turn on when the Netduino reboots / powers on?
Paul


The Jaycar relays do. I'll have to check with the 4-relay board. If you want to inhibit switching during power up you first need to decide whether you want high-side or low-side switching, and then put either pull-up or pull down resistance on the switching side through a high value cap.

Even that may not produce a long enough delay, in which case you can use a 555 in monostable configuration (one-shot).
One day, all this too shall parse.

#18 Cabadam

Cabadam

    Advanced Member

  • Members
  • PipPipPip
  • 90 posts

Posted 21 February 2012 - 12:38 AM

I've been using the relay kit from Jaycar. Switching current is less than a milliamp, it's happy at 3.3V and it can switch up to 30A DC. For low power stuff I also use the 4-relay board from Little Bird Electronics with great success.


Unfortunately, the Jaycar one doesn't indicate it can switch the 24AC I need for this particular project. The shield looks tempting, although I don't have a way to power it's 9V source at the moment (and I also need 9 total relays).

I'm still sorting out how to power things though. Right now it is something like:

Main -> 24VAC Transformer -> Splits here ->
- Sprinkler valves (what the relay is actually controlling)
- 24VAC to 12VDC regulator -> WiFi Bridge -> Netduino -> (5V) Relay

Right now the relay is being powered off the Netduino, but I was also planning ultimately to add a LCD to the mix.

Due to the combined current requirements of the relay and LCD, I was considering breaking them off and powering them external to the Netduino, probably off of the 24VAC transformer as it has the highest rating (50VA, the 24VAC to 12VDC has 1500mA).

One of my end goals was to keep whole system powered via a single wall plug (currently the 24VAC transformer). Although, I'm still trying to sort out the components I'll need to make that happen. I'm mostly trying to look at premade boards because I don't really trust my circuit-building skills enough to handle the power connections and not screw something up and toast something.


On a related note, I got the specs and schematics on the "newer" version of the relays I am using. I found this very interesting:
Input control signal voltage:
0V - 0.5V Low stage (relay is ON)
2.5V –5V High state (relay is OFF).



If that is true, and it is different from older variant of the board I have, this means it should work fine with the 3.3V signal lines coming from the Netduino. It also means that it should handle the boot-up case since the Netduino is using a pull-up resistor to get it up to 3.3V.

I emailed them back asking them to confirm this (I'll also know for sure once I receive the new 2-channel one I ordered). If that really is the case, then I might order a new 8-channel one to replace the older 8-channel one. That should allow me to connect it straight in via the Netduino without needing external hardware on the signal lines. *crosses fingers*

I've attached the schematic if anyone wants a read over. Full specs are:

Size: 138 x 56 x 20mm
Power Supply: 5V DC / 400mA (relay all ON)
Input control signal voltage:
0V - 0.5V Low stage (relay is ON)
2.5V –5V High state (relay is OFF).
Input control signal LOW state current:
2.5V: 0.1mA.
3.3V: 0.18mA.
5V: 0.35mA.
JD-VCC or VCC: Power supply input, 5V DC. (JD-VCC RELAY POWER VCC:SYSTEM VCC)
GND: Power supply ground and control signal ground.
CH_x: Control signal input, Low: relay ON, High: relay OFF.
COM / NO / NC: (C1=COM1, C2=COM2)
Control signal state low, the relay ON, COM - NO disconnected, COM - NC connected.
Control signal stage high, the relay OFF, COM - NO connected, COM - NC disconnected

Attached Files



#19 Cabadam

Cabadam

    Advanced Member

  • Members
  • PipPipPip
  • 90 posts

Posted 21 February 2012 - 01:54 AM

And they just responded - the ability to take 3.3V control signal IS a change from the original version. Hopefully that will be confirmed when I receive the new 2-channel one!

#20 Cabadam

Cabadam

    Advanced Member

  • Members
  • PipPipPip
  • 90 posts

Posted 28 February 2012 - 01:22 AM

And they just responded - the ability to take 3.3V control signal IS a change from the original version. Hopefully that will be confirmed when I receive the new 2-channel one!


Short update - I've received the new 2-relay board. Works fine. I power it via 5V into the JD-VCC. The VCC next to the IN1/IN2 gets 3.3V. And everything works great. I'll start working on a wiki page for it.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.