{"id":12953,"date":"2016-03-17T09:00:54","date_gmt":"2016-03-17T16:00:54","guid":{"rendered":"https:\/\/blog.digilentinc.com\/?p=12953"},"modified":"2021-06-16T14:19:46","modified_gmt":"2021-06-16T21:19:46","slug":"levitating-a-ping-pong-ball-first-serious-attempt","status":"publish","type":"post","link":"https:\/\/digilent.com\/blog\/levitating-a-ping-pong-ball-first-serious-attempt\/","title":{"rendered":"Levitating a Ping Pong Ball &#8211; First Serious Attempt"},"content":{"rendered":"<p>Welcome back to the Digilent Blog!<\/p>\n<p><a href=\"https:\/\/digilent.com\/blog\/index.php\/levitating-a-ping-pong-ball-first-steps\/\" target=\"_blank\" rel=\"noopener\">Last time<\/a>, I showed my initial attempt\u00a0into living out my dream of performing magic tricks (with a little help from the electronic realm), and found that my &#8220;oh yeah, sure, no problem&#8221; attitude was not going to work. So I came up with a new plan of using the <a href=\"https:\/\/digilent.com\/shop\/pmodmaxsonar-maxbotix-ultrasonic-range-finder\/\" target=\"_blank\" rel=\"noopener\">PmodMAXSONAR<\/a> as an input for my desired height and using a <a href=\"https:\/\/digilent.com\/shop\/pmodod1-open-drain-output\/\" target=\"_blank\" rel=\"noopener\">PmodOD1<\/a> or <a href=\"https:\/\/digilent.com\/shop\/pmodoc1-open-collector-output\/\" target=\"_blank\" rel=\"noopener\">PmodOC1<\/a> as my method for controlling the fan speed to levitate the ball in a nice four foot <a href=\"http:\/\/www.amazon.com\/dp\/B000OMHJJO\/ref=biss_dp_t_asn\" target=\"_blank\" rel=\"noopener\">polycarbonate tube<\/a>. Let&#8217;s see how that turned out.<\/p>\n<p>I definitely fought with this one for awhile as I was too stubborn to give in, at least not\u00a0quite as\u00a0easily as I had with my first attempt. I did see some success and learned a lot about the balance between usability, reliability, and effort exerted to make the first two items viable. In principle, I would receive distance information from the PmodMAXSONAR (since it&#8217;s a nice ultrasonic sensor to detect objects, such as my hand, that are located in front of it), which I would then process within the microcontroller to see the measured distance is within my desired\u00a0sensing range.<\/p>\n<figure id=\"attachment_13045\" aria-describedby=\"caption-attachment-13045\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-13045\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/03\/First-Serious-Attempt-setup-600x381.jpg\" alt=\"The setup of the more serious attempt with the microcontroller, the PmodMAXSONAR, the PmodOC1, and the fan holder.\" width=\"600\" height=\"381\" srcset=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/03\/First-Serious-Attempt-setup-600x381.jpg 600w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/03\/First-Serious-Attempt-setup-768x487.jpg 768w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/03\/First-Serious-Attempt-setup-1024x650.jpg 1024w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/03\/First-Serious-Attempt-setup-800x507.jpg 800w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><figcaption id=\"caption-attachment-13045\" class=\"wp-caption-text\">The setup of the more serious attempt with the microcontroller, the PmodMAXSONAR, the PmodOC1, and the fan holder.<\/figcaption><\/figure>\n<p>If the reported distance was between 6 and 36 inches, I had the microcontroller calculate a corresponding duty cycle to run the fan with the PmodOC1 (I decided against the PmodOD1 since my small fan would not need as much current as the PmodOD1 is capable of providing) as my method of switching the 5V supply to the fan on and off. That&#8217;s when I started running into some problems.<\/p>\n<p>The first was that I didn&#8217;t stop and consider what the &#8216;OC&#8217; meant in reference to the PmodOC1\u2014it means open collector. This means that the collector portion of the <a href=\"http:\/\/www.instructables.com\/id\/Transistor-Basics-BJTs\/\" target=\"_blank\" rel=\"noopener\">NPN BJT<\/a>\u00a0is not connected to the positive voltage supply that it would normally be connected to, implying that simply connecting the output on the PmodOC1 to whatever you trying to run does not do anything (as I found out). Rather, the ground of whatever you are attempting to run needs to be attached to the output on the PmodOC1 (the collector) and the positive wire (or anode in the case of an LED) needs to be attached to your positive power source. This configuration will allow current to flow through the system when you apply enough current to the base, as shown in the diagram below.<\/p>\n<figure id=\"attachment_13036\" aria-describedby=\"caption-attachment-13036\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-13036\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/03\/BJT-with-a-fan-600x350.png\" alt=\"When power is applied to the Base, the gate is closed so that current can flow from VCC, through the fan, through the BJT, and then to GND.\" width=\"600\" height=\"350\" \/><figcaption id=\"caption-attachment-13036\" class=\"wp-caption-text\">When power is applied to the Base, the gate is closed so that current can flow from VCC, through the fan, through the BJT, and then to GND.<\/figcaption><\/figure>\n<p>After figuring this out, I promptly found that once the fan reached a certain speed, the ping pong ball would simply travel all the way to the top of the tube with no proportionality aspect in terms of height whatsoever. Turns out (as I should have realized), that if you want proportional height control, you need to implement a way for a linear change in energy (either an increase or decrease) to occur. Because we want the fan to blow more strongly as the measured hand height increases, we need to slowly increase\u00a0the amount of air that is released from the tube as the ball floats higher in the air by drilling small holes about an inch apart all the way up the tube.<\/p>\n<figure id=\"attachment_13059\" aria-describedby=\"caption-attachment-13059\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-13059\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/03\/Tube-with-air-release.jpg\" alt=\"Proportional control can be achieved with consistent air release valves.\" width=\"300\" height=\"375\" \/><figcaption id=\"caption-attachment-13059\" class=\"wp-caption-text\">Proportional control can be achieved with consistent air release valves.<\/figcaption><\/figure>\n<p>In this endeavor, I was wildly successful\u2014everything worked as exactly as it was supposed to. And then the moment ended.<\/p>\n<p>Apparently, when you use things in way that they are not designed to be used, like rapidly turning a DC fan on and off, they tend to deteriorate as evidenced when I found that having the fan on full blast only floated the ball a third of the way up the tube rather than threatening to blow it out of the tube entirely. Additionally, the PmodMAXSONAR, while great in principle, proved to not be as user friendly as I originally envisioned. As an ultrasonic range finder, it does best at detecting flat objects such as a wall or ceiling whereas the human hand tends to have multiple curves, so a clean ultrasonic signal is not returned to the Pmod. Also, people are\u00a0never quite sure if their hand is\u00a0directly above the PmodMAXSONAR, leading to some skewed results.<\/p>\n<p>With all this in mind, I will make another, (and hopefully final), attempt to successfully float a ping pong ball with a <a href=\"https:\/\/digilent.com\/shop\/pmodacl2-3-axis-mems-accelerometer\/\" target=\"_blank\" rel=\"noopener\">PmodACL2<\/a> that I can tilt and measure the acceleration from to execute height control, a DC fan designed to be controlled by a <a href=\"http:\/\/www.instructables.com\/id\/How-to-use-Pulse-Width-Modulation\/\" target=\"_blank\" rel=\"noopener\">PWM<\/a> signal eliminating the need for the PmodOC1), and a taller stand to enable more air flow.<\/p>\n<div class='watch-action'><div class='watch-position align-left'><div class='action-like'><a class='lbg-style6 like-12953 jlk' data-task='like' data-post_id='12953' data-nonce='ee750c7abc' rel='nofollow'><img src='https:\/\/digilent.com\/blog\/wp-content\/plugins\/wti-like-post-pro\/images\/pixel.gif' title='Like' \/><span class='lc-12953 lc'>+1<\/span><\/a><\/div><div class='action-unlike'><a class='unlbg-style6 unlike-12953 jlk' data-task='unlike' data-post_id='12953' data-nonce='ee750c7abc' rel='nofollow'><img src='https:\/\/digilent.com\/blog\/wp-content\/plugins\/wti-like-post-pro\/images\/pixel.gif' title='Unlike' \/><span class='unlc-12953 unlc'>0<\/span><\/a><\/div><\/div> <div class='status-12953 status align-left'><\/div><\/div><div class='wti-clear'><\/div>","protected":false},"excerpt":{"rendered":"<p>James and the Giant Fight with Gravity: The second installment of the saga!<\/p>\n","protected":false},"author":17,"featured_media":13066,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38,4327,1561],"tags":[],"ppma_author":[4469],"class_list":["post-12953","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-expansion-modules","category-projects","category-applications"],"jetpack_featured_media_url":"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/03\/Youre-A-Wizard-James-With-Sparks-1000.png","authors":[{"term_id":4469,"user_id":17,"is_guest":0,"slug":"jamescolvin","display_name":"James Colvin","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/509febded809c5de0423909f6ae6587f?s=96&d=mm&r=g","author_category":"","user_url":"","last_name":"Colvin","last_name_2":"","first_name":"James","first_name_2":"","job_title":"Applications Engineer \/ Technical Support Engineer \/ Product Support Engineer \/ Technical Writer \/ the person to bother about T&M and JTAG when the senior design engineer is busy","description":"A local Digilent employee who is sometimes tricked into making other content besides documentation and supporting customers on the Digilent Forum, but then I get to write a little more informally so that's a plus. \r\n\r\nA sassy engineer, lover of puns and dad jokes, father and husband. \r\n\r\nI know both way too much and simultaneously almost nothing about a number of nerdy topics. If you want to hear me rant, ask me what data rate USB C operates at."}],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts\/12953","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/comments?post=12953"}],"version-history":[{"count":0,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts\/12953\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/media\/13066"}],"wp:attachment":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/media?parent=12953"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/categories?post=12953"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/tags?post=12953"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=12953"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}