{"id":381,"date":"2020-03-17T08:36:10","date_gmt":"2020-03-17T08:36:10","guid":{"rendered":"https:\/\/starthardware.org\/en\/?p=381"},"modified":"2020-03-17T08:36:12","modified_gmt":"2020-03-17T08:36:12","slug":"touchless-soap-dispenser-with-arduino","status":"publish","type":"post","link":"https:\/\/starthardware.org\/en\/touchless-soap-dispenser-with-arduino\/","title":{"rendered":"Touchless soap dispenser with Arduino"},"content":{"rendered":"\n<p>These are crazy times we live in and I thought for a while about releasing this project. However, you don&#8217;t have that many opportunities to actively do something against the spread of viruses like the Corona virus. Stay at home and wash your hands. Well, I have an idea for hand washing and so I&#8217;ll show you how to build a touchless soap dispenser with Arduino. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Components<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li> 1x <a href=\"https:\/\/amzn.to\/3d5m7zR\">Arduino UNO<\/a>*<\/li><li> 1x IR distance sensor <a href=\"https:\/\/amzn.to\/3cZQMi5\">GP2Y0A41SK0F<\/a>*<\/li><li> 1x <a href=\"https:\/\/amzn.to\/2TTwxuS\">servo motor<\/a>*<\/li><li>     cables<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Circuit<\/h2>\n\n\n\n<p>The circuit consists of two partial circuits. The infrared distance sensor is connected to 5V+,GND and the analog input 0. The servo motor is also connected to 5V+ and GND. It is controlled via the digital pin 7.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"572\" src=\"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2020\/03\/arduino-soap-dispenser-1024x572.jpg\" alt=\"Arduino soap dispender\" class=\"wp-image-382\" srcset=\"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2020\/03\/arduino-soap-dispenser-1024x572.jpg 1024w, https:\/\/starthardware.org\/en\/wp-content\/uploads\/2020\/03\/arduino-soap-dispenser-300x168.jpg 300w, https:\/\/starthardware.org\/en\/wp-content\/uploads\/2020\/03\/arduino-soap-dispenser-768x429.jpg 768w, https:\/\/starthardware.org\/en\/wp-content\/uploads\/2020\/03\/arduino-soap-dispenser.jpg 1165w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Functionality<\/h2>\n\n\n\n<p>The sensor can be installed above the soap dispenser looking down or next to the soap dispenser looking up. It reacts within a range of 10 &#8211; 30 cm and activates the servo motor via the Arduino. The servo motor pulls on a string that runs over the pump of the soap dispenser and is fixed on the other side. This pushes the pump down and soap is dispensed. Afterwards the servo moves back to its starting position, the pump moves up again. <\/p>\n\n\n\n<p>To ensure the function you have to adjust three values in the code. To do this, build up the circuit and do a dry test without soap dispenser. Load the code on the Arduino board and start the serial monitor of the Arduino software (Tools&gt;Serial Monitor). Set the baud rate (at the bottom of the window) to 115200. Now you should see the values from the sensor. Hold your hand over the sensor and remember the value at which the sensor should trigger. Write the value into the variable irThreshold. <\/p>\n\n\n\n<p>Now try out values for the servo: Where should it start and how far should it turn. You do this with the variables servoPositionPumps and servoPositionNonPumps. If everything fits, install the soap dispenser. Of course there is a little bit of handicraft work involved. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Code<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;Servo.h>\n\nint servoPin = 7;\nint irPin = 0;\n\nServo myServo;                        \/\/ create servo object\n\nint servoPositionPumpen = 30;         \/\/ adjust to your servo\nint servoPositionNichtPumpen = 120;   \/\/ adjust to your servo\nint irThreshold = 300;                \/\/ when shall the sensor react?\n\nint lastState = -1;                   \/\/ -1 = pump not pushed\nint state = -1;\n\nvoid setup() {\n  Serial.begin(115200);               \/\/ start serial monitor\n  myServo.attach(servoPin);           \/\/ initialise servo motor\n\n  \n  myServo.write(servoPositionNichtPumpen);  \/\/ servo to start position\n  delay(1000);                              \/\/ wait for one second\n}\n\n\nvoid loop() {\n  Serial.println(analogRead(irPin));                \/\/ serial output of sensor value\n\n  if (analogRead(irPin)>irThreshold) state = 1;     \/\/ trigger event detected\n  else state = -1;                                  \/\/ no trigger event detected\n  \n  if ((state==1)&amp;&amp;(lastState!=1)){                  \/\/ prevent continious triggering\n    myServo.write(servoPositionPumpen);             \/\/ pump\n    delay(1000);                                    \/\/ wait for one second\n    myServo.write(servoPositionNichtPumpen);        \/\/ release pump\n    delay(1000);                                    \/\/ wait for one second\n  }\n  lastState=state;                                  \n  delay(20);\n}<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>These are crazy times we live in and I thought for a while about releasing this project. However, you don&#8217;t have that many opportunities to actively do something against the spread of viruses like the Corona virus. Stay at home and wash your hands. Well, I have an idea for hand washing and so I&#8217;ll&hellip;&nbsp;<a href=\"https:\/\/starthardware.org\/en\/touchless-soap-dispenser-with-arduino\/\" class=\"\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">Touchless soap dispenser with Arduino<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":383,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","footnotes":""},"categories":[5],"tags":[],"class_list":["post-381","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino-projects"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v18.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Touchless soap dispenser with Arduino - StartHardware - Tutorials for Arduino<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/starthardware.org\/en\/touchless-soap-dispenser-with-arduino\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Touchless soap dispenser with Arduino - StartHardware - Tutorials for Arduino\" \/>\n<meta property=\"og:description\" content=\"These are crazy times we live in and I thought for a while about releasing this project. However, you don&#8217;t have that many opportunities to actively do something against the spread of viruses like the Corona virus. Stay at home and wash your hands. Well, I have an idea for hand washing and so I&#8217;ll&hellip;&nbsp;Read More &raquo;Touchless soap dispenser with Arduino\" \/>\n<meta property=\"og:url\" content=\"https:\/\/starthardware.org\/en\/touchless-soap-dispenser-with-arduino\/\" \/>\n<meta property=\"og:site_name\" content=\"StartHardware - Tutorials for Arduino\" \/>\n<meta property=\"article:published_time\" content=\"2020-03-17T08:36:10+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-03-17T08:36:12+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2020\/03\/arduino-soap-dispenser-title.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"675\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Stefan Hermann\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/starthardware.org\/en\/#website\",\"url\":\"https:\/\/starthardware.org\/en\/\",\"name\":\"StartHardware - Tutorials for Arduino\",\"description\":\"Arduino, Electronics, Fun\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/starthardware.org\/en\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/starthardware.org\/en\/touchless-soap-dispenser-with-arduino\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2020\/03\/arduino-soap-dispenser-title.jpg\",\"contentUrl\":\"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2020\/03\/arduino-soap-dispenser-title.jpg\",\"width\":1200,\"height\":675,\"caption\":\"Arduino touchless soap dispenser\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/starthardware.org\/en\/touchless-soap-dispenser-with-arduino\/#webpage\",\"url\":\"https:\/\/starthardware.org\/en\/touchless-soap-dispenser-with-arduino\/\",\"name\":\"Touchless soap dispenser with Arduino - StartHardware - Tutorials for Arduino\",\"isPartOf\":{\"@id\":\"https:\/\/starthardware.org\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/starthardware.org\/en\/touchless-soap-dispenser-with-arduino\/#primaryimage\"},\"datePublished\":\"2020-03-17T08:36:10+00:00\",\"dateModified\":\"2020-03-17T08:36:12+00:00\",\"author\":{\"@id\":\"https:\/\/starthardware.org\/en\/#\/schema\/person\/811b16fabcbfeef4210ea79cf0990a59\"},\"breadcrumb\":{\"@id\":\"https:\/\/starthardware.org\/en\/touchless-soap-dispenser-with-arduino\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/starthardware.org\/en\/touchless-soap-dispenser-with-arduino\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/starthardware.org\/en\/touchless-soap-dispenser-with-arduino\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/starthardware.org\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Touchless soap dispenser with Arduino\"}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/starthardware.org\/en\/#\/schema\/person\/811b16fabcbfeef4210ea79cf0990a59\",\"name\":\"Stefan Hermann\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/starthardware.org\/en\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/5b5a74ee1d07024fd1eff9b1f7137108089169010a93afaee907b9325ee579a6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/5b5a74ee1d07024fd1eff9b1f7137108089169010a93afaee907b9325ee579a6?s=96&d=mm&r=g\",\"caption\":\"Stefan Hermann\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Touchless soap dispenser with Arduino - StartHardware - Tutorials for Arduino","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/starthardware.org\/en\/touchless-soap-dispenser-with-arduino\/","og_locale":"en_US","og_type":"article","og_title":"Touchless soap dispenser with Arduino - StartHardware - Tutorials for Arduino","og_description":"These are crazy times we live in and I thought for a while about releasing this project. However, you don&#8217;t have that many opportunities to actively do something against the spread of viruses like the Corona virus. Stay at home and wash your hands. Well, I have an idea for hand washing and so I&#8217;ll&hellip;&nbsp;Read More &raquo;Touchless soap dispenser with Arduino","og_url":"https:\/\/starthardware.org\/en\/touchless-soap-dispenser-with-arduino\/","og_site_name":"StartHardware - Tutorials for Arduino","article_published_time":"2020-03-17T08:36:10+00:00","article_modified_time":"2020-03-17T08:36:12+00:00","og_image":[{"width":1200,"height":675,"url":"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2020\/03\/arduino-soap-dispenser-title.jpg","type":"image\/jpeg"}],"twitter_card":"summary_large_image","twitter_misc":{"Written by":"Stefan Hermann","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"https:\/\/starthardware.org\/en\/#website","url":"https:\/\/starthardware.org\/en\/","name":"StartHardware - Tutorials for Arduino","description":"Arduino, Electronics, Fun","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/starthardware.org\/en\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https:\/\/starthardware.org\/en\/touchless-soap-dispenser-with-arduino\/#primaryimage","inLanguage":"en-US","url":"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2020\/03\/arduino-soap-dispenser-title.jpg","contentUrl":"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2020\/03\/arduino-soap-dispenser-title.jpg","width":1200,"height":675,"caption":"Arduino touchless soap dispenser"},{"@type":"WebPage","@id":"https:\/\/starthardware.org\/en\/touchless-soap-dispenser-with-arduino\/#webpage","url":"https:\/\/starthardware.org\/en\/touchless-soap-dispenser-with-arduino\/","name":"Touchless soap dispenser with Arduino - StartHardware - Tutorials for Arduino","isPartOf":{"@id":"https:\/\/starthardware.org\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/starthardware.org\/en\/touchless-soap-dispenser-with-arduino\/#primaryimage"},"datePublished":"2020-03-17T08:36:10+00:00","dateModified":"2020-03-17T08:36:12+00:00","author":{"@id":"https:\/\/starthardware.org\/en\/#\/schema\/person\/811b16fabcbfeef4210ea79cf0990a59"},"breadcrumb":{"@id":"https:\/\/starthardware.org\/en\/touchless-soap-dispenser-with-arduino\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/starthardware.org\/en\/touchless-soap-dispenser-with-arduino\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/starthardware.org\/en\/touchless-soap-dispenser-with-arduino\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/starthardware.org\/en\/"},{"@type":"ListItem","position":2,"name":"Touchless soap dispenser with Arduino"}]},{"@type":"Person","@id":"https:\/\/starthardware.org\/en\/#\/schema\/person\/811b16fabcbfeef4210ea79cf0990a59","name":"Stefan Hermann","image":{"@type":"ImageObject","@id":"https:\/\/starthardware.org\/en\/#personlogo","inLanguage":"en-US","url":"https:\/\/secure.gravatar.com\/avatar\/5b5a74ee1d07024fd1eff9b1f7137108089169010a93afaee907b9325ee579a6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5b5a74ee1d07024fd1eff9b1f7137108089169010a93afaee907b9325ee579a6?s=96&d=mm&r=g","caption":"Stefan Hermann"}}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/posts\/381","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/comments?post=381"}],"version-history":[{"count":1,"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/posts\/381\/revisions"}],"predecessor-version":[{"id":384,"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/posts\/381\/revisions\/384"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/media\/383"}],"wp:attachment":[{"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/media?parent=381"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/categories?post=381"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/tags?post=381"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}