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 Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • 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
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • 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 671 subscribers
  • Views 5754 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
  • Former Member
    Former Member over 12 years ago

    Dear Eleen:

     

    First, look at http://elinux.org/RPi_Low-level_peripherals

     

    This site tells you how the GPIO pins are wired on the Raspberry Pi. Then google "webiopi" (Web I/O Pi) to see the Python source code for a web interface to turn those GPIO pins on and off.

     

    Next, make a diagram of the pins on the GPIO header and the pins on the relay board and match up the pin names one at a time.

     

    Before you connect anything up, read about TTL voltage levels and make sure you understand 3.3V vs 5V interfacing as connecting the wrong wires leads to more problems, so study is important at this stage.

     

    Charles

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

    Looking at the pic it seems like they've got an RTC, unecessary for  the relay, a Pi Cobbler from adafruit and a level converter which you can also get from adafruit. The nice thing about those relays is you drive them to ground to activate, but it is still probably a good idea to isolate your pi from the relay board.

     

    But follow the advice from Charles and look at those resources. You will find that the circuit pictured is pretty easy to replicate.

     

     

    Mike

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

    Eleen

    That relay board you linked to is unlikely to work, without something between the Pi and the relays.

     

    The board states it requires 15-20mA to control the relays, but a reviewer found it was 3.8mA.

    However it uses 5v and is derived by a regulator from the 12v required to run the relays.

    The GPIO is 3v3, so you will need something else between the Pi and the relays.

     

    The picture appears to show an opto-coupled relay board, which has a better chance and is isolated.

     

    These only require 2mA to control these and are available in 2,4 or 8 relays.

    http://yourduino.com/sunshop2/index.php?l=product_detail&p=218

     

     

     

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • 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

    Thank you, pjc123

     

    I did make a mistake in the link to the relay board. SainSmart has so many different kinds of relays, I was a little confused.

     

    I was meaning to asking the wire up between the RPi and http://www.sainsmart.com/8-channel-dc-5v-relay-module-for-arduino-pic-arm-dsp-avr-msp430-ttl-logic.html

     

    Thank you for the detailed reply and pointing out the hookup diagram.

     

    I also want to figure out a different hook up, in stead of using a breadboard, the wire up should be like this:http://www.youtube.com/watch?v=rbkoJQEUt60

     

    The video includes a document on how to build the RPi with the relay. https://github.com/fixedd/RPi_SainSmart_Interface

     

    I am having fun with the tinkering

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

    Glad to help.  Since my post, I moved my circuit from the breadboard to a circuit board, but since I am doing this just one time, rather than make or have someone make a printed circuit board I just used a pre-made circuit board and used wires to connect everything.  However, it would be a good learning experience for you to make your own pcb board, and it is nice not having to do all that wiring.

     

    I used the following BPS model BR1 solderable PC breadboard:

     

    http://www.busboard.us/pdfs/BPS-MAR-BR1-001.pdf

     

     

    I don't know if you are going to use the examples shown in the tutorial to write code for the relay or what, but there are various libraries written to control the GPIO ports.  I am using the first one, which is based on the "C" programming language:

     

     

    C:

     

    http://www.airspayce.com/mikem/bcm2835/index.html

     

    https://projects.drogon.net/raspberry-pi/wiringpi/

     

    http://quick2wire.com/2012/05/safe-controlled-access-to-gpio-on-the-raspberry-pi/

     

     

     

    PYTHON:

     

    https://pypi.python.org/pypi/RPi.GPIO

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

    Maybe you have already solved your problem, but I thought your might be interested in this: http://www.reddit.com/r/raspberry_pi/comments/19x4wp/how_to_wire_a_raspberry_pi_to_a_sainsmart_5v/

     

    http://i.imgur.com/4HzhwYB.jpg

    What you’ll need/What I used:

    • Raspberry Pi Model B (Rev 2.0)
    • Sainsmart 8-channel DC 5V Relay Module (Got mine for $12 on Amazon)
    • Some jumper wires. I used some 5” ones and some 3” ones from Radio Shack. These also come with header pins which I used. The product descriptions say 10.3” and 10.5”, but the 10 is quantity... confusing.
    • +5V power supply. The Raspberry pi requires up to about 500mA, and each relay requires about 72mA (total: ~1.1A for 8 relays), so be sure to chose a supply capable of 1.5A or more to leave a little headroom.
    • 2.2k ohm +/-5% resistors (color code: Red red red - gold). You’ll need one for each relay you plan to operate.
    • 10k ohm +/-5% resistors (color code: Brown Black Orange - Gold). You'll need one for each relay you plan to operate.
    • Some NPN transistors. I used some 2N222’s from Radio Shack (bag of 15 for $3.49). You’ll need one for each relay.
    • A small project circuit board. I used one from Radio Shack like this.
    • A terminal/barrier strip like this (not shown in photo). I cut the small plug off the end of the power supply leads, stripped the wires, and added some crimp-on spade connectors to attach them to the barrier strip. This will allow me to remove the power supply if necessary. I will also connect the 24V sprinkler supply to this barrier strip. Eventually I plan to run everything with the 24V supply (hopefully), but haven’t figured out a circuit to [efficiently/safely] reduce 24V to 5V to run the RPi and Relay Board. If anyone has any ideas, please let me know.

    Things to note:

    • The diagram only shows 4 GPIO pins connected to the relay module... that’s just because I am only using 4... connecting additional pins/relays would work exactly the same way.
    • I opted to not use the micro-USB port to supply power to the Pi, and instead soldered some header pins to TP1 and TP2 to provide +5V and GND respectively. This avoided having to cut/splice a USB cable and made for cleaner wiring. The header pins came with some jumper leads I bought at Radio Shack that I used to make all the connections. The header pins are a pain to solder if you're only doing one at a time. I had a spare 5V 2.0Amp Wall-wart charger laying around, so I used that to power everything instead of having a supply for the RPi, a supply for the relay module, and another supply for the sprinkler valves.
    • I used +5V to power the relays and the opto isolators by connecting 5V from the supply to VCC on the 10-pin header and then using the supplied jumper between VCC and JDVCC on the 3-pin header.
    • On the relay board, there are two VCC pins and two GND pins. The VCC pins are electrically identical, as are the GND pins, so you only need to connect to one (each) of them.
    • !!!!!!! GPIO pins are slightly different on Rev 1.0 and Rev 2.0 boards !!!!!!! Also, there are different numbering schemes depending on which programming library you plan to use to control the GPIO pins (Either BCM or Wiring Pi).
    • The Sainsmart relays are "active low", which means that instead of turning on when they get a 3.3V signal from a GPIO port, they turn off... This is contrary to what you would think (or would want). In any event, you need a way to translate the high (3.3V) output of the GPIO pin to 0V for each input of the relay board. This is done using a 2.2kohm resistor and an NPN transistor. I used 2N222 transistors from Radio Shack (got 15 of them for ~$3.50 US). A voltage at the base of the transistor effectively shorts the relay input to ground (0V) turning the relay on.
    • Each relay has 3 terminals which I’ve labeled A, B, and C in the diagram. While “active”, each relays’ A and B terminals are connected, and while “inactive”, B and C are connected. A and C are never electrically connected. For a sprinkler system, you would probably want to connect +24V (or whatever voltage your sprinkler valves/whatever require) to each “A” terminal, and then connect the lead for each sprinkler zone to the “B” terminal. You will also need to connect the common wire of your sprinkler wiring to the ground terminal of your 24V supply.
    • I used the long traces in the middle of the project circuit board as power/ground busses, although that’s not shown in the diagram. I grounded the emitters of the transistors to the ground bus. I also soldered some header pins to the busses as a means of distributing power to the RPi and Relay Module.
    • 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
>
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