{"id":14,"date":"2009-03-09T20:59:03","date_gmt":"2009-03-10T03:59:03","guid":{"rendered":"http:\/\/www.partofthething.com\/thoughts\/?p=14"},"modified":"2015-12-06T16:31:48","modified_gmt":"2015-12-07T00:31:48","slug":"hot-tub-controller","status":"publish","type":"post","link":"https:\/\/partofthething.com\/thoughts\/hot-tub-controller\/","title":{"rendered":"Hot Tub Controller"},"content":{"rendered":"<p>So, I have to tell you about the hot tub project. It&#8217;s been going on for a few weeks now and we just basically finished it. I (with some help from Jesse) have set up a microcontroller to control and monitor the hot tub. We have a temperature sensor mounted on the heating element tube and we wired in a relay to control when the heater turn on. Then we wrote code to allow it to interface with email, the internet, and even text messages! For real. Look:<\/p>\n<figure id=\"attachment_15\" aria-describedby=\"caption-attachment-15\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.partofthething.com\/thoughts\/wp-content\/uploads\/2009\/03\/cell.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15\" src=\"http:\/\/www.partofthething.com\/thoughts\/wp-content\/uploads\/2009\/03\/cell-300x225.jpg\" alt=\"Text message from the hot tub\" width=\"300\" height=\"225\" \/><\/a><figcaption id=\"caption-attachment-15\" class=\"wp-caption-text\">Text message from the hot tub<\/figcaption><\/figure>\n<p>Haha! Here are some more gems:<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/www.partofthething.com\/thoughts\/wp-content\/uploads\/2009\/03\/plots.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-16\" title=\"Temperature plots\" src=\"http:\/\/www.partofthething.com\/thoughts\/wp-content\/uploads\/2009\/03\/plots.png\" alt=\"Temperature plots\" width=\"472\" height=\"502\" \/><\/a>and you can control it with this form:<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/www.partofthething.com\/thoughts\/wp-content\/uploads\/2009\/03\/control_form.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-17\" title=\"control_form\" src=\"http:\/\/www.partofthething.com\/thoughts\/wp-content\/uploads\/2009\/03\/control_form.png\" alt=\"control_form\" width=\"387\" height=\"380\" \/><\/a>Or you can just control it from the command line:<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/www.partofthething.com\/thoughts\/wp-content\/uploads\/2009\/03\/terminal.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-18\" title=\"terminal\" src=\"http:\/\/www.partofthething.com\/thoughts\/wp-content\/uploads\/2009\/03\/terminal-300x196.png\" alt=\"terminal\" width=\"300\" height=\"196\" \/><\/a>So here&#8217;s what&#8217;s going on. Firstly, there&#8217;s an <a href=\"http:\/\/www.arduino.cc\/\">arduino<\/a> connected to a USB port of the computer in the basement. Here&#8217;s a pic:<\/p>\n<p style=\"text-align: left;\"><a href=\"http:\/\/www.partofthething.com\/thoughts\/wp-content\/uploads\/2009\/03\/img_2559.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-19\" title=\"Arduino\" src=\"http:\/\/www.partofthething.com\/thoughts\/wp-content\/uploads\/2009\/03\/img_2559-1024x768.jpg\" alt=\"Arduino\" width=\"614\" height=\"461\" \/><\/a>One of the digital pins on the Arduino is connected to a <a href=\"http:\/\/www.maxim-ic.com\/products\/1-wire\/\">OneWire<\/a> bus with three temperature sensors hooked up to it with a pull-down resistor connecting the bus to the 5V line. That&#8217;s the green wire. The ground is white ground.\u00a0 The three sensors are hooked up (in parasite power mode) to 30 feet of indoor\/outdoor CAT-5 wire from Home Depot. I surrounded each temperature sensor with a piece of 3\/8&#8243; O.D. copper tubing (which is miraculously already corroding) and pinched them down and sealed them up with Silicone. Here&#8217;s a pic of the outdoor sensor.<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/www.partofthething.com\/thoughts\/wp-content\/uploads\/2009\/03\/img_2558.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-20\" title=\"Outdoor temp sensor in copper\" src=\"http:\/\/www.partofthething.com\/thoughts\/wp-content\/uploads\/2009\/03\/img_2558-1024x768.jpg\" alt=\"Outdoor temp sensor in copper\" width=\"614\" height=\"461\" \/><\/a><\/p>\n<p>Anyway, yeah. The last sensor, the one on the tub, is wrapped in lots of insulation from the hardware store to try to keep the outdoor temperature from affecting the hot tub readings.<\/p>\n<p>On another digital pin (the orange wire), we have a relay circuit that we can turn on and off easily. In the hot tub, it connects the wire that connects the coil of the main heater relay. So it&#8217;s\u00a0 a relay for a relay, effectively. We just set the temperature dial very high and use the Arduino to cut it off when we want. We got the circuit from <a href=\"http:\/\/www.arduino.cc\/playground\/uploads\/Learning\/relays.pdf\">here<\/a>. Here&#8217;s a copy of that:<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/www.partofthething.com\/thoughts\/wp-content\/uploads\/2009\/03\/schematic.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-21\" title=\"schematic\" src=\"http:\/\/www.partofthething.com\/thoughts\/wp-content\/uploads\/2009\/03\/schematic-1024x408.jpg\" alt=\"schematic\" width=\"614\" height=\"245\" \/><\/a><\/p>\n<p>Nice. I used a relay that can handle up to 30A, 240V, with a 12V coil. I got the 12V by splicing off of the hard drive power cable inside the computer (blue wire, with white blue as ground. That&#8217;s the same ground, but we didn&#8217;t want to tap into the fragile cat5 wire again). That&#8217;s unfortunate because it requires the computer be on to have the heater on. A better design would not rely on the computer to maintain control of the hot tub.<\/p>\n<p>The rest of it is just software. I&#8217;m using the pySerial module to read and write to the USB tty device in 32-bit <a href=\"http:\/\/www.ubuntu.com\/\">Ubuntu<\/a> 8.10 Linux. The code that I compiled on the Arduino chip simply accepts simple characters through the serial port and does as asked. It knows how to turn heater on, off, read temperatures, and tell whether or not the heater is on. I&#8217;ll build some safety logic in soon. Right now, all the control logic and communication is done in <a href=\"http:\/\/www.python.org\">Python<\/a> on the computer. I have an Arduino class that abstracts the commands the Arduino knows. Then there&#8217;s the hottubController class that checks the sensors and turns the heat on and off accordingly. It calls the communication class, that checks for commands in an IMAP email account, submits temperature information to a MySQL database on my server, and sends command responses via SMTP. The text messaging functionality works simply because you can easily use the <a href=\"http:\/\/en.wikipedia.org\/wiki\/SMS_gateways\">text-to-email gateways<\/a> used by many major phone companies. The MySQL stuff is done with the MySQLdb python module, which is fairly simple.<\/p>\n<p>The web form is a python cgi that makes that simple HTML table and sends the commands in. The plotter is another python script that reads the database and puts the data into an HTML file, which is then parsed by the <a href=\"http:\/\/code.google.com\/p\/flot\/\">flot<\/a> JavaScript plotting routines on the clientside, allowing zooming and dynamic date x-axis labels, which are awesome.<\/p>\n<p>Still to come: predictive hot tub times. Since the heating is very linear, it&#8217;s possible to extrapolate the time at which the tub will reach a given temperature. You&#8217;ll get a text that says: &#8220;the hot tub will be ready at 10:37PM&#8221; How cool will that be at the bar?<\/p>\n<p>With all the copper, casings, arduino, sensors, relays, silicone, insulation, and various other tools I bought during this, it&#8217;s up to about $100, not including the computer. Not bad!<\/p>\n<h2>More Details<\/h2>\n<p>In case you&#8217;re wondering or debugging the hot tub controller, here are some more details.<\/p>\n<figure id=\"attachment_345\" aria-describedby=\"caption-attachment-345\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.partofthething.com\/thoughts\/wp-content\/uploads\/2009\/03\/img_2627.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-345\" title=\"Wiring of hot tub controller\" src=\"http:\/\/www.partofthething.com\/thoughts\/wp-content\/uploads\/2009\/03\/img_2627-300x225.jpg\" alt=\"The breadboard setup for the hot tub controller\" width=\"300\" height=\"225\" \/><\/a><figcaption id=\"caption-attachment-345\" class=\"wp-caption-text\">The breadboard setup for the hot tub controller<\/figcaption><\/figure>\n<figure id=\"attachment_346\" aria-describedby=\"caption-attachment-346\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.partofthething.com\/thoughts\/wp-content\/uploads\/2009\/03\/img_2628.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-346\" title=\"Hot tub arduino set up\" src=\"http:\/\/www.partofthething.com\/thoughts\/wp-content\/uploads\/2009\/03\/img_2628-300x225.jpg\" alt=\"Here's what the arduino wires look like. Nothing special. \" width=\"300\" height=\"225\" \/><\/a><figcaption id=\"caption-attachment-346\" class=\"wp-caption-text\">Here&#39;s what the arduino wires look like. Nothing special. <\/figcaption><\/figure>\n<p>Out at the hot tub, you&#8217;ll see a silver toggle switch. Under normal operation, this should be in the center position. To shut down special features and go back to plain-old hot tub, put the switch in the up position. This gives control of the hot tub back to its internal thermostat. It also disables the 10 second heater delay relay.<\/p>\n<p><img decoding=\"async\" id=\"kosa-target-image\" style=\"position: absolute; visibility: hidden; z-index: 2147483647; left: 181px; top: 3497px;\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAABYAAAAUCAYAAACJfM0wAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAK8AAACvABQqw0mAAAAB90RVh0U29mdHdhcmUATWFjcm9tZWRpYSBGaXJld29ya3MgOLVo0ngAAAAWdEVYdENyZWF0aW9uIFRpbWUAMDQvMDQvMDhrK9wWAAACMElEQVQ4ja3SP2gTcRQH8O8vvUtIGmkqTY3SaMVFz6KDW2ywg4s4dGgXp3SyVLIIthCKQxCCuoZaXaSO\/ilKd4sSdXRL0EWtIRYaSkXsJTH33utwSZM01xo0D353v+N+97l33\/upQCAwFgwGfehiFYtFUxsYGPCmUqmv3YQTicSwBgCapnXTBQBoSinout5VVCnVDr\/44B\/OZH0xs6KMThCfR3LRs+aTycjvbwfCmawvduZkn7EwN4TBfheY90fXN6uYuffdyGQRu3apkmyDmzM2K8pYmBvC6kcLK+\/KMEsWLCIQMSyLULUIFhH0HsGNycNYnDuO6PRno9lQSsFVh+tDQSEY6MHymzJKFQILgxkgYhALmBnMDLNsIf1sA8cG3VDYYzhFAWWfRBjCAiIbIxYQE1ga17+2GSICKLQYznCtiATEDK6BIrU5MUhgd0+NH+AIt+5jshdqgkpVwEwNkBgs9lyE4XY3nnLMWNf13QEAG1uE2JVe9PUC5JCvCMPrVpifOor1YnW34\/pw7NjvVbmZ+3ljcTaMq5EjbRFJ07Gw8QfTd9fg96rc3o7bMh4f9SytvDenLl7\/ZADAl5cjWF7dwmy60PaSeiPjo56lv2Ycnzi0Fp9AEgAu39x8+urtT9x5\/GP74a2++LlTuumo76kDd4W9ALj9qIDIiOfBhdO+jtB9O279TFcuet77fD7Wn+sU7ajj1+kTSccb\/wv\/aymloEKh0Fg4HPZ2E87n86Udvs4FoWqwSHUAAAAASUVORK5CYII=\" alt=\"\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>So, I have to tell you about the hot tub project. It&#8217;s been going on for a few weeks now and we just basically finished it. I (with some help from Jesse) have set up a microcontroller to control and monitor the hot tub. We have a temperature sensor mounted on the heating element tube &hellip; <a href=\"https:\/\/partofthething.com\/thoughts\/hot-tub-controller\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Hot Tub Controller<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":4,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":""},"categories":[69,7,70],"tags":[12,29,33,51],"class_list":["post-14","post","type-post","status-publish","format-standard","hentry","category-electronics-and-physics","category-random","category-startup-ideas","tag-arduino","tag-hot-tub","tag-jesse","tag-python"],"_links":{"self":[{"href":"https:\/\/partofthething.com\/thoughts\/wp-json\/wp\/v2\/posts\/14","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/partofthething.com\/thoughts\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/partofthething.com\/thoughts\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/partofthething.com\/thoughts\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/partofthething.com\/thoughts\/wp-json\/wp\/v2\/comments?post=14"}],"version-history":[{"count":1,"href":"https:\/\/partofthething.com\/thoughts\/wp-json\/wp\/v2\/posts\/14\/revisions"}],"predecessor-version":[{"id":868,"href":"https:\/\/partofthething.com\/thoughts\/wp-json\/wp\/v2\/posts\/14\/revisions\/868"}],"wp:attachment":[{"href":"https:\/\/partofthething.com\/thoughts\/wp-json\/wp\/v2\/media?parent=14"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/partofthething.com\/thoughts\/wp-json\/wp\/v2\/categories?post=14"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/partofthething.com\/thoughts\/wp-json\/wp\/v2\/tags?post=14"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}