{"id":52,"date":"2015-10-29T21:58:20","date_gmt":"2015-10-29T21:58:20","guid":{"rendered":"https:\/\/zhutarduino.wordpress.com\/?page_id=52"},"modified":"2020-10-12T16:39:51","modified_gmt":"2020-10-12T16:39:51","slug":"how-to-use-any-relay-with-your-arduino-the-safe-way","status":"publish","type":"page","link":"https:\/\/thezhut.com\/?page_id=52","title":{"rendered":"How to use any relay with your arduino the safe way"},"content":{"rendered":"<p><a href=\"https:\/\/thezhut.com\/wp-content\/uploads\/2015\/10\/f7j5fyeifo7059g_medium.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-55\" src=\"https:\/\/thezhut.com\/wp-content\/uploads\/2015\/10\/f7j5fyeifo7059g_medium.jpg?w=300\" alt=\"F7J5FYEIFO7059G_MEDIUM\" width=\"670\" height=\"400\" srcset=\"https:\/\/thezhut.com\/wp-content\/uploads\/2015\/10\/f7j5fyeifo7059g_medium.jpg 620w, https:\/\/thezhut.com\/wp-content\/uploads\/2015\/10\/f7j5fyeifo7059g_medium-300x179.jpg 300w\" sizes=\"auto, (max-width: 670px) 100vw, 670px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>This\u00a0tutorial will show you how to use any relay new or used with your ARDUINO the safe and proper way, If you purchases a preasymbled relay board for your arduino with all the components on it this is not the tutorial you are looking for. This\u00a0tutorial will show you how to use optocouplers and transistors to safely connect a stand alone relay to your arduino board..<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/thezhut.com\/wp-content\/uploads\/2015\/10\/fw20p9oifr69uop_medium.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-56\" src=\"https:\/\/thezhut.com\/wp-content\/uploads\/2015\/10\/fw20p9oifr69uop_medium.jpg?w=300\" alt=\"FW20P9OIFR69UOP_MEDIUM\" width=\"671\" height=\"293\" srcset=\"https:\/\/thezhut.com\/wp-content\/uploads\/2015\/10\/fw20p9oifr69uop_medium.jpg 620w, https:\/\/thezhut.com\/wp-content\/uploads\/2015\/10\/fw20p9oifr69uop_medium-300x131.jpg 300w\" sizes=\"auto, (max-width: 671px) 100vw, 671px\" \/><\/a><\/p>\n<p>The picture above shows the circuit you need to build..<\/p>\n<p>The parts you will need:<\/p>\n<p>#affiliate links#<\/p>\n<p>2 x <a href=\"http:\/\/www.dx.com\/p\/1-4w-resistance-metal-film-resistors-400-piece-pack-121339?Utm_rid=99156049&amp;Utm_source=affiliate\" rel=\"nofollow\"><span style=\"color: #0066cc;\">220\u03a9 resistors<\/span><\/a>.<\/p>\n<p>1 X <a href=\"http:\/\/www.dx.com\/s\/transistor?category=410&amp;Utm_rid=99156049&amp;Utm_source=affiliate\" rel=\"nofollow\"><span style=\"color: #0066cc;\">TIP120 DARLINGTON<\/span><\/a> transistor is recommended but any one that will handle your relay will work .<\/p>\n<p>1 X <a href=\"http:\/\/www.dx.com\/p\/sharp-1-channel-4-pin-pc817-optocoupler-black-20-pcs-163822?Utm_rid=99156049&amp;Utm_source=affiliate\" rel=\"nofollow\"><span style=\"color: #0066cc;\">SHARP PC817<\/span><\/a> optocoupler.<\/p>\n<p>1 X <a href=\"http:\/\/www.dx.com\/s\/relay?category=410&amp;Utm_rid=99156049&amp;Utm_source=affiliate\" rel=\"nofollow\"><span style=\"color: #0066cc;\">relay<\/span><\/a>.<\/p>\n<p>1 X <a href=\"http:\/\/www.dx.com\/s\/diode?category=410&amp;Utm_rid=99156049&amp;Utm_source=affiliate\" rel=\"nofollow\"><span style=\"color: #0066cc;\">1N4001 diode<\/span><\/a>.<\/p>\n<p>ARDUINO board, jumper wires &amp; breadboard.<\/p>\n<p>The Optocoupler is the most important part, it isolates the circuit from the relay using light. For more info about optocouplers please check out my\u00a0tutorial about them at this link (<a href=\"http:\/\/www.instructables.com\/id\/Isolating-circuits-from-your-arduino-with-optocoup\/\" rel=\"nofollow\"><span style=\"color: #0066cc;\">OPTOCOUPLERS<\/span><\/a>). The 220\u03a9 resistor cuts the voltage down from 5v to 1.2v on the led of the optocoupler, The max voltage on the led of the sharp PC817 is 1.4v.<\/p>\n<p>The transistor is a darlington tip120, I chose this because it will handle almost all the small to medium sized relays you could be using. This transistor will handle up to a 60v 5amp load. The base voltage of this transistor is 5v max and that&#8217;s what the 220\u03a9 resistor is for, it brings the voltage down to 1.5v well below 5v (try to never run components to there max, they will have short lives and get very hot).<\/p>\n<p>Now for the relay I&#8217;m using a 12v relay, if you are using a relay that requires a different voltage please use the appropriate power supply. Also remember NOT to connect your grounds between your arduino and power supply, that&#8217;s why we are using the optocoupler to isolate them from each other.<\/p>\n<p>If your relay does not have a diode built in make sure you add one, A 1N4001 or any similar will work.<\/p>\n<p>Now you have the circuit built lets try it out!..<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/thezhut.com\/wp-content\/uploads\/2015\/10\/f7th3i6ifr1uiva_medium.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-57\" src=\"https:\/\/thezhut.com\/wp-content\/uploads\/2015\/10\/f7th3i6ifr1uiva_medium.jpg?w=300\" alt=\"F7TH3I6IFR1UIVA_MEDIUM\" width=\"671\" height=\"447\" srcset=\"https:\/\/thezhut.com\/wp-content\/uploads\/2015\/10\/f7th3i6ifr1uiva_medium.jpg 620w, https:\/\/thezhut.com\/wp-content\/uploads\/2015\/10\/f7th3i6ifr1uiva_medium-300x200.jpg 300w\" sizes=\"auto, (max-width: 671px) 100vw, 671px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>To test your new relay circuit out just copy and paste this code into your ARDUINO IDE&#8230; Make sure you are using pin 9 on your arduino for the relay trigger!!..<\/p>\n<p>int rel=9;<br \/>\nvoid setup() {<br \/>\npinMode(rel,OUTPUT);<br \/>\n}<br \/>\nvoid loop() {<br \/>\ndigitalWrite(rel,HIGH);<br \/>\ndelay(1000);<br \/>\ndigitalWrite(rel,LOW);<br \/>\ndelay(1000);<br \/>\n}<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/p>\n<p>This code will make your relay turn on and off every 1 second.<\/p>\n<p>If you have any questions or problems please leave a comment on our <a href=\"https:\/\/www.facebook.com\/zarduino\/\" target=\"_blank\" rel=\"noopener noreferrer\">Facebook Page<\/a>&#8230;&#8230;&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; This\u00a0tutorial will show you how to use any relay new or used with your ARDUINO the safe and proper way, If you purchases a preasymbled relay board for your arduino with all the components on it this is not &hellip; <a href=\"https:\/\/thezhut.com\/?page_id=52\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":10,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":"","_links_to":"","_links_to_target":""},"class_list":["post-52","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages\/52","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/thezhut.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=52"}],"version-history":[{"count":1,"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages\/52\/revisions"}],"predecessor-version":[{"id":1612,"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages\/52\/revisions\/1612"}],"up":[{"embeddable":true,"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages\/10"}],"wp:attachment":[{"href":"https:\/\/thezhut.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=52"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}