{"id":985,"date":"2014-01-30T16:46:00","date_gmt":"2014-01-30T16:46:00","guid":{"rendered":"https:\/\/theshanty.us\/?p=985"},"modified":"2025-08-06T16:56:06","modified_gmt":"2025-08-06T16:56:06","slug":"electronic-uppy-downy-thingy-aka-echobox","status":"publish","type":"post","link":"http:\/\/blog.theshanty.us\/index.php\/2014\/01\/30\/electronic-uppy-downy-thingy-aka-echobox\/","title":{"rendered":"Electronic uppy-downy thingy (AKA: EchoBox)"},"content":{"rendered":"\n<p>Back in August I got a height adjustable desk. It&#8217;s motorized! So, one of my basic tenets is: What has motors, must be hacked! (which incidentally is NOT why my Roomba isn&#8217;t working right now)<\/p>\n\n\n\n<p>I (as usual) didn&#8217;t do a great job of documenting the process. The project took shape because in order to make the desk go up and down, I would be forced to hold a button for up 17 seconds! Can you imagine the drudgery of holding in a button for 17 long, tiring seconds?<\/p>\n\n\n\n<p>I decided to create a device with a microcontroller and a sonic module to bounce sound off of the floor and measure the distance between the desk and the floor. I started with an Ardiuno&nbsp;<a href=\"http:\/\/dx.com\/p\/118037\" target=\"_blank\" rel=\"noreferrer noopener\">nano<\/a>&nbsp;and a (knock-off)&nbsp;<a href=\"http:\/\/dx.com\/p\/148659\" target=\"_blank\" rel=\"noreferrer noopener\">Ping(((<\/a>&nbsp;module.<\/p>\n\n\n\n<p>Then I went to Radio Shack and found the perfect case and a piece of perf board to build on.<\/p>\n\n\n\n<p>I knew I&#8217;d need to open up the control and solder in a connector (I chose a stereo plug) to actually control the direction of travel. I got lucky. The desk&#8217;s controller had three solder pads right behind the plug for the controls. Up &#8211; Ground &#8211; Down.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"768\" height=\"1024\" src=\"https:\/\/theshanty.us\/wp-content\/uploads\/2025\/08\/20130925_144059-768x1024.jpg\" alt=\"\" class=\"wp-image-987\" srcset=\"http:\/\/blog.theshanty.us\/wp-content\/uploads\/2025\/08\/20130925_144059-768x1024.jpg 768w, http:\/\/blog.theshanty.us\/wp-content\/uploads\/2025\/08\/20130925_144059-225x300.jpg 225w, http:\/\/blog.theshanty.us\/wp-content\/uploads\/2025\/08\/20130925_144059-1152x1536.jpg 1152w, http:\/\/blog.theshanty.us\/wp-content\/uploads\/2025\/08\/20130925_144059-1024x1365.jpg 1024w, http:\/\/blog.theshanty.us\/wp-content\/uploads\/2025\/08\/20130925_144059-rotated.jpg 1536w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/figure>\n\n\n\n<p>Then I got to experimenting with the Ping module, I came up with some code to make it work. It would simply send a trigger signal out to the trigger pin and then begin listening on the output pin.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1024\" height=\"768\" src=\"http:\/\/theshanty.us\/wp-content\/uploads\/2025\/08\/20131203_112011_result.jpg\" alt=\"\" class=\"wp-image-986\" srcset=\"http:\/\/blog.theshanty.us\/wp-content\/uploads\/2025\/08\/20131203_112011_result.jpg 1024w, http:\/\/blog.theshanty.us\/wp-content\/uploads\/2025\/08\/20131203_112011_result-300x225.jpg 300w, http:\/\/blog.theshanty.us\/wp-content\/uploads\/2025\/08\/20131203_112011_result-768x576.jpg 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Once that was working I just needed a way to switch the up and down controls on and off in the desk controller. I added a couple 2222 transistors to a couple digital pins and wired them up. I don&#8217;t remember exactly how I did it, but I will post a schematic when I get a chance.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1024\" height=\"768\" src=\"http:\/\/theshanty.us\/wp-content\/uploads\/2025\/08\/20140105_122012_result.jpg\" alt=\"\" class=\"wp-image-994\" srcset=\"http:\/\/blog.theshanty.us\/wp-content\/uploads\/2025\/08\/20140105_122012_result.jpg 1024w, http:\/\/blog.theshanty.us\/wp-content\/uploads\/2025\/08\/20140105_122012_result-300x225.jpg 300w, http:\/\/blog.theshanty.us\/wp-content\/uploads\/2025\/08\/20140105_122012_result-768x576.jpg 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Next came the push buttons to select which direction the program will send the desk.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"768\" height=\"1024\" src=\"http:\/\/theshanty.us\/wp-content\/uploads\/2025\/08\/20140105_122020_result.jpg\" alt=\"\" class=\"wp-image-993\" style=\"width:740px;height:auto\" srcset=\"http:\/\/blog.theshanty.us\/wp-content\/uploads\/2025\/08\/20140105_122020_result.jpg 768w, http:\/\/blog.theshanty.us\/wp-content\/uploads\/2025\/08\/20140105_122020_result-225x300.jpg 225w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>Red for up Black for down<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>The board, when it was all wired up, was a mess, but it works!<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"768\" height=\"1024\" data-id=\"989\" src=\"https:\/\/theshanty.us\/wp-content\/uploads\/2025\/08\/20140105_122055_result.jpg\" alt=\"\" class=\"wp-image-989\" srcset=\"http:\/\/blog.theshanty.us\/wp-content\/uploads\/2025\/08\/20140105_122055_result.jpg 768w, http:\/\/blog.theshanty.us\/wp-content\/uploads\/2025\/08\/20140105_122055_result-225x300.jpg 225w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"768\" height=\"1024\" data-id=\"988\" src=\"https:\/\/theshanty.us\/wp-content\/uploads\/2025\/08\/20140105_122049_result.jpg\" alt=\"\" class=\"wp-image-988\" srcset=\"http:\/\/blog.theshanty.us\/wp-content\/uploads\/2025\/08\/20140105_122049_result.jpg 768w, http:\/\/blog.theshanty.us\/wp-content\/uploads\/2025\/08\/20140105_122049_result-225x300.jpg 225w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/figure>\n<\/figure>\n\n\n\n<p>All dressed up in it&#8217;s pretty enclosure&#8230;<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-2 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" data-id=\"990\" src=\"https:\/\/theshanty.us\/wp-content\/uploads\/2025\/08\/20140105_122103_result.jpg\" alt=\"\" class=\"wp-image-990\" srcset=\"http:\/\/blog.theshanty.us\/wp-content\/uploads\/2025\/08\/20140105_122103_result.jpg 1024w, http:\/\/blog.theshanty.us\/wp-content\/uploads\/2025\/08\/20140105_122103_result-300x225.jpg 300w, http:\/\/blog.theshanty.us\/wp-content\/uploads\/2025\/08\/20140105_122103_result-768x576.jpg 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" data-id=\"991\" src=\"https:\/\/theshanty.us\/wp-content\/uploads\/2025\/08\/20140105_122114_result.jpg\" alt=\"\" class=\"wp-image-991\" srcset=\"http:\/\/blog.theshanty.us\/wp-content\/uploads\/2025\/08\/20140105_122114_result.jpg 1024w, http:\/\/blog.theshanty.us\/wp-content\/uploads\/2025\/08\/20140105_122114_result-300x225.jpg 300w, http:\/\/blog.theshanty.us\/wp-content\/uploads\/2025\/08\/20140105_122114_result-768x576.jpg 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/figure>\n\n\n\n<p>Mounted under the desk. The finished product.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"http:\/\/theshanty.us\/wp-content\/uploads\/2025\/08\/20140130_094916_result.jpg\" alt=\"\" class=\"wp-image-992\" srcset=\"http:\/\/blog.theshanty.us\/wp-content\/uploads\/2025\/08\/20140130_094916_result.jpg 1024w, http:\/\/blog.theshanty.us\/wp-content\/uploads\/2025\/08\/20140130_094916_result-300x225.jpg 300w, http:\/\/blog.theshanty.us\/wp-content\/uploads\/2025\/08\/20140130_094916_result-768x576.jpg 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Now the code!<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/*\n echoBox\n   This is a sketch that controls the control box for my desk at work.\n   It is a motorized desk that requires you to hold the button until \n   it gets to the correct height. \n   \n   This will allow me to program a height and press a button to get the \n   desk to the correct location.\n *\/\n\n\/\/ set pin numbers:\n#include\nconst int outputDn = 2;\nconst int outputUp = 3;\nconst int trigger  = 6;\nconst int pingPin  = 7;\nconst int buttonDn = 8;\nconst int buttonUp = 9;\n\n\/\/ variables will change:\nint setUpState = 0;\nint setDnState = 0;\n\nvoid setup() {\n  \/\/ initialize the pushbutton pin as an input:\n  pinMode(outputUp, OUTPUT);     \n  pinMode(outputDn, OUTPUT);     \n  pinMode(buttonUp, INPUT);     \n  pinMode(buttonDn, INPUT);     \n  Serial.begin(9600);\n}\n\nvoid loop(){\n  long duration, debug;\n  float inches;\n  debug = 1;\n  \n  setUpState = digitalRead(buttonUp);\n  setDnState = digitalRead(buttonDn);\n  if (setDnState == LOW) {\n    duration = 10000;\n    while (duration > 2900) {\n      digitalWrite(outputDn, HIGH);  \n      delay(100); \n      pinMode(pingPin, OUTPUT);\n      digitalWrite(trigger, LOW);\n      delayMicroseconds(2);\n      digitalWrite(trigger, HIGH);\n      delayMicroseconds(5);\n      digitalWrite(trigger, LOW);\n\n      pinMode(pingPin, INPUT);\n      duration = pulseIn(pingPin, HIGH);\n      inches = microsecondsToInches(duration);\n      if (debug = 1) {\n        Serial.print(inches);\n        Serial.print(\"in - \");\n        Serial.print(duration);\n        Serial.print(\"ms\");\n        Serial.println();\n      }\n    }\n    digitalWrite(outputDn, LOW);\n  }\n  if (setUpState == LOW) {\n    duration = 100;\n    while (duration &lt; 4650) {\n      digitalWrite(outputUp, HIGH);  \n      delay(200); \n      pinMode(pingPin, OUTPUT);\n      digitalWrite(trigger, LOW);\n      delayMicroseconds(2);\n      digitalWrite(trigger, HIGH);\n      delayMicroseconds(5);\n      digitalWrite(trigger, LOW);\n\n      pinMode(pingPin, INPUT);\n      duration = pulseIn(pingPin, HIGH);\n      inches = microsecondsToInches(duration);\n      if (debug = 1) {\n        Serial.print(inches);\n        Serial.print(\"in - \");\n        Serial.print(duration);\n        Serial.print(\"ms\");\n        Serial.println();\n      }\n    }\n    digitalWrite(outputUp, LOW); \n  }  \n}\n\nvoid getHeight() {\n  \/\/ Add code here to do the measurement to reduce the number of lines\n}\n\nlong microsecondsToInches(float microseconds)\n{\n  return microseconds \/ 74 \/ 2;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Back in August I got a height adjustable desk. It&#8217;s<\/p>\n","protected":false},"author":4,"featured_media":986,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[78,22,74],"tags":[],"class_list":["post-985","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino","category-maker","category-work"],"featured_image_urls":{"full":["http:\/\/blog.theshanty.us\/wp-content\/uploads\/2025\/08\/20131203_112011_result.jpg",1024,768,false],"thumbnail":["http:\/\/blog.theshanty.us\/wp-content\/uploads\/2025\/08\/20131203_112011_result-150x150.jpg",150,150,true],"medium":["http:\/\/blog.theshanty.us\/wp-content\/uploads\/2025\/08\/20131203_112011_result-300x225.jpg",300,225,true],"medium_large":["http:\/\/blog.theshanty.us\/wp-content\/uploads\/2025\/08\/20131203_112011_result-768x576.jpg",640,480,true],"large":["http:\/\/blog.theshanty.us\/wp-content\/uploads\/2025\/08\/20131203_112011_result.jpg",640,480,false],"1536x1536":["http:\/\/blog.theshanty.us\/wp-content\/uploads\/2025\/08\/20131203_112011_result.jpg",1024,768,false],"2048x2048":["http:\/\/blog.theshanty.us\/wp-content\/uploads\/2025\/08\/20131203_112011_result.jpg",1024,768,false],"chromenews-featured":["http:\/\/blog.theshanty.us\/wp-content\/uploads\/2025\/08\/20131203_112011_result.jpg",1024,768,false],"chromenews-large":["http:\/\/blog.theshanty.us\/wp-content\/uploads\/2025\/08\/20131203_112011_result-825x575.jpg",825,575,true],"chromenews-medium":["http:\/\/blog.theshanty.us\/wp-content\/uploads\/2025\/08\/20131203_112011_result-590x410.jpg",590,410,true]},"author_info":{"display_name":"chuckularone","author_link":"http:\/\/blog.theshanty.us\/index.php\/author\/chuckularone\/"},"category_info":"<a href=\"http:\/\/blog.theshanty.us\/index.php\/category\/arduino\/\" rel=\"category tag\">Arduino<\/a> <a href=\"http:\/\/blog.theshanty.us\/index.php\/category\/maker\/\" rel=\"category tag\">Maker<\/a> <a href=\"http:\/\/blog.theshanty.us\/index.php\/category\/work\/\" rel=\"category tag\">Work<\/a>","tag_info":"Work","comment_count":"0","_links":{"self":[{"href":"http:\/\/blog.theshanty.us\/index.php\/wp-json\/wp\/v2\/posts\/985"}],"collection":[{"href":"http:\/\/blog.theshanty.us\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.theshanty.us\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.theshanty.us\/index.php\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.theshanty.us\/index.php\/wp-json\/wp\/v2\/comments?post=985"}],"version-history":[{"count":1,"href":"http:\/\/blog.theshanty.us\/index.php\/wp-json\/wp\/v2\/posts\/985\/revisions"}],"predecessor-version":[{"id":995,"href":"http:\/\/blog.theshanty.us\/index.php\/wp-json\/wp\/v2\/posts\/985\/revisions\/995"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/blog.theshanty.us\/index.php\/wp-json\/wp\/v2\/media\/986"}],"wp:attachment":[{"href":"http:\/\/blog.theshanty.us\/index.php\/wp-json\/wp\/v2\/media?parent=985"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.theshanty.us\/index.php\/wp-json\/wp\/v2\/categories?post=985"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.theshanty.us\/index.php\/wp-json\/wp\/v2\/tags?post=985"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}