# Float a Ping Pong Ball at Will!

4,568

32

2

Hello!

I have always been fascinated by things that are controlled wirelessly by hand motions which is probably why I own a Wii now that I'm thinking about it. But I haven't really gotten to doing any motion control of my own design before so I felt like I was missing out on some of my life goals.

But no more! With the aid of some extra components like a fan, an accelerometer, and a microcontroller to do some processing, I have mastered the art of floating a ping pong ball with only my hand.

### Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

## Step 1: The Secrets Behind the Trick

So what's really happening behind the scenes?

The accelerometer that I am using reports back a value representative of the measured acceleration along a single axis, in this case the x-axis (using Cartesian coordinates). The microcontroller can take that acceleration measurement and then send out an appropriate pulse-width modulation signal that will turn the fan on and off. The greater the measured acceleration (which is increased as the module is rotated due to gravity), the more frequently the fan is turned on so the ping pong ball floats higher. When the module is laid flat or not as tilted, the measured acceleration is closer to a value of 0 g, the fan will be on less of the time so that the ball does not float as high.

If we run through this calculation cycle at a reasonable pace, the ball will nicely float up and down in time with the rotating of the module.

Sound interesting? Let's get started!

## Step 2: Materials

Before you get started on any project, you'll need to gather up all the materials that you need. I ended up using these different materials:

• A chipKIT WF32 for the microcontroller, although other microcontrollers could also be used in it's stead
• A PmodACL2 to act as the accelerometer
• A clear polycarbonate tube (Amazon link) for the ping pong ball to float in without awkwardly flying off to the side. This particular tube was also chosen because it gave just enough clearance in its inside diameter to allow the average ping pong ball size (taken from my random sample of 5) to easily pass through without a lot air blowing around the sides
• the ping pong ball (anywhere you get it is fine since it doesn't need to be sturdy - just light and approximate size, a craft ball will do)
• A small 5V fan (Mouser link to a pwm controllable 5V fan of the appropriate physical size and power for the system)
• wires
• A 5V external power supply
• If desired, an adapter for the external power supply (I hand soldered mine with an appropriately sized barrel jack connector and a pair of wires). This isn't needed if you just want to take advantage of the barrel jack connector on the microcontroller board.

## Step 3: A Small Amount of Background

I'm personally a fan of having at least some understanding of how things work, so I'll share a bit of knowledge explaining how some of the components in the project are working.

Let's start with the PmodACL2. This is an accelerometer which reports acceleration data along each of the Cartesian axes (X, Y, and Z). Through SPI, you can read the acceleration registers and process the information from one axis (in my case I used the X-axis). Depending on the angle the Pmod is rotated at we will measure a 12-bit positive or negative acceleration.

The other bit of background is getting the fan to run at different speeds. One would think (or at least I thought) that you could simply apply a smaller voltage to a fan than what it is rated for and it will run at a slower speed. Unfortunately, this is not always the case; you may find that if you apply even half a volt less than what is marked on the fan it won't turn on at all as I found with the few fans that I tried out.

So instead, what I ended up doing instead was getting a PWM controllable fan and applying a pulse width modulation signal to the appropriate wire so that I could control the fan speed with relative ease. The fan is rated to take a PWM frequency as high as 25 kHz (which is what desktop computers typically run their fans at), but I found that the fan did not tend to get up to speed as easily when the pwm signal was changing that quickly, so I instead ran the fan at a 10 Hz frequency.

But what about the proportional control? The biggest thing to remember with proportional control is that there has to be a proportional change in energy occurring in the system. I initially tried a solid tube to float the ping pong ball in, but found that as soon as you get the fan spinning fast enough to overcome the force of gravity the ball will float all the way to the top. Awkward.

So, what I ended up doing was to drill small holes (about 1/8" in diameter) with about an inch spacing inbetween them all the way up one side of the 4 foot tube. This effectively enabled proportional control since more air leaked out of the system the higher the ball was floating, requiring the fan to spin faster to float the ball higher.

## Step 4: Getting the Circuit Ready

Naturally, you can always set up the circuit differently than I do if you have your own components or prefer soldering things together.

On this step, I have a few reference pictures detailing the various wire connections that I made. But to communicate in a nutshell of what I did on my breadboard, I powered the two sides of the breadboard with different voltages: one side I used the 3.3V line from the WF32 and the other side received the 5V line from the WF32.

I then wired up the PWM fan with the red wire attached to the 5V rail, the black wire to a grounded rail, and the brown wire connected to pin 6 on the WF32 to receive the PWM signal so that the fan speed can be controlled. The yellow wire on the fan is the tachometer which I did not need for this project so I left it unconnected.

The PmodACL2 communicates over SPI, so we'll connect it's pins 1-4 (CS, SI (also known as MOSI), SO (also known as MISO), and SCLK to pins 10, 11, 12, and 13, respectively, on the WF32. Pin 5 on the PmodACL2 should be connected to ground and pin 6 connected to the 3.3V rail on the breadboard. The rest of the pins (7-12 on the lower row on the header) do not need to be connected to anything for this project.

I use an external power supply with this project through either the barrel jack on the WF32 or the VIN and GND pins on the power header (J3) to ensure that the system has sufficient current to operate (plus, I'm not tethered to a laptop). To do so, I put J15 in the EXT jumper position and arrange the jumpers on J16 to have VU connected to 5V0 if I am using a 5V external power supply or have the jumpers set up so that VU is connected to LDO IN and LDO OUT is connected to 5V0 if I am using an external power supply that is rated between 7V and 15V.

## Step 5: More Thoughts

To hold the fan and tube in place, I ended up 3D printing (well, graciously accepted a co-workers offer to design and print) a stand that provided sufficient air flow for the 5V fan to float the ping pong ball the entire length of the tube. The part I ended up using can be download from this step (or eventually from Repables.com here--I keep receiving an error when I attempt to create an account).

To secure the fan you can either tap around the four rounded corners of the fan to hold it in place or use a small screw or piece of wire (I used soft brass) to hold the fan up. Otherwise, if the fan falls down while running, it will likely start to suffer as the flow of air that was helping to keep the components cool is suddenly cut off.

The code I used to program the WF32 is available in a zip file above for both MPIDE and the Arduino IDE with the chipKIT core. The library for the PmodACL2 can be downloaded from its Resource Center here. If you need it, details for installing libraries in MPIDE or Arduino can be found here and here, respectively.

## Step 6: Parting Thoughts

I hope this Instructable was somewhat informative how I ended up achieving a small goal of mine to pull off a magic trick -- even if I had some help from the electronics world to get it working. For those who are interested in the whole process I went through to get it going (including some of the problems and failures I went through) you can check them out on the Digilent Blog with Part 1, Part 2, and Part 3.

You can check out a picture of the project in action on Digilent's Twitter feed and a small video of it going on Digilent's Instagram. If you happen to be in the San Diego area during the ECExpo during ECEDHA 2016, it'll be shown off at Digilent's booth in Booth 308.

## Recommendations

• ### Internet of Things Class

22,806 Enrolled

## 2 Discussions

Hi quinnsullivan,

Oh goodness, I haven't gotten back to that! Thank you for pointing it out. I eventually got an account (apparently by not clicking to agree to the terms and service, having it tell me I needed to, and then clicking it). I uploaded the project to there now, but I'm still waiting for it to finish uploading and give me a final url. I'll post back when I can see it.