I stumbled on a fun, visceral way to show how Arduinos can sense and respond.
In preparation for a presentation at the Online News Association Conference in Los Angeles, I grabbed a Ping distance sensor I had in a bin. The Ping works like a bat — it emits an inaudible, high-frequency sound, and listens for the sound to bounce off an object. The round-trip time between ping and reflection reveals the distance.
To show that distance, I used a strip of multicolored LEDs called Neopixels, which are cool because you can control a whole line of lights using just three wires: one for power, one for ground and one connected to an Arduino data pin.
I initially planned to make the LEDs light up vertically or change colors when someone put their hand in front of the sensor. But then I realized it’d be far cooler to have the lights follow someone’s hand.
The experience is pretty cool. It feels almost magic!
The tech stuff
The example program for the Ping turns readings into centimeters, so all it took was some tinkering to figure out how many LEDs are in each centimeter. For my strip, the answer is about 1.34, and the key line is here:
leds_long = cm * 1.36;
The entire program is here.
And here’s how everything is wired up: