element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Raspberry Pi Forum Raspberry Pi GPIO Control
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
Raspberry Pi Wishlist
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 39 replies
  • Subscribers 681 subscribers
  • Views 7431 views
  • Users 0 members are here
  • raspberry
  • gpio
  • raspberry_pi
  • raspberrypi
Related

Raspberry Pi GPIO Control

Former Member
Former Member over 12 years ago

I saw a picture on flickr, which interests me vey much. I want to make a same one, as I want to learn some more about GPIO control.

I got the raspberry Pi and this exact 8 channel relay. How can I do the wire up? There are many cables, I am a bit confused,

image

  • Sign in to reply
  • Cancel
Parents
  • pjc123
    pjc123 over 12 years ago

    Why didn't you buy the board that the flickr site told you that they used?  Unless you made a mistake, your "This exact 8 channel relay" url that you point to is a 12V 16 Channel relay board and is the wrong relay board.  You should have bought the 5V version, not the 12V version, so it works with the pi (Unless you absolutely needed 16 channels instead of 8 and planned on getting an additional 12v power supply.  Here is the proper board:

     

    http://www.sainsmart.com/8-channel-dc-5v-relay-module-for-arduino-pic-arm-dsp-avr-msp430-ttl-logic.html

     

     

    I have many very detailed threads regarding the operation and hookup of this relay on the raspberry pi site (See user pjc123) including theory, current requirements, hookup, etc.  I have been using it for several months now, and it works perfectly if hooked up properly.  A person recently drew up a very nice and extremely easy to follow diagram on how to hook it up, of which I have added a couple of enhancements.  There are also a couple of threads on how to hook it up with a darlington pair IC instead of a transistor if you so desire.  Be careful of the advice that people may give you regarding this board as there are variants from other manufacturers that do not operate the same.  The following specifically applies to the Sainsmart 8 channel 5V Relay module, part # SKU:20-018-102.

     

    Here is the hookup diagram:  EDIT:  As I indicated in the following thread, do not power the raspberry pi through the test points as noted in this person's diagram, because doing so bypasses the raspberry pi's main fuse (Unless you are adding your own protection device).  Power the raspberry pi the normal way through the microusb port instead.

     

    http://www.raspberrypi.org/phpBB3/viewtopic.php?f=44&t=36225

     

     

    There is also a solid state version of the above board but it is for AC loads not AC/DC loads like the relay board.  Also, it can not handle the higher current load of the relay board.  The relay board can handle a 10 amp load, while the solid state version can only handle 2 amps.  However there are some advantages to the solid state version.  People have indicated that it does not need a transistor or darlington pair on the front end and can be driven directly from the 3.3v signals of the GPIO ports.  Also, the current draw of the coils on the relay board are 60ma each and require an external 5v power supply to drive the coils if you plan on using more than a couple of relays simultaneously;  this is not an issue with the solid state version.  Disclaimer:  I have not used the solid state version and can only speak for what others have claimed.  Also, I have not seen detailed hookup diagrams for it:

     

    http://www.sainsmart.com/8-channel-5v-solid-state-relay-module-board-omron-ssr-4-pic-arm-avr-dsp-arduino.html

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 12 years ago in reply to pjc123

    Hi,

     

    You guys seem to be pro at the RPi and relay control.

    Can you guys offer some tips as to how I would control this 12v relay from it?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • mcb1
    mcb1 over 12 years ago in reply to Former Member

    Personally

    I'd be asking Sainsmart for some info as their document page is empty.

     

    It hints at needing a 15-20mA driver, but the picture shows some logic chips on board.

     

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • gdstew
    gdstew over 12 years ago in reply to mcb1

    It hints at needing a 15-20mA driver, but the picture shows some logic chips on board.

     

    They look like opto-isolators to me. There are very few if any 4 pin logic chips in DIP packages that I am aware of.

     

    3.3V logic outputs will work with TTL compatible inputs (2.4V min. logic high). They will not work with CMOS inputs (40xx, 74HCxx)

    when they use a 5V supply.

     

    Edited to add:

     

    NOTE:

    If a TTL compatible input is tied to +5 through a pull up resistor it is not a good idea to connect it to a 3.3V output. If the

    ICs on the relay board are opto-isolators then I suspect the anode of the IR LED in the opto-isolator is connected to

    +5V through a current limiting resistor and it would NOT be a good idea to connect this directly to a RPI output.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 12 years ago in reply to mcb1

    I need a 12v relay to use with this 12v solenoid

     

    Could you offer an alternative 12v relay board?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • mcb1
    mcb1 over 12 years ago in reply to Former Member

    No you don't.

     

    You need a relay that is capable of switching a 12v load at whatever current the solenoid draws.

     

    Any 5v relay that has 2Amp contacts should be fine to switch this solenoid.

     

     

     

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • mcb1
    mcb1 over 12 years ago in reply to gdstew

    gary

     

    Sorry I should have replied earlier.

     

    My browser only showed the 18pin devices, so I didn't see the optos, or the multi pin connector and incorrectly assummed it had logic.

    (Once I viewed it at work on IE, it showed up, but I can't reply from there)

     

    Having said that, there is little or no useful information on the page to help users, (unless you consider a drawing of the voltage regulator as useful).

     

    I also have concerns about why an opto-coupled device needs 15-20mA to drive it, when they are using something else to physically switch the relay.

    I would have thought 1-2mA or 3-4 at the worst should be enough to control them

     

     

    Mark.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • mcb1
    mcb1 over 12 years ago in reply to gdstew

    gary

     

    Sorry I should have replied earlier.

     

    My browser only showed the 18pin devices, so I didn't see the optos, or the multi pin connector and incorrectly assummed it had logic.

    (Once I viewed it at work on IE, it showed up, but I can't reply from there)

     

    Having said that, there is little or no useful information on the page to help users, (unless you consider a drawing of the voltage regulator as useful).

     

    I also have concerns about why an opto-coupled device needs 15-20mA to drive it, when they are using something else to physically switch the relay.

    I would have thought 1-2mA or 3-4 at the worst should be enough to control them

     

     

    Mark.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
  • gdstew
    gdstew over 12 years ago in reply to mcb1

    Hi Mark,

     

    I found a "schematic representation" for one of the eight relay channels in the pictures on the link provided in the original post. I started to post the

    picture here but was unsure of the copyright so I decided not to.

     

    If this is accurate then it looks like they are driving two LEDs in series, one in the opto-isolator and a state indicator LED on the board so the

    15 - 20 mA is reasonable. It also shows an independent VCC supply source for the LEDs so it should be able to use 3.3V to make it compatible

    with the RPI GPIOs. However the RPI itself can not supply enough current on 3.3V (50 mA max) for all the relay drivers so a seperate power supply

    would be needed. My concern is that the electrical characteristics of the GPIO pins are poorly documented although I found one source on the web

    that says they are capable of sinking 16 mA:

     

    http://www.mosaic-industries.com/embedded-systems/microcontroller-projects/raspberry-pi/gpio-pin-electrical-specifications

     

    This is still cutting it too close for me without knowing the value of R1 in the "schematic" or being able to test it first.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • johnbeetem
    johnbeetem over 12 years ago in reply to gdstew

    Gary Stewart wrote:

     

    My concern is that the electrical characteristics of the GPIO pins are poorly documented although I found one source on the web  that says they are capable of sinking 16 mA...

    The RasPi GPIOs are IMO pretty well documentated at the RasPi Hardware Wiki, which includes a link to a more detailed document showing how to set GPIO source/sink current between 2 and 16 mA.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • gdstew
    gdstew over 12 years ago in reply to johnbeetem

    John,

     

    I went to the hardware wiki web page (I have it bookmarked) but missed the current ratings. The link I gave says the same thing. However the link to the

    GPIO Datasheet Addendum on the hardware wiki page does not say how much current they will sink, only how much they will source. Directly copied from

    that site (emphasis is mine):  "If the drive strength is set low(000) most of these are tri-stated so they do not add anything to the output current", and the word

    sink does not appear on that page so this is still not properly documented. Looking at the "schematic" on the relay board web page the opto-isolator driver

    (GPIO pin) needs to sink between 15 and 20 mA.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • pjc123
    pjc123 over 12 years ago in reply to gdstew

    gdstew,

     

    This thread is getting a bit convoluted as some people are talking about 5V relay boards and others 12V relay boards, but if you are talking about the 5V based version of the Sainsmart 8 channel relay card, the 15-20ma specification is a complete and utter error.  It takes about 2ma (I have measured this with a meter) to activate the opto portion of the relay card (This value also seems reasonable by just looking at the schematic.  opto, LED, and yes the key missing value of the resistor which is 1k (measured with a meter) ).  In addition, it takes about 60ma (measured with a meter) to operate each coil.  You will need a separate power supply other than the pi's, as I use, if you plan to operate all relays simultaneously (60ma X 8 = 480ma), especially if you have power hungry usb devices also attached to your pi.  A Vcc of 3.3V will not reliably work; I have verified this as others have as well.  Sometimes it trips the opto, sometimes it does not.  Recently someone changed the resistor value on the relay board so you can drive it with a Vcc of 3.3V instead of 5V, so that is an option.  I am not going to get into a discussion about the following as it has been beaten to death on the raspberrypi.org forums (your choice about what you want to do), but I would not sink the Vcc of 5V into a 3.3V based device.  Yes it will probably work, for how long is anyone's guess.  Actually, 5V or 3.3V Vcc, there is still the chance that you could send a HIGH instead of a LOW through the GPIO port by mistake, and power both ends of the opto circuit.  I also believe an active LOW circuit is completely !$#-backwards.  Therefore I suggest either putting transistors or a darlington pair ic between the GPIO outputs and the relay board opto inputs.  Doing so and all these issues completely go away.  I use transistors and have been running this way for almost a year now;  see my earlier post in this thread for where to find further discussions of these issues.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • johnbeetem
    johnbeetem over 12 years ago in reply to gdstew

    Gary Stewart wrote:

     

    John,

     

    I went to the hardware wiki web page (I have it bookmarked) but missed the current ratings. The link I gave says the same thing. However the link to the

    GPIO Datasheet Addendum on the hardware wiki page does not say how much current they will sink, only how much they will source. Directly copied from

    that site (emphasis is mine):  "If the drive strength is set low(000) most of these are tri-stated so they do not add anything to the output current", and the word

    sink does not appear on that page so this is still not properly documented. Looking at the "schematic" on the relay board web page the opto-isolator driver

    (GPIO pin) needs to sink between 15 and 20 mA.

    Since Gert doesn't distinguish between source and sink current, I think he means that the current spec is the same for both pulling up (source) and pulling down (sink).  Since these are CMOS drivers, NFETs are usually stronger than PFETs so usually the sink current is at least as strong as source current.

     

    Gert elaborates that by 16 mA he means that you can source or sink 16 mA and still meet the output voltage specs.  But then he lists the input voltage thresholds, which are not the same as the output levels or you won't have any noise margin.

     

    With any chip that has lots of I/Os, you do have to be careful of simultaneous switching.  For example, if lots of outputs start to sink a lot of current simultaneously you can get ground bounce.  However, I would suspect that pjc123 is correct and you don't need to source or sink 15-20 mA from each pin -- perhaps a total of 15-20 mA is what they meant.

     

    You should probably use a relay board with a published schematic (or sufficient reliable on-line discussion) so you can do your own analysis.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • gdstew
    gdstew over 12 years ago in reply to johnbeetem

    Since Gert doesn't distinguish between source and sink current, I think he means that the current spec is the same for both pulling up (source) and pulling down (sink).

     

    I would prefer a real spec rather than speculation as to what Gert ment. Since Gert did not mention sink current and I'm sure he understands the difference I would prefer not

    to assume they are the same.

     

    Since these are CMOS drivers, NFETs are usually stronger than PFETs so usually the sink current is at least as strong as source current.

     

    Yes that is normally true however I would still prefer to see a real spec rather than speculation.

     

    But then he lists the input voltage thresholds, which are not the same as the output levels or you won't have any noise margin.

     

    Gert was clearly talking about the voltage drop on the output pin not meeting the input threshold spec when it is trying to supply more current than it was designed for.


    However, I would suspect that pjc123 is correct and you don't need to source or sink 15-20 mA from each pin -- perhaps a total of 15-20 mA is what they meant.

     

    Edited:

     

    That is not what is specified by the maker of the relay board. They clearly state that each driver input needs 15 to 20 mA although that does seem too high to me.

    If each of the 8 inputs uses ~2 mA for the LEDs then 15 - 20 mA total is probably about right.

     

    http://www.sainsmart.com/8-channel-dc-5v-relay-module-for-arduino-pic-arm-dsp-avr-msp430-ttl-logic.html

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • mcb1
    mcb1 over 12 years ago in reply to johnbeetem

    John Beetem wrote:

     

     

    You should probably use a relay board with a published schematic (or sufficient reliable on-line discussion) so you can do your own analysis.

     

    It is a shame the Sainsmart don't actually show the necessary information. One of their links points to an ebay seller.

     

    We have continually tried pointing Posters to sites that have documentation so that they can ask the supplier ... maybe we need to stop answering until Sainsmart pull their finger out?

     

     

    pjc123

    Your observations are more in line with what I expected.

    Your method using a transistor (with series resistor between GPIO pin and base ....for those others reading this) is the perfect solution.

     

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 12 years ago in reply to johnbeetem

    There is indeed no noticeable difference between source and sink current. Modern silicon is not like the old days where it could sink a lot more then source.

    One of the reasons is that there is not one transistor/FET anymore. There are a many in parallel. Thus if you want balance you just put a few more in parallel to get symmetrical behaviour.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube