By Tom Smith

It started as an off-hand challenge. While observing a ping pong ball suspended in a clear tube below a Motion Detector and buoyed by a small fan—a favorite demonstration of how we can use our sensors with NI LabVIEW software—Dave Vernier said, “You know, I bet we could do this with an Arduino. Maybe you should look into that!”

I started with a quick refresher on Proportional, Integral, and Derivative (PID) control. Each of these components evaluates a characteristic of the difference between the set point and the location of the actual measured value. In my case, the set point was the height I wanted the ball to be in comparison to the actual location, as measured by the Motion Detector.

  • Proportional takes into account how far off you are from your set point—the bigger the difference, the bigger the change in my fan speed.
  • Integral considers the time and distance the ball is from the set point.
  • Derivative looks at how fast the ball is responding.

These different factors are weighted (or tuned) and added together to create an algorithm to drive the fan speed.

I mounted the Vernier Arduino Interface Shield onto the SparkFun® RedBoard and then attached my Motion Detector and Digital Control Unit. The DCU was used to control the fan. With the physical setup and PID control research complete, I began programming.

Not feeling compelled to start from scratch, I copied our Arduino Sketch for the Motion Detector and searched the Arduino website for existing sample code. If you aren’t familiar with the Arduino website, it has a wealth of libraries and sample code ready to be used. There was a PID Library in their reference materials that included a helpful tutorial advising how to import it. It took a little tinkering, but it was soon up and running.

I also found tutorials by Top Tech Boy for combining VPython with Arduino code. You can view those tutorials at

Eager to watch a visual representation of my PID-controlled floating ping pong ball, I ate lunch at my desk while I figured out how to get my real-time data into VPython.

Here’s what I learned:

  1. It is really easy to connect Vernier sensors and the DCU to an Arduino for creative and exciting projects.
  2. There are a lot of easy-to-implement solutions for most any application using Arduino. You don’t have to learn everything all at once. Many users share their code online to help other users get started. You and your students are bound to learn a thing or two in the modification process.
  3. You never know where a project like this will take your students (or you)!


For more ideas of how to get started, go to