Relay modual where GND turn on relays how to hook up to transistor? - Page 1
Forum section: electronics / beginners

author: Beamin
author_rank: Super Contributor
timestamp: October 20, 2017, 07:23:42 pm
content: I got these Chinese relay modual that have 4 inputs GND CH1 CH2 and VCC.When you power it up the relays stay open when you hook the ground of the power supply to CH 1 or 2 it activates the relays.So if I want to use these with an Arduino do I need to build some sort of voltage divider circuit to use them? Whats strange is that when GND in not connected to CH1 nothing happens but when GND is connected the relay turns on. Shouldn't this configuration turn on when there is No connection as well? It appears to have two of those opto isolators on the board.If I have an Arduino connected the out put has high or low. How does this board know the difference between low and no connection?What if I wanted to control it with transistors would I need jfets?

author: KMoffett
author_rank: Regular Contributor
timestamp: October 20, 2017, 08:08:18 pm
content: Please post a link to the module for spec's. NPN transistor or logic level Mosfet. Collector (drain) to CH1 or CH2 and emitter (source) to ground. Resistor from transistor base to Arduino I/O. No gate resistor needed for Mosfet. I/O high turns on module relay.Ken

author: Beamin
author_rank: Super Contributor
timestamp: October 20, 2017, 09:39:11 pm
content: Quote from: KMoffett on October 20, 2017, 08:08:18 pmYeah I don't have any info about it. I bought it online with some broken English about "100% happy technetium good product to use our product"The relays work off 5 volts; has dual optos and two resistors on the circuit board which is black so it's no help. I tried reversing the polarity and my psu just cuts off with a over current limit fault.

