{"id":491,"date":"2019-03-30T11:14:55","date_gmt":"2019-03-30T10:14:55","guid":{"rendered":"https:\/\/next-hack.com\/?p=491"},"modified":"2020-06-05T21:18:00","modified_gmt":"2020-06-05T19:18:00","slug":"a-simple-12-channel-usb-controlled-relay-board-part-1","status":"publish","type":"post","link":"https:\/\/next-hack.com\/index.php\/2019\/03\/30\/a-simple-12-channel-usb-controlled-relay-board-part-1\/","title":{"rendered":"A simple 12-channel USB controlled relay board (part 1)"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\" id=\"toc-introduction-0\">Introduction<\/h3>\n\n\n\n<p>In the Internet of Things (IoT) era, being able of controlling everything is becoming more and more requested. The most common example is the home automation: one would like to control for instance lights, the gates, and even appliances. One could use advanced wireless and custom solutions, but this adds difficulty to the task, and  discourages many people. A much simpler way is to connect directly a relay board to a PC\/Mac: one can choose his\/her preferred high level language programming environment. Relays allow easy and inexpensive control of loads.<\/p>\n\n\n\n<p> How to connect relays to a PC? Of course via USB! An USB-controlled board is a very advantageous solution: you can hook it up to any PC\/Mac with an USB port and it also can draw directly the required power from it.<\/p>\n\n\n\n<p>Despite its simplicity, this project will allow you to control up to 12 relays. The chosen relays allow to switch (resistive) loads up to 3A. If heavier loads must be switched, then one can either put a more rugged relay, or can use these relays as a switch, to control bigger relays close to the loads.<\/p>\n\n\n\n<p>The board is USB compliant, as the current consumption with all the relays in the ON state is less than 350 mA.<\/p>\n\n\n\n<p>We used\u00a0<a href=\"https:\/\/shop.itaca-innovation.com\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">uChip<\/a>, which is an Arduino Zero compatible board shrunk to a 16 DIP package. This allows us to make a compact design. Actually you might use anything you want that has an USB connection and enough I\/O pins.<\/p>\n\n\n\n<p>In this project we also put two pushbuttons which might be used for testing purposes, or emergency buttons, or other things. These functionalities are left open to your immagination!<\/p>\n\n\n\n<p>Part 1 will cover the full project, which allows to control the board using a PC\/MAC or even a Raspberry. <br>Part 2 will cover the USB Host implementation, that allows to connect a 3G dongle, and to allow to control the relays using SMS.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-theory-of-operation-1\">Theory of operation<\/h3>\n\n\n\n<p>The device waits for a serial connection on the USB port (CDC). Once a connection has been established, it periodically listens for commands. You might use any baud rate, as the USB device implements a virtual COM port.<\/p>\n\n\n\n<p>The commands are as follows:<\/p>\n\n\n\n<p>Capital letters A to L select the relay(s) you want to turn on or off. For instance ACF will select the first, the third, and the sixth relays. A subsequent 0, will turn off all the selected relays. A subsequent 1 will turn the selected relays on. Any other characters (including lower case a-l and 2-9 etc.) will abort the command.<\/p>\n\n\n\n<p>For instance &#8220;ACF1&#8221; will turn on relays A, C and F.<\/p>\n\n\n\n<p>If we write &#8220;CF0&#8221;, the relays C and F will be turned off.<\/p>\n\n\n\n<p>Any combination of relays can be turned on\/off simultaneously.<\/p>\n\n\n\n<p>Each relay is connected to uChip using a BJT. The LEDs show the state of the channels.<\/p>\n\n\n\n<p>Here is the schematics PNG and <a rel=\"noreferrer noopener\" aria-label=\"here the KiCAD project! (opens in a new tab)\" href=\"https:\/\/next-hack.com\/wp-content\/uploads\/2019\/03\/uChipRelay.zip\" target=\"_blank\">here the KiCAD project!<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"2204\" height=\"1559\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2019\/03\/uChipRelayControllerSch.png\" alt=\"\" class=\"wp-image-509\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"> <br>Downloads<\/h2>\n\n\n\n<p><a href=\"https:\/\/next-hack.com\/wp-content\/uploads\/2019\/03\/uChipRelay.zip\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"Click here for the full KiCAD project. (opens in a new tab)\">Click here for the full KiCAD project.<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/next-hack.com\/wp-content\/uploads\/2019\/03\/uChipRelay.ino\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"Click here for the Arduino sketch! (opens in a new tab)\">Click here for the Arduino sketch!<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Hardware requirements<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>1x <a rel=\"noreferrer noopener\" aria-label=\"uChip (opens in a new tab)\" href=\"https:\/\/www.kickstarter.com\/projects\/1186620431\/uchip-arduino-zero-compatible-in-a-narrow-dip-16-p\" target=\"_blank\">uChip<\/a><\/li><li>12x  BC337-40<\/li><li>12x 3.3 kOhm resistor, 5%, 1\/4 W, through hole<\/li><li>12x 1.5 kOhm resistor, 5%, 1\/4 W, through hole  <ul><li><em>(adjust value to achieve the desired LED luminosity) <\/em><\/li><\/ul><\/li><li>1x 270 Ohm resistor, 5%, 1\/4 W, through hole<ul><li> <em>(adjust value to achieve the desired LED luminosity)<\/em><\/li><\/ul><\/li><li>1&#215;100 uF electrolytic capactor, 6.3 mm diameter, working voltage &gt; 6.3 V<\/li><li>13x 2-poles screw terminal, 5.08 mm spacing <ul><li><em>(the 13th is used if you want to provide the 5V power externally. This will be used also for the second part of this project: being able to use the board by connecting it to an USB 3G dongle)<\/em><\/li><\/ul><\/li><li> 1x 6.35&#215;16 cm prototyping board. <ul><li>Of course this measure is not standard, so you might want to buy one 10&#215;16 standard, as we did.<\/li><li>Not needed if you instead decide to use the layout provided in the KiCAD project archive.<\/li><\/ul><\/li><li>1x 5 mm LED. Pick your color! <ul><li>We just used red as it was the cheapest!<\/li><\/ul><\/li><li>12x 1.8 mm LED. <ul><li>Pick your color here too!<\/li><\/ul><\/li><li>12x 1N4148 diode<\/li><li>12x TE Connectivity PCN-105D3MHZ relay. <ul><li><em>These relays were choosen because&nbsp;of&nbsp;their&nbsp;compactness&nbsp;and&nbsp;low&nbsp;coil&nbsp;drive&nbsp;current.<\/em><\/li><\/ul><\/li><li>KS-01Q-01 pushbutton. <em>These are optional.<\/em><\/li><li> Hexagonal standoff M3 Nylon 6mm (e.g. CBMFTS210A). <ul><li><em>Pay special safety&nbsp;precautions if you use metal standoff&nbsp;instead!<\/em><\/li><\/ul><\/li><li> Hexagonal  nylon M3 nut. <ul><li>Pay special safety precautions if you use metal nut instead!<\/li><\/ul><\/li><li> Micro-USB to USB Cable.<\/li><li>16-Pin IC socket.<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Software requirements<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>Arduino IDE.<\/li><li>A terminal program such as termite or your program.<\/li><li><a href=\"https:\/\/next-hack.com\/wp-content\/uploads\/2019\/03\/uChipRelay.ino\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"This sketch. (opens in a new tab)\">This sketch.<\/a><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Let&#8217;s go for the next hack!<\/h2>\n\n\n\n<p>In these steps we use a 10&#215;16 cm perfboard. Of course, you can also manufacture the PCB following the layout.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Step 1: prepare the prototyping board<\/h4>\n\n\n\n<p>Jump to step 2 if you decide tho make your own PCB!<br>First measure the desired board size<\/p>\n\n\n\n<p>a. Measure the desired board size.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1192\" height=\"1600\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2019\/03\/cutPerfboard.png\" alt=\"\" class=\"wp-image-499\"\/><\/figure>\n\n\n\n<p>b. Cut the board.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"1600\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2019\/03\/cutPerfboard-2.png\" alt=\"\" class=\"wp-image-498\"\/><\/figure>\n\n\n\n<p>c. Use a file to smooth the edges. <\/p>\n\n\n\n<p> d.  Mark the position for the holes. <br><strong>SAFETY WARNING!<\/strong><em>&nbsp;If using 110-240 V loads, then place the holes a bit farther than what&#8217;s shown here, especially near the screw terminal<\/em>&nbsp;blocks<em>. Alternatively do not use metal stand-off, but plastic ones<\/em>&nbsp;as suggested in the component list<em>.<\/em> <\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"1600\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2019\/03\/holes.png\" alt=\"\" class=\"wp-image-503\"\/><\/figure>\n\n\n\n<p style=\"text-align:left\">e. Drill the holes. <br><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1600\" height=\"1184\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2019\/03\/drilled-Holes.png\" alt=\"\" class=\"wp-image-500\"\/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">Step 2: solder the components<\/h4>\n\n\n\n<p>Solder all the components, in order of height. Resistors, IC socket, BJTs, diodes, 5-mm LED, screw terminal blocks, capacitor, the other LEDs, relays, pushbuttons. <\/p>\n\n\n\n<p><strong>Note! If using a prototyping board,  keep the component leads. These will be useful later for the connections! <\/strong><\/p>\n\n\n\n<p><strong>If you are using a PCB (i.e. not prototyping board), then jump directly to step 5!<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1600\" height=\"1196\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2019\/03\/justsoldered.png\" alt=\"\" class=\"wp-image-504\"\/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">Step 3: remove pads near the high voltage side<\/h4>\n\n\n\n<p><em>(Only for prototyping boards!)<\/em> After soldering the components, remove the extra pads around the relays and screw terminal blocks, ti improve insulation. This can be done using the soldering iron.&nbsp;<strong>Be sure to use a sacrificial tip and not your good one!<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"1600\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2019\/03\/padsremoval.png\" alt=\"\" class=\"wp-image-505\"\/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">Step 4: create the connections<\/h4>\n\n\n\n<p>Make the connections using the wires you cut from the components. Use additional wire when no space is left. \ud83d\ude42  <\/p>\n\n\n\n<p><a href=\"https:\/\/next-hack.com\/wp-content\/uploads\/2019\/03\/uChipRelay.zip\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"Here is an example KiCAD layou (opens in a new tab)\">Here is an example KiCAD layou<\/a>t. It will be like the picture below. You can use this as a reference when using the prototyping board.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1486\" height=\"722\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2019\/03\/exampleLayout.png\" alt=\"\" class=\"wp-image-501\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"1600\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2019\/03\/connections.png\" alt=\"\" class=\"wp-image-497\"\/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">Step 5: upload the sketch<\/h4>\n\n\n\n<p>Insert uChip, connect the board with a microUSB cable and program uChip using the <a href=\"https:\/\/next-hack.com\/wp-content\/uploads\/2019\/03\/uChipRelay.ino\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"sketch provided (opens in a new tab)\">sketch provided<\/a> and Arduino IDE. <\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1920\" height=\"1041\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2019\/03\/programmng.png\" alt=\"\" class=\"wp-image-507\"\/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">Step 6: enjoy!<\/h4>\n\n\n\n<p>Use your favourite terminal program (serial monitor, termite, etc.) and write a test string to see if it works. For instance, entering ABCDEFGHIJK1 will cause all LEDs will turn on. <\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"898\" height=\"1600\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2019\/03\/allOn.png\" alt=\"\" class=\"wp-image-496\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Introduction In the Internet of Things (IoT) era, being able of controlling everything is becoming more and more requested. The most common example is the home automation: one would like to control for instance lights, the gates, and even appliances&#8230;. <a class=\"read-more-button\" href=\"https:\/\/next-hack.com\/index.php\/2019\/03\/30\/a-simple-12-channel-usb-controlled-relay-board-part-1\/\">(READ MORE)<\/a><\/p>\n","protected":false},"author":2,"featured_media":506,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[32,1,2,33],"tags":[],"class_list":["post-491","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-all-projects","category-general-hacks","category-iot","category-other-arduino-projects"],"_links":{"self":[{"href":"https:\/\/next-hack.com\/index.php\/wp-json\/wp\/v2\/posts\/491"}],"collection":[{"href":"https:\/\/next-hack.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/next-hack.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/next-hack.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/next-hack.com\/index.php\/wp-json\/wp\/v2\/comments?post=491"}],"version-history":[{"count":9,"href":"https:\/\/next-hack.com\/index.php\/wp-json\/wp\/v2\/posts\/491\/revisions"}],"predecessor-version":[{"id":603,"href":"https:\/\/next-hack.com\/index.php\/wp-json\/wp\/v2\/posts\/491\/revisions\/603"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/next-hack.com\/index.php\/wp-json\/wp\/v2\/media\/506"}],"wp:attachment":[{"href":"https:\/\/next-hack.com\/index.php\/wp-json\/wp\/v2\/media?parent=491"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/next-hack.com\/index.php\/wp-json\/wp\/v2\/categories?post=491"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/next-hack.com\/index.php\/wp-json\/wp\/v2\/tags?post=491"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}