{"id":2339,"date":"2017-10-17T15:13:16","date_gmt":"2017-10-17T14:13:16","guid":{"rendered":"http:\/\/dronesonen.hibu.no\/?p=2339"},"modified":"2017-10-17T16:23:55","modified_gmt":"2017-10-17T15:23:55","slug":"smart-mirror-cw-42","status":"publish","type":"post","link":"https:\/\/dronesonen.usn.no\/?p=2339","title":{"rendered":"Smart Mirror: CW 42"},"content":{"rendered":"<p><strong>Electrical\/Mechanical:<\/strong><\/p>\n<p>This is the first and well working draft of our arduino program to control the motors.<\/p>\n<p>\/*\u00a0Connect 5V on Arduino to VCC on Relay Module<br \/>\nConnect GND on Arduino to GND on Relay Module<br \/>\nConnect Power on Arduino to the Common Terminal (middle terminal) on Relay Module.<br \/>\n*\/<\/p>\n<p>\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/Relay\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/<br \/>\nconst int relay = 5;<br \/>\n\/\/ int relayVal;<\/p>\n<p>\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/loadCell\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/<br \/>\n#include &#8220;HX711.h&#8221;<br \/>\n#define zero_factor 145230<br \/>\n#define DOUT 3 \/\/gelb \/ yellow<br \/>\n#define CLK 2 \/\/orange<br \/>\nfloat calibration_factor = ((200000 * 0.00045359237) + 52400);<br \/>\nHX711 scale(DOUT, CLK);<\/p>\n<p>\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/Servo\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/<br \/>\n#include &lt;Servo.h&gt;<br \/>\nServo myservo360; \/\/continious rotation servo<br \/>\nServo myservo180; \/\/ 180 servo<br \/>\nint direction = 1;<br \/>\nint pos3 = 0;<br \/>\nint pos1 = 0;<br \/>\nconst int servPin360 = 9;<br \/>\nconst int servPin180 = 8;<\/p>\n<p>&nbsp;<\/p>\n<p>\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/Button\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/<br \/>\nconst int butPin = 12;<br \/>\nint butVal;<\/p>\n<p>&nbsp;<\/p>\n<p>void setup() {<br \/>\npinMode(butPin, INPUT);<br \/>\npinMode(relay, OUTPUT);<\/p>\n<p>Serial.begin(9600);<\/p>\n<p>scale.set_scale(calibration_factor); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\/\/ when u open the serial monitor the value should be between -0.5 and + 0.5: for setting it to 0 we will have to mount it to the box<br \/>\nscale.set_offset(zero_factor); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\/\/Zero out the scale using a previously known zero_factor<br \/>\nSerial.println(&#8220;Reading: &#8220;);<br \/>\nclose();<br \/>\n}<\/p>\n<p>void loop() {<br \/>\nSerial.println(scale.get_units(), 1);<\/p>\n<p>checkButton(); \/\/ function to check if the button is pressed<br \/>\nif (butVal == HIGH) {<br \/>\nmyservo360.attach(servPin360);<br \/>\ndigitalWrite(relay, LOW); \/\/relay works inverse: LOW = connected to external powersupply<\/p>\n<p>\/\/push the toothpaste out of the cylinder<br \/>\nwhile (scale.get_units() &lt;= 10) { \/\/ when the weight is more then 10, call the function<br \/>\nservo360(); \/\/ of the first servo<br \/>\n}<br \/>\nmyservo360.detach();<br \/>\nmyservo180.attach(servPin180); \/\/ connect the second servo<\/p>\n<p>\/\/ open the door of the box, so that the user can grab the toothbrush<br \/>\nservo180(); \/\/ call the function of the second servo to open the door<br \/>\nmyservo180.detach();<br \/>\n}<br \/>\nelse {<br \/>\ndigitalWrite(relay, HIGH); \/\/ disconnect powersupply<br \/>\n}<br \/>\n}<br \/>\n\/\/&#8212;&#8212;-End of Loop&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/p>\n<p>\/\/&#8212;&#8212;-Start of Functions&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\nint checkButton() {<br \/>\nbutVal = digitalRead(butPin);<br \/>\nreturn butVal;<br \/>\n}<\/p>\n<p>void servo360() {<br \/>\ndirection = 100; \/\/ number &lt; 90: movement clockwise; number &gt; 90: movement counterclockwise; the actual number controles the speed of rotation<br \/>\nmyservo360.write(direction);<br \/>\n\/\/to be attached here: stop the movement when the toothpaste is empty. so we need to know the maximum<br \/>\n\/\/ in centimeters and calculate it back to the rotation, best is probably to measure it<br \/>\n}<\/p>\n<p>&nbsp;<\/p>\n<p>void servo180() {<br \/>\nopen(); \/\/ call function to open the box<br \/>\nwhile (scale.get_units() &lt; 50) { \/\/ do nothing as long as the weight recognised is smaller then 50 (we still need to find out which number actually makes sense through making a few measurements when the toothbrush gets put into the bracket, thats the number we need here)<br \/>\n}<br \/>\nwhile (scale.get_units() &gt; 50) { \/\/ call function close, when toothbrush gets put into the bracket \/ box<br \/>\nclose();<br \/>\n}<br \/>\n}<\/p>\n<p>void open() {<br \/>\ndelay(2000); \/\/ this delay gives the toothpaste a little bit time to settle onto the toothbrush<br \/>\ndirection = 1;<br \/>\nif (direction == 1) {<br \/>\nmyservo180.write(140);<br \/>\ndelay(100);<br \/>\n}<br \/>\n}<br \/>\nvoid close() {<br \/>\ndelay(2000); \/\/ this delay is very important, it should be as accurate as possible and be the average time that a person needs to put the toothbrush back into the bracket, and remove his hand, so that the door doesnt close if the hand is still in the door. maybe we have to use a sensor to make it nicer<br \/>\ndirection = 0;<br \/>\nif (direction == 0) {<br \/>\nmyservo180.write(0);<br \/>\ndelay(1000); \/\/ give to servo time to do the movement<br \/>\n}<br \/>\n}<\/p>\n<p><strong>Software:<\/strong><\/p>\n<p>The software side of the project is moving forward in terms of getting our program to the Raspberry Pi that will be used to provide information to the screen of our smartmirror.<\/p>\n<p>Since we discovered that making a touch-interface would be to expensive, we&#8217;ve decided to control the smartmirror using simple voice-commands. User identification is done using facial recognition. The backbones for both the voice- and facial recognition are done, the remaining work for these parts are the configurations needed to get them working on the Pi. We also need to integrate them into our main program which is made in Kivy.<\/p>\n<p>As a screen we have decided to port the Raspberry Pi to an iPad through the built-in VNC functionality of the Pi. Below is a video of the current concept.<\/p>\n<p>&nbsp;<\/p>\n<p><iframe loading=\"lazy\" title=\"Smartmirror on iPad\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/55c2O8KdMw4?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Electrical\/Mechanical: This is the first and well working draft of our arduino program to control the motors. \/*\u00a0Connect 5V on Arduino to VCC on Relay Module Connect GND on Arduino to GND on Relay Module Connect Power on Arduino to the Common Terminal (middle terminal) on Relay Module. *\/ \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/Relay\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ const int relay = 5; [&hellip;]<\/p>\n","protected":false},"author":55,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"image","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2339","post","type-post","status-publish","format-image","hentry","category-uncategorized","post_format-post-format-image"],"_links":{"self":[{"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=\/wp\/v2\/posts\/2339","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=\/wp\/v2\/users\/55"}],"replies":[{"embeddable":true,"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2339"}],"version-history":[{"count":4,"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=\/wp\/v2\/posts\/2339\/revisions"}],"predecessor-version":[{"id":2345,"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=\/wp\/v2\/posts\/2339\/revisions\/2345"}],"wp:attachment":[{"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2339"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2339"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2339"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}