{"id":921,"date":"2016-03-05T22:33:02","date_gmt":"2016-03-05T22:33:02","guid":{"rendered":"https:\/\/psyphi.net\/blog\/?p=921"},"modified":"2016-03-07T11:35:36","modified_gmt":"2016-03-07T11:35:36","slug":"remote-power-management-using-arduino","status":"publish","type":"post","link":"https:\/\/psyphi.net\/blog\/2016\/03\/remote-power-management-using-arduino\/","title":{"rendered":"Remote Power Management using Arduino"},"content":{"rendered":"<p><a href=\"https:\/\/psyphi.net\/blog\/2016\/03\/remote-power-management-using-arduino\/2016-03-04-21-20-07\/\" rel=\"attachment wp-att-923\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-923 size-large\" src=\"http:\/\/psyphi.net\/wp-uploads\/2016\/03\/2016-03-04-21.20.07-1024x768.jpg\" alt=\"2016-03-04 21.20.07\" width=\"840\" height=\"630\" srcset=\"https:\/\/psyphi.net\/wp-uploads\/2016\/03\/2016-03-04-21.20.07-1024x768.jpg 1024w, https:\/\/psyphi.net\/wp-uploads\/2016\/03\/2016-03-04-21.20.07-300x225.jpg 300w, https:\/\/psyphi.net\/wp-uploads\/2016\/03\/2016-03-04-21.20.07-1200x900.jpg 1200w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/a><\/p>\n<p>2016-03-07 Update: <a href=\"https:\/\/github.com\/rmp\/arduino-power-mgmt\" target=\"_blank\">Git Repo available<\/a><\/p>\n<p>Recently I&#8217;ve been involved with building a hardware device consisting of a cluster of low-power\u00c2\u00a0PC servers. The boards chosen for this particular project aren&#8217;t enterprise or embedded -style boards with specialist features like out of band (power) management (like Dell&#8217;s <a href=\"https:\/\/www.dell.com\/learn\/us\/en\/555\/solutions\/integrated-dell-remote-access-controller-idrac\" target=\"_blank\">iDRAC<\/a> or Intel&#8217;s <a href=\"http:\/\/www.intel.com\/content\/www\/us\/en\/architecture-and-technology\/intel-active-management-technology.html\" target=\"_blank\">AMT<\/a>) so I started thinking about how to\u00c2\u00a0approximate something similar.<\/p>\n<p>It&#8217;s also a little reminiscent of <a href=\"http:\/\/www.linux-ha.org\/wiki\/STONITH\" target=\"_blank\">STONITH<\/a> (Shoot The Other Node In The Head), used for aspects of the <a href=\"http:\/\/www.linux-ha.org\/\" target=\"_blank\">Linux-HA<\/a> (High Availability) services.<\/p>\n<p>I dug around in a box of goodies and found a couple of handy parts:<\/p>\n<ol>\n<li><a href=\"http:\/\/www.amazon.co.uk\/gp\/product\/B00PHY3HH2\/ref=as_li_tl?ie=UTF8&amp;camp=1634&amp;creative=19450&amp;creativeASIN=B00PHY3HH2&amp;linkCode=as2&amp;tag=psynetwebsol-21\" target=\"_blank\">Arduino<\/a> Duemilanove<\/li>\n<li><a href=\"http:\/\/www.amazon.co.uk\/gp\/product\/B016CX3492\/ref=as_li_tl?ie=UTF8&amp;camp=1634&amp;creative=19450&amp;creativeASIN=B016CX3492&amp;linkCode=as2&amp;tag=psynetwebsol-21\" target=\"_blank\">Seeedstudio Arduino Relay Shield v3<\/a><\/li>\n<\/ol>\n<p>The relays are rated for switching up to 35V at 8A &#8211; easily handling the 19V @ 2A for the mini server boards I&#8217;m remote managing.<\/p>\n<p>The other handy thing to notice is that the Arduino by its nature is serial-enabled, meaning you can control it\u00c2\u00a0very simply using a USB connection to the management system without needing any more shields or adapters.<\/p>\n<p>Lastly it&#8217;s worth mentioning that the relays are effectively <a href=\"https:\/\/en.wikipedia.org\/wiki\/Switch#Contact_terminology\" target=\"_blank\">SPDT<\/a> switches so have connections for circuit open and closed.\u00c2\u00a0In my case this is useful as most of the time I don&#8217;t want the relays to be energised, saving power and prolonging the life of the relay.<\/p>\n<p>The example <a href=\"https:\/\/www.arduino.cc\/en\/Main\/Software\" target=\"_blank\">Arduino code<\/a> below opens a serial port and collects characters in a string variable until a carriage-return (0x0D) before acting, accepting commands &#8220;on&#8221;, &#8220;off&#8221; and &#8220;reset&#8221;. When a command is completed, the code clears the command buffer and flips voltages on the digital pins controlling the relays. Works a treat &#8211; all I need to do now is splice the power cables for the cluster compute units and run them through the right connectors on the relay boards. With the draw the cluster nodes pull being well within the specs of the relays it might even be possible to happily run two nodes\u00c2\u00a0through each relay.<\/p>\n<p>There&#8217;s no reason why this sort of thing couldn&#8217;t be used for many other purposes too &#8211; home automation or other types of remote management, and could obviously be activated over ethernet, wifi or bluetooth instead of serial &#8211; goes without saying for a relay board -duh!<\/p>\n<blockquote>\n<pre>int MotorControl1 = 4;\r\nint MotorControl2 = 5;\r\nint MotorControl3 = 6;\r\nint MotorControl4 = 7;\r\nint incomingByte = 0; \/\/ for incoming serial data\r\nString input = \"\"; \/\/ for command message\r\n\r\nvoid action (String cmd) {\r\n  if(cmd == \"off\") {\r\n    digitalWrite(MotorControl1, HIGH); \/\/ NO1 + COM1\r\n    digitalWrite(MotorControl2, HIGH); \/\/ NO2 + COM2\r\n    digitalWrite(MotorControl3, HIGH); \/\/ NO3 + COM3\r\n    digitalWrite(MotorControl4, HIGH); \/\/ NO4 + COM4\r\n    return;\r\n  }\r\n\r\n  if(cmd == \"on\") {\r\n    digitalWrite(MotorControl1, LOW); \/\/ NC1 + COM1\r\n    digitalWrite(MotorControl2, LOW); \/\/ NC2 + COM2\r\n    digitalWrite(MotorControl3, LOW); \/\/ NC3 + COM3\r\n    digitalWrite(MotorControl4, LOW); \/\/ NC4 + COM4\r\n    return;\r\n  }\r\n\r\n  if(cmd == \"reset\") {\r\n    action(\"off\");\r\n    delay(1000);\r\n    action(\"on\");\r\n    return;\r\n  }\r\n\r\n  Serial.println(\"unknown action\");\r\n}\r\n\r\n\/\/ the setup routine runs once when you press reset:\r\nvoid setup() {\r\n  pinMode(MotorControl1, OUTPUT);\r\n  pinMode(MotorControl2, OUTPUT);\r\n  pinMode(MotorControl3, OUTPUT);\r\n  pinMode(MotorControl4, OUTPUT);\r\n  Serial.begin(9600); \/\/ opens serial port, sets data rate to 9600 bps\r\n  Serial.println(\"relay controller v0.1 rmp@psyphi.net actions are on|off|reset\");\r\n  input = \"\";\r\n} \r\n\r\n\/\/ the loop routine runs over and over again forever:\r\nvoid loop() {\r\n  if (Serial.available() &gt; 0) {\r\n    incomingByte = Serial.read();\r\n\r\n    if(incomingByte == 0x0D) {\r\n      Serial.println(\"action:\" + input);\r\n      action(input);\r\n      input = \"\";\r\n    } else {\r\n      input.concat(char(incomingByte));\r\n    }\r\n  } else {\r\n    delay(1000); \/\/ no need to go crazy\r\n  }\r\n}\r\n\r\n\r\n\r\n<\/pre>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>2016-03-07 Update: Git Repo available Recently I&#8217;ve been involved with building a hardware device consisting of a cluster of low-power\u00c2\u00a0PC servers. The boards chosen for this particular project aren&#8217;t enterprise or embedded -style boards with specialist features like out of band (power) management (like Dell&#8217;s iDRAC or Intel&#8217;s AMT) so I started thinking about how &hellip; <a href=\"https:\/\/psyphi.net\/blog\/2016\/03\/remote-power-management-using-arduino\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Remote Power Management using Arduino&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[45,11],"tags":[1102,414,13,1103,114,1099,422,1101,1100,1104],"class_list":["post-921","post","type-post","status-publish","format-standard","hentry","category-hardware","category-programming","tag-amt","tag-arduino","tag-code","tag-idrac","tag-power","tag-relay","tag-remote","tag-seeedstudio","tag-serial","tag-stonith"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/psyphi.net\/blog\/wp-json\/wp\/v2\/posts\/921","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/psyphi.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/psyphi.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/psyphi.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/psyphi.net\/blog\/wp-json\/wp\/v2\/comments?post=921"}],"version-history":[{"count":6,"href":"https:\/\/psyphi.net\/blog\/wp-json\/wp\/v2\/posts\/921\/revisions"}],"predecessor-version":[{"id":929,"href":"https:\/\/psyphi.net\/blog\/wp-json\/wp\/v2\/posts\/921\/revisions\/929"}],"wp:attachment":[{"href":"https:\/\/psyphi.net\/blog\/wp-json\/wp\/v2\/media?parent=921"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/psyphi.net\/blog\/wp-json\/wp\/v2\/categories?post=921"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/psyphi.net\/blog\/wp-json\/wp\/v2\/tags?post=921"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}