Project tutorial

Driving a Focus Stacking Rail Using an Arduino © GPL3+

Driving my focus stacking rail using an Arduino to achieve micron steps.

  • 305 views
  • 1 comment
  • 3 respects

Components and supplies

About this project

Hardware

This project is a part of my larger project on focus stacking of fern gametophytes.

This section explains what hardware is required for an Arduino-driven rail system, and how it is all wired up. We are only covering the electronics here and the other hardware is discussed in the main page.

The full setup from several angles

This is the full setup from above. From top to bottom, the parts are the microscope block connected via cogs to the stepper motor. The stepper motor is then wired to a stepper motor shield, which is in turn wired to the Arduino at the bottom of the photo.

This is the same setup from the side. From left to right, the parts are the Arduino, the stepper motor shield, the stepper motor, and then the cogs from the stepper motor to the microscope section on which the camera is mounted.

Below, again, is the full setup, but shown from slightly above.

Wiring positions on the Arduino

The three images below show in detail where the jumper wires need to be connected. Further information about where these wires go is given in the following sections.

Stepper motor shield to Arduino:

The stepper motor shield is shown in this image:

The wire connections from the top left corner of the stepper shield to the Arduino are as follows:

GND to GND STEP to Digital 2 DIR to Digital 3

Stepper motor to stepper motor shield

The stepper motor has four wires which are all unlabelled. It took us some work to figure out which was which, so that we could connect them to the right places. Our four wires are blue, green, red and black. They are connected to the pairs of holes labelled "A" and "B" at the bottom centre of the shield as seen in the photo above.

Power cable to stepper motor

The stepper motor needs power to operate, and this is provided via the stepper motor shield. We used a 12V transforner plug, the wires of which are soldered directly onto the stepper motor shield. Those wires are the black wires visible in the bottom left part of the image above. They are soldered to GND and M+.

Infra red remote control:

The infra red remote control is wired up to the Arduino, so that the shot can be triggered automatically, after each forward movement of the camera. Each time the camera has moved forward, the Arduino triggers the infra red remote control bulb to light, causing the camera to take a shot.

The photo below shows the position of the remote control in the setup.

The two images below show how the infra red camera trigger is wired up. Tim had to take the case right off and then soldered on wires, and firmly connected them using a hot glue gun.

These wires are connected to the Arduino as follows:

Digital 13 to IR + terminal nearest bulb. GND to IR terminal furthest from bulb.

The cogs

Lastly, below is the set of cogs that allow the stepper motor to drive the microscope block. The cogs are fairly soft plastic and we just got them off the shelf in Maplin. We cut the insides out and they slid easily onto the microscope knob.

Code

The code (attached below) moves the microscope block forward by some tiny amount (how ever far we tell it to go), and then it pauses for the system to settle and triggers the camera to take a shot.

We also have a fast version that drives the rail much faster so that ferns do not have so much time to dry out.

Once the code has been uploaded to the Arduino, it will keep running whenever the battery is plugged in. So when using this computer to drive the focus block, just start it by plugging in the battery and stop it by unplugging the battery. Any modification to the code, for example to change the step size, will require reattaching the arduino to the computer and modifying the code again.

Code

Fast Arduino codeC/C++
This code enables the Arduino to drive the focus rail with 17 micron increments and rapid movement of the rail.
// Number of pictures to take
#define shots 100
// How far to advance between shots
// 128 steps == 1 mark on the fine control == 1 micron
#define MICRON 128L
#define distance (17 * MICRON)

//Declare pin functions on Arduino
#define stp 2
#define dir 3
#define fire 13

void setup() {
  pinMode(stp, OUTPUT);
  pinMode(dir, OUTPUT);
  pinMode(fire, OUTPUT);
  digitalWrite(stp, LOW);
  digitalWrite(dir, HIGH);
  Serial.begin(9600); //Open Serial connection for debugging
}

//Main loop
void loop() {
    long int i, j;
    char input;

    Serial.println("Press Enter to start");
    do {
        input = Serial.read();
    } while (input != '\n');
    
    for (i = 0; i < shots; i++) {
        trigger();
        for (j = 0; j < distance; j++) {
            step();
        }
    }
}

// Power on the IR trigger circuit to fire the camera
void trigger()
{
    delay(1000); // wait for vibration to settle
    digitalWrite(fire, HIGH); // take the picture
    delay(1000); // wait for that to happen
    digitalWrite(fire, LOW); // disable the IR circuit again
}

// Advance the motor by one step
void step()
{
    digitalWrite(stp, HIGH); //Trigger one step forward
    delayMicroseconds(25);
    digitalWrite(stp, LOW); //Pull step pin low so it can be triggered again
    delayMicroseconds(25);  
}
Slow Arduino codeC/C++
This code enables the Arduino to drive the focus rail with small micron steps, and slow movement to allow settling between movements.
// Number of pictures to take 
#define shots 100 
// How far to advance between shots 
// 128 steps == 1 mark on the fine control == 1 micron 
#define MICRON 128L 
#define distance (17 * MICRON) 
//Declare pin functions on Arduino 
#define stp 2 
#define dir 3 
#define fire 13 
void setup() { 
pinMode(stp, OUTPUT); 
pinMode(dir, OUTPUT); 
pinMode(fire, OUTPUT); 
digitalWrite(stp, LOW); 
digitalWrite(dir, HIGH); 
Serial.begin(9600); //Open Serial connection for debugging 
} 
//Main loop 
void loop() { 
  long int i, j; 
  char input; 
  Serial.println("Press Enter to start"); 
  do { 
      input = Serial.read(); 
  } while (input != '\n'); 
  for (i = 0; i < shots; i++) { 
      trigger(); 
      for (j = 0; j < distance; j++) { 
          step(); 
      } 
  } 
} 
// Power on the IR trigger circuit to fire the camera 
void trigger() 
{ 
  delay(1000); // wait for vibration to settle 
  digitalWrite(fire, HIGH); // take the picture 
  delay(2000); // wait for that to happen 
  digitalWrite(fire, LOW); // disable the IR circuit again 
} 
// Advance the motor by one step 
void step() 
{ 
  digitalWrite(stp, HIGH); //Trigger one step forward 
  delay(1); 
  digitalWrite(stp, LOW); //Pull step pin low so it can be triggered again 
  delay(1);   
} 
Github
https://github.com/BioMakers/23_Focus-stacking-system-for-gametophyte-ferns

Comments

Similar projects you might like

Pac-Man LED Pixel Panel Costume

Project tutorial by Ben Muller

  • 4,981 views
  • 4 comments
  • 86 respects

LoRa Gateway for DeviceHive

Project tutorial by DeviceHive IoT team

  • 1,320 views
  • 2 comments
  • 17 respects

IoT Bird Feeder with Sigfox and Tweeter

Project showcase by Gaël Porté

  • 388 views
  • 0 comments
  • 7 respects

Raspberry Pi and Arduino Laptop

Project tutorial by Dante Roumega

  • 17,831 views
  • 6 comments
  • 45 respects

SmartWay

Project tutorial by Universum

  • 275 views
  • 0 comments
  • 5 respects

Arduino-Based Automatic Guitar Tuner

Project tutorial by Ben Overzat

  • 3,618 views
  • 0 comments
  • 12 respects
Add projectSign up / Login