Motion

When we want to get a really close look at something, we use microscopes or close-up lenses on cameras. But getting up close carries with it a well-known problem -- not all of the subject is in focus at the same time.

We might have the front of the subject in focus:

or we might have the back of the subject in focus:

but we can't get both at the same time.

In macro photography (the use of close-up lenses) this is called limited depth of field. It is often sought after for artistic reasons, and occasionally to add clarity to the foreground subject by deliberately blurring the background. But it is often quite useful to have the entire subject in focus in a single image.

To get around this problem, we can take a lot of pictures, each one a little closer to the subject, and use computer software to combine all the images into one,making adjustments for things that change as we get closer, such as the apparent size of the subject, the lighting, and the way it changes shape. While all of this processing is quite complicated, software that does it all automatically is inexpensive. Some examples of software to do photo stacking are Zerene Stacker, and Helicon Focus.

Here is such a stack of images, made into a short video, followed by the stacked photo:

The final image looks like this:

You can click on the image to see the full size result. Make it full screen on a good size monitor, and you can see all the detail of the tiny hairs, both in the foreground and in the background.

Of course, taking those 200 shots, moving the camera closer each time, would be a tedious task. But we have a tiny computer, which is perfect for handling tedious tasks. It never gets bored, or takes shortcuts.

 

To make the subject move closer to the camera lens, we will need a gadget called a linear stepper motor. With a little searching on the Internet, you can find one like that shown below for a few dollars:

A stepper motor is an electric motor that rotates just a few degrees each time a computer issues a step command. This one is tiny, and has been attached to a screw. As the motor turns, the screw advances a tiny platform by 0.16 millimeters for each step. If we issue 200 step commands, it will move 32 millimeters, or about an inch and a quarter. The entire range of travel is about 60 millimeters, or almost 2 and a half inches.

The motor has four connections on the bottom side that we solder wires onto so the computer can control it. In the photo below you can almost see we have added brown, red, orange, and yellow wires, from front to back on the bottom of the motor. Those wires lead to the solderless breadboard to the left, that has our tiny computer on it. I have also taped a cone of white paper to the little platform on the motor, to act as a light diffuser and provide a featureless white background for our subject, the acorn stuck to a rolled-up bit of sticky tape. You need to anchor the subject well, so it does not move between shots, since the motor jerks a little bit with each step.

In that photo you can also see an infrared LED to the right of the motor. Our tiny computer is going to use that to send infrared commands to the camera to take the picture. Our program will move the motor all the way back, then cycle through moving a step closer and then taking a picture, over and over for 200 times. Our subject is not quite 32 millimeters from front to back, so some of the photos at the beginning or end will be out of focus completely. Don't worry -- the stacking software will ignore those.

The breadboard circuit has our tiny computer at one end, and a motor control integrated circuit chip at the other end. They just barely fit together on this size breadboard.

The motor driver chip is the L293D, and it is actually very simple in its operation. You can think of it as a device that copies the pins on the tiny computer, but with more power. It has four inputs that connect to four pins on the tiny computer. It has four outputs that connect to the four wires in the stepper motor. It has a 3.3 volt power supply for the inputs, which is connected to the 3.3 volt pin on the tiny computer. It has another power pin, which supplies the power for the outputs, and it can be anything from 4.5 volts all the way up to 12 volts. It also has two pins that each enable one side of the chip, but we will be using both sides all the time, so we will keep those pins connected to 3.3 volts.

Our little stepper motor needs more current than the pins on the tiny computer can supply. The L293D chip can supply much more current (up to 1.2 amperes). It can be driven by as much as 36 volts, but without an extra heat sink attached, we recommend keeping the voltage down to 12 volts or less. We will be using a nine volt battery to drive our little motor.

The breadboard diagram is shown above (click on it for a larger view). The 9 volt battery connects to the power rows at the top and bottom of the breadboard. The four inputs on the L293D chip connect to D12, D11, D10 and D9, respectively. The infrared LED connects to D2 and ground. The shorter lead is the cathode lead, and that connects to ground. The enable pins and the power pins are all connected to +9 volts. The ground of the tiny computer is connected to the ground of the L293D chip, so they can agree on a baseline for zero volts.

The wires to the motor are the ones color-coded yellow, orange, red, and brown.

The code for the program is made much simpler by the use of two libraries. One of them, the stepper motor library, is already loaded in the Arduino IDE. The other one, which allows us to communicate with several popular brands of cameras, was written bySebastian Setz, and is available for download here. Once you have downloaded the library, add it to the Arduino IDE by clicking on the Sketch menu, and then clickingInclude Library, and then selecting Add .ZIP Library.

With both libraries now available, the code looks like this:

#include <stepper.h>
#include <multicameraircontrol.h>

enum { STEPS_PER_REVOLUTION = 64 };

//
// The Stepper class takes the pins in the order 1 3 2 4
//
Stepper motor( STEPS_PER_REVOLUTION, 9, 10, 11, 12 );

void setup()
{
  motor.setSpeed( 460 );
  motor.step( -400 );
}

Canon T3i( 13 );
int mstep = 0;

void loop()
{
  motor.step( 1 );
  T3i.shutterNow();
  delay( 1000 );
  if( mstep++ >= 400 )
  {
    mstep = 0;
    motor.step( -400 );
  }
}

The photo above shows a Canon T3i camera with a macro lens and a twin flash set up in front of the acorn. The camera is set to remote so the infrared LED can control it. To use the system, we anchor the subject carefully on the platform, then push the reset button on the tiny computer. The setup() routine then moves the platform all the way back. It will keep trying to move it even after it is all the way back, as a way of ensuring it will be in the right position no matter where we left it. Then it moves forward one step, triggers the camera, and repeats.

After 200 shots, we put all the images into Zerene Stacker (or Helicon Focus, or some other photo stacking program), and create our final image.