What news from AWS re:Invent last week will have the most impact on you?
Amazon Q, an AI chatbot for explaining how AWS works.
Super-fast S3 Express storage.
New Graviton 4 processor instances.
Emily Freeman leaving AWS.
I don't use AWS, so none of this will affect me.
Tech Life

Off-The-Shelf Hacker: Repurpose Your DIY Projects

Dec 26th, 2015 6:27am by
Featued image for: Off-The-Shelf Hacker: Repurpose Your DIY Projects

As I mentioned in my previous Off-The-Shelf Hacker columns, I’m a big fan of modularizing my projects so I can mix and match parts as needed. Last Christmas my daughter gave me a little 1.8” color TFT display. It took an hour or so to get it working with an Arduino. Since then the little screen has seen service in my Steampunk conference badge series of prototypes, using a plain-Jane Arduino, the Yun and even the Raspberry Pi.

A while back, I took delivery of an HRC-SR04 ultrasonic range finder module from Amazon. As you might expect, it was only a matter of time before the range finder found itself hooked up to the 1.8” Arduino/TFT screen combination, in some kind of a portable format. Putting a quick proof-of-concept together was pretty easy. I just pirated the Arduino Pro-Mini, battery and nano-regulator module from version 1 of the Steampunk badge, configured the software and in a short time was measuring distances with sound.

Let’s see what it takes to get the HC-SR04 reading distances and outputting those values to the TFT display. Next week, we’ll look at how you can use and package this technology into a project.

Repurpose Your Projects

The basic Arduino Pro-Mini can serve as the base for a lot of interesting projects.

Take a look at the following schematic. I removed the DS18B20 digital temperature sensor and red LED features (from the schematic), then replaced them with the HC-SR04 ultrasonic range finder. Adding the wires and sensor took all of 15 minutes.

Arduion Pro-Mini/LCD/Ultrasonic Sensor Schematic

Arduino Pro-Mini/LCD/Ultrasonic Sensor Schematic

Otherwise, the schematic is the same as the old badge project.

That’s the beauty of module design and using microcontrollers in your projects. In this case, the Arduino Pro-Mini and TFT display combo can do multiple jobs, simply by hooking up different sensors and output devices, then modding the code.

Speaking of the code, reading an ultrasonic sensor isn’t overly complicated either.

I used the NewPing Arduino library for this project.

First, we go through the usual initialization steps of defining pins, setting up variables and initializing the ultrasonic sensor and serial communications. I typically like to include serial output when developing code, for diagnostic purposes. You can always drop the println statements and such after everything is running right. Keep in mind also, that most Arduinos have about 32 KB of program space. Naturally, one space saving technique is to eliminate any extra, non-essential serial text producing code.

Finally, the main loop reads the ultrasonic sensor, does a conversion from its integer output to a character string and sends it to the TFT display. Using a black background, the distance and “inches” are printed on the screen, at the location (10, 50). The same string is then printed in black, to erase the white text, after which the cycle is repeated. It’s necessary to erase the text with black text, so the values don’t pile up on top of each other, eventually resulting in just white squares on the screen. It’s kind of brute-force, although it works. Use a minimum of 29 milliseconds between pings to make sure you get a good reading. I set the delay at 200 because when smaller values are used, the numbers on the screen blink increasingly faster and it becomes annoying.

You’ll notice, in the opening picture above, that the device is running on 4 AAA batteries. That’s a carry over from the Steampunk badge and will work fine in a wearable project. Make sure the switch is turned off when the USB-to-Serial cable it hooked up for programming. I also like to take a battery out of the holder, just in case the switch is inadvertently left in the on position or when stuffing the device in my computer bag.

Yes, I know, the Dallas DS18B20 is still hooked up in the picture. As my story deadline loomed I chose to sideline that “feature” for another time. Off-the-shelf hackers always dream about what’s next, but it’s good to keep potential project creep in check, so as not to have undesirable downstream workflow effects.

Wrap Up

Being able to measure from 1 inch to about 10 feet has real application in the physical computing World. Wiring it up and putting the code together is pretty straightforward as well.

Next week, I’ll cover a few interesting applications I’ve found around the Web, such as, how to increase the range with a reflector and how to find the position of your garage door, using a sonar sensor. We’ll also talk about ways to incorporate sonar in a wearable.

Until then, may all manner of cool physical computing hardware materialize in your Christmas stockings.

Group Created with Sketch.
TNS owner Insight Partners is an investor in: Shelf.
THE NEW STACK UPDATE A newsletter digest of the week’s most important stories & analyses.