Introduction: Build an Arduino Based Thermal Scanner
Welcome to my first instructable!
Here you'll find all the information on how to build an automatic thermal imager using off-the-shelf parts. This project can help you identify static areas that need insulation from cold weather or find hotspots that needs shielding. While you won't get live pictures or see ghosts in a dark room, you will be able to detect slow heat changes on surfaces.
After this project is done for little $, you can scan a wall or windows to identify areas of improvement.
My ambition to create this project is from nasty New England weather and home energy efficiency. I have some bad windows and walls that need identifying for improvements and I didn't want to spend $$$ on a tool or to rent one. The thermal image I was looking for doesn't need to be live or fast, but it does need to provide an image of the surface to identify areas that are cold.
While running around with a single point IR might be enough, I wanted to see a map of the surface to see the extent and spread of the cold area.
Step 1: Materials Needed
Arduino programing/flashing tools
Processing programming tools (http://processing.org/ )
Here's what I used to make it:
*Wire for pin connections
*ZyTemp IR module (Harbor Freight Cen-tech for $9 on sale) (http://www.zytemp.com/products/tn205.asp)
*coat hanger wire
*small amount of wood
*18 gauge steel wire
*soldering iron + solder
Step 2: Hardware Setup - Electronics
First you need to get the hardware all set up. I used an old IDE connector and stripped out the pins for an easy connector, but anything will work fine. My only reason was to make it quickly removal and neat.
Pictures describe best, but here's a text breakdown:
pin 9/10 are servo Pan/tilt connections
pin 2 is IR clock
pin 12 is IR data
wire servo 1 white (pwm pos.) wire to pin 9, red to 5V and black to ground
wire servo 2 white wire to pin 10, red to 5V and black to ground
IR module (http://www.metrisinst.com/item_management/assets/files/TN9_UserManual_009.pdf):
wire IR data (pin D on module) to pin 12
wire IR clock (pin C on module) to pin 2
wire IR power (pin V on module) to diode from 3.3V supply
wire IR ground (pin G on module) to ground
(laser pointer versions -- solder a wire from V to the laser pos wire to have that on when measuring)
Remove the battery from the module!
Now you'r electronics are all set up and ready to be placed somewhere.
Step 3: Hardware Setup - Mechanical
Making a pan/tilt platform is a bit more of a complicated step. You can search online for many types/ideas but most of them are directly linked on the servo. I wanted one that didn't put much stress on the servo internals so I built a custom one.
I used 2 blocks that are about 1"x1" for the pivot points which are nailed to a thin piece of MDF.
The pivot mechanism is a coat hanger wire that was bent into position. It looks like a 'U' with wings... see second image. The U part is where the sensor is banded onto it and keeps the sensor aligned while moving. The link to the servo on this rod looks like an L shape that has a arm connecting the link and servo together, I used a light weight steel rod that's strong enough for pushing but can be bent to align the 90deg mark.
The platform of this is a busted HDD, if you don't have these you can probably get away with a flat piece of wood as the base and put a pin as the center point. Make a hole in the tilt platform for the pin to fit in so that it can swivel around it.
With the HDD, I used an 18 gauge equivalent drill bit on my drill press to make a small hole in the aluminum spindle. Don't drill too deep or you may lock up the rotor! Use the 18 gauge wire and make a small 90 deg bend, fit it in the hole and connect up to the pan servo, make sure it doesn't slip out easily (use a Z-shaped bend on the servo).
If you're using the HDD as the platform, make sure to bolt it to the tilt platform or the servo torque will knock it off. I re-used some of the HDD screws for that and cardboard for washers. If you made a simple pivot platform you probably skipped the HDD drilling part. I would suggest making a hole (same size as the wire) near the pivot point on the tilt platform as your pan control arm connection.
Step 4: Software - Arduino Portion
OK! Now that you're all done with the hardware, let's move onto the software.
The Arduino is used as an interface in this project. It allows the servos and IR sensor to communicate easily with the computer using simple commands.
While this is a "simple" operation, there are some critical areas that need to be addressed. One of those issues that I ran into a lot was communication syncs. Basically by the time the microprocessor was ready to read the command, the computer has not completed sending it. A simple solution to this is to assign a "command ready" character. I chose a semi-colon as my terminator.
To make sure that the commands are in a serial aspect that will halt the computer from trying to read a temperature while the IR sensor was in motion, I need a response method. A solution that, common for communications, is called ACKs, or acknowledgement. Let's say we execute "p120;" (pan to 120deg), we want the computer to wait for the microprocessor to say "AP120;" (ack pan 120). Once the ACK is received the program can continue to fetch a temperature or the next set of commands.
Another complicated part is reading the IR data from the serial port on the sensor. In order to read the data we must do something called "bit-bang". This involves setting up an interrupt on the clock falling edge to read the bit on the data line. Each "burst" of data that comes in contains a header and some data that needs to be decoded.
Reading the pdf for the ZyTemp module (http://www.metrisinst.com/item_management/assets/files/TN9_UserManual_009.pdf ) on page 13 you can see the data sequence for each of the bursts of data. Instead of spending some time on this, I decided to do a quick search and found someone else already wrote this for the arduino (they did a precise hotplate temperature controller). The source is documented in the code for reference and credit for the ideas.
All in all the Arduino code, when compiled, takes 7982 bytes of space.
Commands to know (all commands must end with a ';':
p<n>; #pan to <n> deg
t<n>; #tilt to <n> deg
r; #read the IR sensor object
a; #read the IR sensor ambient temp
use these to adjust protection zones (doesn't allow a pan/tilt command to work if out of bounds - some servos will chew them selfs up if they try to go beyond a max)
u<n>; #set upper servo boundary (protection) default is 145 deg
l<n>; # set lower servo boundary (protection) default is 35 deg
Step 5: Software - Computer Portion
Now that you have flashed the arduino, let's look at the PC portion of the software.
To achieve a simple and quick program I used Processing. It's Java based and can run on many platforms so compatibility is high. The program will use parameters in the setup() to define an area to scan. Each measurement is plotted on a simple grid and color coded relative to all other cells, meaning red = hot and blue = cold (relative of course!).
There's just a few tweaks to the program that most people will need to do:
1. Define the bondary to be scanned (see previous step for default boundary limits for protection, don't issue something beyond that or th program will "hang"). I would suggest in the Arduino dev tool use the serial console and type in some of the boundaries you want to scan. If you have the laser pointer on it's easy to see where it will scan. Use the commands from the last step for this stage.
1a. Once you find the boundaries, modify the pan_min,pan_max,tilt_min and tilt_max variables in the setup() to match.
2. Set up how many steps you want to measure (as seen in the line "size(size*20,size*20); //colls, rows". This is somewhat open to interpretation... while you can do a 100x100 grid, it would take forever to scan. If you read the ZyTemp info, you'll know it scans at a 1.4Hz rate.. the program is set to read at 1.2Hz (t prevent errors, etc) so that's 1.2 measurements every second. Any faster an you'll get a blur in the "image" as the sensor doesn't update that fast.
Here's some examples:
You want to measure a wall that's wide, set the range for the pan high then the tilt. Set the grid to something relative to that area, say 25,15. This will make the image wider and shorter in height. If the cell size is too big you can reduce it by changing "int size=50;" to something like 40. You might get text overlaps for each cell so be careful about that.
The resulting image you'll get in the gui can be copied to a editor (gimp/photoshop...) and overlapped with a real image
Step 6: Thoughts
Some improvements i would like to make at some point:
Make a nice gui to define the range limits (sliders instead of manual work)
PDF export, or something similar, to dump the image of the scan
We have a be nice policy.
Please be positive and constructive.