author: frog
author_rank: Contributor
timestamp: October 20, 2017, 10:02:31 pm
content: Essentially from what you are saying, one end of the relay coil is connected to 5v all the time, and when you connect the GND terminal to GND it completes the circuit and operates the relay - have I got that right?So if you want to switch this with an Arduino you may be able to do so directly (if it's opto isolated then the Arduino IO pin may be able to supply enough current to operate it). Otherwise you'll need a transistor - either NPN bipolar or N-channel FET will do. In the case of a FET you'd connect the gate to the Arduino IO, the drain to the relay GND terminal and the source to your power supply GND. If you're using a bipolar then you'll need a resistor (about 10k) between the Arduino UI and the base, the collector goes to the relay and emitter to PSU GND.I'm not sure what voltage is applied to the 'high' side of the opto, if this is higher than 5v then *don't* try connecting directly to your Arduino, you'll definitely need a transistor. Hope that helps.

author: Ian.M
author_rank: Super Contributor
timestamp: October 20, 2017, 10:27:15 pm
content: The best, sharpest colour closeup photos you can manage (subject to the forum's 400K attachment size limit) of both sides of the board would help. Try bright oblique lighting so there is some chance of seeing the track edges under the black solder resist. We may need some measurements taken to confirm the connections, but even with black solder resist we should be able to come up with a schematic.

author: Beamin
author_rank: Super Contributor
timestamp: October 20, 2017, 11:32:12 pm
content: Reversing that jumper causes it to short. Reversing the + and- and the jumper causes the modual not to work.EDit: getting better pics

author: Beamin
author_rank: Super Contributor
timestamp: October 20, 2017, 11:36:54 pm
content: mwoar.

author: frog
author_rank: Contributor
timestamp: October 20, 2017, 11:41:28 pm
content: That looks very much like you should be able to drive it directly from your Arduino, the optos appear to have the appropriate resistors on-board and there's what looks like an additional transistor to drive the relay coil and a freewheel diode.

author: frog
author_rank: Contributor
timestamp: October 20, 2017, 11:43:35 pm
content: So you'd connect your 5V supply to VCC, GND to GND and then use the arduino to drive CH1 and CH2 low when you want to activate either relay.

author: Ian.M
author_rank: Super Contributor
timestamp: October 20, 2017, 11:56:37 pm
content: I think the header with the jumper on allows you to separate the Vdd to the optocoupler inputs from Vdd to the relays (JD-Vdd). That would let you run the optos from an Arduino and use an external supply for the relay coils.Quote from: frog on October 20, 2017, 11:41:28 pmQuote from: frog on October 20, 2017, 11:43:35 pmMaybe, maybe not. I would suggest checking the connections with a DMM on continuity. Start from IN2 and see which pin of which opto it connects to. From the same side of the same opto trace where the other pin goes to, and so on till you've figured out how R4 and LED 'IN2' are connected. Check the opto input side and the LED with the DMM on diode test (hopefully it goes up to 2V on that range) to get the polarity. I suspect they are all in series and Frog is correct, but lets prove it.Also, what's marked on the relays, what model are the optos and what are the resistor values?Caution: clearances don't look adequate for mains use - I wouldn't care to use the relays for switching more than 50V AC, or their max DC V rating.

author: Beamin
author_rank: Super Contributor
timestamp: October 21, 2017, 12:04:35 am
content: So when the Arduino goes low its connecting the Arduino IO pin to ground? This has me confused as to why they don't activate with no connection AND ground state. Rather they only activate with ground but not with NC. Why would you make a device like this? Seems stupid and overly complicated for a general purpose unit. But then again I don't really understand Asian culture even though I have lived and worked with Asian people for years and my family married into Asian people. They are superstious so maybe it has something to do with bad luck.I am rereading the above post to figure out what you mean.

author: Ian.M
author_rank: Super Contributor
timestamp: October 21, 2017, 12:22:50 am
content: My suspicion is that there is the opto input LED, a resistor, and the visible indicator LED all in series, with the anode of the indicator LED to Vdd and the cathode of the opto LED to the input pin. In that case connecting an Arduino and outputting '0' would turn the relay on, and outputting '1' would turn it off. NC or Arduino pin set as input doesn't piut any current through the opto's LED so is also off. However till you do some testing, I'm just guessing.

author: frog
author_rank: Contributor
timestamp: October 21, 2017, 03:31:19 am
content: Quote from: Beamin on October 21, 2017, 12:04:35 amThe key thing to understand is that a disconnected input is not the same as a grounded input. In this case it seems likely that the other end of the opto is connected via a resistor to 5v. If the other end is disconnected then no current will flow, if it's grounded then current will flow and the relay will be activated.

author: Beamin
author_rank: Super Contributor
timestamp: October 21, 2017, 12:56:42 pm
content: So if I want to hook an Arduino to it (Arduino runs off of computer power; module runs off power supply) do I have to tie the grounds together: connect the ground pin of the Arduino to the power supply - lead then hook pin 13 (or what ever my io pin is) to the ch1 relay pin? Then alternate the pin 13 between high and low? What would happen if the ground weren't tied together would it do nothing? I'm always apprehensive about this stuff( rather just plug it in and see what happens) because I don't want to blow up my Arduino or USB port on the computer.

author: Ian.M
author_rank: Super Contributor
timestamp: October 21, 2017, 01:41:49 pm
content: Its a rather daggy design. The whole point of optocouplers is to avoid the need to join power rails and/or grounds, but that board takes both 5V and ground from the input side to the output side, making the optocouplers pretty much useless if you wire it the obvious way and leave the jumper in place. It would have been much better with a 2 pin connector for power and a 4 pin input connector with a Anode and Cathode pin for each opto allowing you to configure them as active high or active low.It does let you disconnect the 5V and the Ground isn't actually needed by the input side, so you can get isolation from it, *IF* you wire it right:Remove the jumper and connect 5V and Gnd from a PSU to the 3 pin connector outer pins, JD-VCC and GND. *DO* *NOT* connect the middle pin (VCC)..The Arduino 5V will connect to VCC on the 4 pin connector and I/O pins to IN1 and IN2. *DO* *NOT* connect GND.

author: Beamin
author_rank: Super Contributor
timestamp: October 21, 2017, 02:41:11 pm
content: Quote from: Ian.M on October 21, 2017, 01:41:49 pmConnect like this?

author: Ian.M
author_rank: Super Contributor
timestamp: October 21, 2017, 03:28:28 pm
content: No. You are linking the PSU and the arduino if you wire it as your post above.Start by removing the yellow jumper. Its worth checking on your DMM that there is near infinite resistance between all of the PSU pins and the pins going to the Arduino, to be certain I've interpreted the PCB layout correctly. Once that's confirmed, use the diagram below.N.B if you are using a high-end 3.3V logic Arduino, check that IN1 and IN2 are NOT over 3.3V on a DMM, black lead to Arduino Gnd, with 5V from the Arduino connected to VCC, *BEFORE* connecting IN1 and IN2 to the Arduino outputs. If they are, feed Vcc with 3.3V instead of 5V and confirm the relays switch properly at that input voltage when you ground IN1 and IN2.

author: Beamin
author_rank: Super Contributor
timestamp: October 21, 2017, 07:28:35 pm
content: Quote from: Ian.M on October 21, 2017, 03:28:28 pmSo that is checking to see that the relay board is not feeding 5V back into the Arduino instead of 3.3? If its feeding in 5V that will blow up the Arduino? This whole GND to turn things on is a stupid design if you ask me, but its a good way to learn how to do things(or how not to do things). So when they were creating this relay board why would they chose to have GND turn this on instead of +5V? Bad design or is there some application where this is a good idea?

author: Ian.M
author_rank: Super Contributor
timestamp: October 21, 2017, 08:13:07 pm
content: Quote from: Beamin on October 21, 2017, 07:28:35 pmThe first check is to see if the optocouplers are doing their job and isolating the relay coil drivers from the Arduino. If not, and the extra 5V PSU is grounded and the Arduino is PC powered, then yes, there is a (small) risk of damage to the Arduino and even to the PC. Its fairly minimal if the PSU ground is strapped to the PC chassis ground, but that may be impractical for compact form factor PCs, tablets and laptops.The note in italics is *ONLY* applicable if you are using a 3.3V logic Arduino. Most Atmega based Arduinos run at 5V. If in doubt, set an I/O pin to output high andmeasure it! I did forget that some low power 8MHz boards also run at 3.3V, so its not just the high end ones.Quote from: Beamin on October 21, 2017, 07:28:35 pmThey did it that way because the higher charge carrier mobility of electrons in N type silicon (v.s. holes in P type silicon) means NPN transistors and N channel MOSFETs have better specs (for the same physical dimensions and similar doping profiles) than PNP transistors and P channel MOSFETs. This means that many logic chips and MCUs can sink more current with less voltage drop when an output is driving low than they can source when its driving high. In practice, chip designers do a lot of fiddling to try and balance the performance mismatch, e.g. larger area and different geometries for the high side devices.Bipolar TTL is a special case - its particularly difficult to get a decent PNP transistor in the silicon process technologies it used, so most gates used aTotem Pole output stagewhich has very limited capability to drive high and never reaches the Vcc rail.Therefore LEDs or similar loads are usually (but not always) driven by active low logic. Sometimes other considerations dominate - e.g. logic families with little performance difference between the output levels, or for demo boards for novice student use, it may be worth trading off brightness against the need to explain inversion due to the issues above.

author: Beamin
author_rank: Super Contributor
timestamp: October 21, 2017, 10:13:21 pm
content: Quote from: Ian.M on October 21, 2017, 08:13:07 pmSo the purpose of the opto couplers is that they are running the relay coils off the five volts that powers the relay board and not your device you have plugged into it. What I never understood is if the relay board and the Arduino don't have a common ground how you run the board with just the io pins hooked up? I would think the current would have no place to go since the opto couplers are isolating the two sections.

author: frog
author_rank: Contributor
timestamp: October 21, 2017, 10:28:43 pm
content: Looking at the last photo I'd say that JD_VDD and its corresponding ground provide the power to drive the relay coils. This is all on the output of the optocouplers. The connector on the right has VCC, GND and two signals which all correspond to the inputs to the optocouplers. So unless you connect the GNDs together, the two supplies can be completely isolated.I had assumed that you were using a 5V Arduino, in which case you might as well share a supply, but if you have a 3.3v device then you'll want 3.3 on the VCC of the right-hand connector.The current paths are:VCC to opto input to GND on the right-hand connector, switched by the two control pins.JD_VDD to GND on the left-hand connector, switched by the opto outputs.I hope that helps a little.

author: Ian.M
author_rank: Super Contributor
timestamp: October 21, 2017, 11:21:45 pm
content: Errr..... not quite.Quote from: frog on October 21, 2017, 10:28:43 pmI think the relay board has one of three possible circuits - see below (only one relay and optocoupler shown). All have similar function.The input current flows from the Arduino 5V supply (or 3.3V for a low voltage Arduino) to VCC then through the opto input LED circuit (and maybe the indicator LED), then from INx back to the Arduino output pin and via the MCU to Arduino Gnd.The relay coil current flows from J1-VCC via the relay coil and transistor to GND. The transistor base current flows via the optocoupler phototransistor (output side), and comes from either VCC via a resistor and possibly the indicator LED or (#2) from the transistor collector circuit, though that would have higher voltage drop.#1 is less likely because of the two LEDs in series - it would make it less likely to work well on 3.3V logic levels. #2 may have problems pulling in the relay if JD-VDD is a bit low and the control logic needs to be able to sink more current, so I believe #3 is the most probable.In *ALL* of them there is no connection required between the Arduino supply (and Gnd) and the relay coil supply and ground.

author: frog
author_rank: Contributor
timestamp: October 21, 2017, 11:59:46 pm
content: I'd assumed that the transistors are driving the optos rather than the other way round; many of the optos I've used need several mA to switch, and an IO pin might struggle. But yes the LED and opto are most likely in series for the reasons you've stated.

author: Beamin
author_rank: Super Contributor
timestamp: October 22, 2017, 04:05:58 pm
content: better pics (posting this for 6 time because the forum is being dumb)

author: Beamin
author_rank: Super Contributor
timestamp: October 22, 2017, 04:08:28 pm
content: another (forum makes me post each one: size too big)

author: Beamin
author_rank: Super Contributor
timestamp: October 22, 2017, 04:09:58 pm
content: pic 3

author: Beamin
author_rank: Super Contributor
timestamp: October 22, 2017, 04:12:29 pm
content: amwoahrrr.....

author: Beamin
author_rank: Super Contributor
timestamp: October 22, 2017, 04:14:21 pm
content: And finally the last one damn maximum file size 60 second rule!

author: Ian.M
author_rank: Super Contributor
timestamp: October 22, 2017, 05:12:52 pm
content: So it uses 817C high CTR optocouplers, and we now have component values for all parts and a better guess at the interconnections. I've revised the schematic.To confirm the schematic, check that with nothing connected and the yellow jumper removed there is absolutely no connection between the pins the jumper was on. Use a DMM on resistance and check both ways round.Edit: Schematic revised to correct pin order of four pin connector.N.B. They really did do a poor job of designing this board. There should be absolutely no tracks under the optos and none of the input tracks should be close to the intermediate relay drive tracks. Also there is grossly inadequate clearance between the common pin of the relay contacts and the intermediate relay drive tracks.It is *UNSAFE* for use on AC mains in spite of the relay ratings. *DO* *NOT* exceed the 30V DC rating.In future, *PLEASE* photo boards against a plain white background (e.g. a sheet of paper) and crop the margins. You will reduce the file size considerably and will be able to attach multiple pictures to one post. If you don't have a photo editor consider usingIrfanView. Its JPEG save RIOT plugin is particularly useful for automatically reducing filesize to a desired limit to fit on forums.

author: Beamin
author_rank: Super Contributor
timestamp: October 22, 2017, 10:42:40 pm
content: Checked the pins with dmm all read zero. I should connect up like this image:Test Arduino is putting out 5 and not 3.3V. Out of scematics one two and tree which made one made it to the final revision? It looked like all three had resistor /bef/ore optp; rather then after wards like in the last one. This would have taken me hours to figure out on my own maybe a burnt board. Thank you eevblog! It will be doable project if a project where the blog get to vote on how it comes together. Maybe in the mean time I will cut 1cm squares 0f coffee cans into cut of blocks to make islands on them. to work on the other thread with 'rf stuff on to the next thread!

author: Ian.M
author_rank: Super Contributor
timestamp: October 22, 2017, 11:56:37 pm
content: Yes. that wiring diagram is O.K:Now you have the board's schematic to match, you should be able to see why I recommended wiring it that way.Edit: Sorry, I got Gnd and Vcc positions swapped on the 4 pin connector on the schematic. See revised schematic above.Its a variant of #1. Just rearrange the order of the series components in the opto input and output circuits.N.B. if you use the external 5V PSU to feed any sensors or other modules that directly connect to the Arduino, you loose the benefits of optoisolation. OTOH the relays provide isolation on their own.

author: ttimmer86
author_rank: Newbie
timestamp: October 24, 2017, 06:57:53 am
content: HMmM HMmMm 6 Z.Sent from my SM-G950F using Tapatalk

author: Beamin
author_rank: Super Contributor
timestamp: October 27, 2017, 08:32:11 pm
content: Quote from: ttimmer86 on October 24, 2017, 06:57:53 amNot only the best post I have seen on the topic but the best in the forum and probably the internet.When you say "6 Z" are you sure you don't mean 7X or 5Y? Based on your post count I probably shouldn't question your authority on this board. I didn't even think of trying HMmM let alone HMmM HMmMm.Also hw is the SM-G950F? Some say its a cheap Chinese rip off that break as soon as you open the box. But I see it supports tap talk.Sent from my CB-475 Chinese bot net automated spammer.