External Motorized Z-Axis Control for Microscopes (Arduino & MicroManager)
590 Views, 7 Favorites, 0 Comments
External Motorized Z-Axis Control for Microscopes (Arduino & MicroManager)
When you think of making something on a budget, you usually aim to save money while accepting some compromises in quality compared to commercial products. Achieving 90% of the quality at 50% of the cost is often considered a win. But today, we're pushing the boundaries—this project cost me about 0.1% of the price of existing commercial solutions. That's a 99.9% savings! And in this case, I'd say the result meets 100% of our lab's needs and about 50% of what a full commercial version can do.
In this Instructable, I'll show you how I built a simple, motorized mechanism to adjust the focus of our microscope in a teaching lab. It's based on a stepper motor that turns the microscope's focus knob, and the entire setup is controlled by an Arduino. Movement is managed via serial communication between the computer and the Arduino.
The key features of this z-axis setup are:
- Extremely low cost: ~$10–20.
- Sub-micron resolution: Precise movements of the focal plane.
- Computer-controlled: Works with simple serial communication interface (such as Arduino IDE) or through MicroManager, enabling z-stack captures.
- Non-invasive: Requires no permanent modifications to the microscope.
But let's also be honest and upfront - this solution has some limitations compared to commercial versions:
- No feedback loop: The system relies on counting steps, which may lead to accumulated errors over time.
- No autofocus (PFS): Long time-lapse experiments requiring autofocus are not supported.
- Manual control restricted: The attachment locks the focus knob during use, though it can be removed and reattached easily.
- Relative movements only: The system measures positions relative to a user-defined z = 0 micron plane. If the attachment is removed, this reference is lost.
Some of these issues can be solved quite easily, but that's for another day!
I hope you find some of this instructable useful, and if you have any questions or comments, feel free to share them at the comment section below!
Supplies
Tools:
Other than screwdrivers and such, you'll need access to a 3D printer and a laser cutter. If you can't find a laser cutter, you could design a motor mount and print it.
You'll also need:
- An Arduino board (I used Uno) & a USB cable for serial communication with the PC
- A small stepper motor (I used a common 28BYJ-48)
- A suitable stepper motor driver (I use the ULN2003)
- 5V Power supply (to power the stepper motor)
- Jumper wires (~6)
- Anti-slip stickers
- 6 mm plywood (for the base).
Motor Mount (& How to Customize)
The basic concept of this motorized z-axis is to turn the focus knob using a stepper motor. We use a Nikon Ts2R microscope, and the dimensions were adjusted to fit it, but they seem to be quite generic. In any case, you can modify the design to fit a different microscope and motor if you like. If you need help, leave a comment and I'll be happy to assist.
- Cut the parts out of 6 mm wood.
- Squeeze the two parts together and add glue if needed.
- Using two small bolts and suitable nuts, attach the motor to the motor mount.
Downloads
Knob Attachment (& How to Customize)
To turn the focus knob, we'll need some adapter between the motor and the focus knob. I wanted it to be easy to attach and remove and made it sure it doesn't obscure the scale.
- Print the adapter. I used clear resin (1st image), but you can print it out of PLA or anything you like.
- Add anti-slip stickers to provide better grip (2nd & 3rd images)
- Make sure it fits your focus knob.
- Attach the adapter to the motor (4th image).
If you want to modify the design to fit a different motor or a different focus knob, you can do it in TinkerCAD. You can stretch the model in all directions as needed, and use boolean operations to create a suitable hole for the motor. I attached the STL file I used, and a blank version that can be modified (rescaled & hole punched into it in TinkerCAD).
The Circuit
Now all we need to do is connect the circuit.
- Connect the Arduino to the stepper motor driver:
- Pin 8 of the Arduino to IN4.
- Pin 9 of the Arduino to IN3.
- Pin 10 of the Arduino to IN2.
- Pin 11 of the Arduino to IN1.
- Connect the stepper motor driver to a 5 volts (DC) power supply. Do not use the Arduino to power the motor.
- Connect the motor to the stepper motor driver.
I used a breadboard, but you can solder the parts if you want a permanent solution. I'll be doing that in the future.
Control Via Serial Communication
At this point, everything is connected. You can control the motor either through MicroManager or through direct serial communication, but each will require flashing the board with a different software. I advise you to first test that everything is working properly using a simple software and direct serial communication via the Arduino IDE.
This software will turn the motor in steps of a constant turning angle defined by the user, and pause between steps. These are defined in the software (first image). You're allowed to divide a full rotation into multiples of 2 (for example, a in each step, move 1/32 of a full turn, 1/64, 1/128...).
- Once you've set the magnitude of each step and the time interval between them, upload the software to the Arduino board.
- Using the serial communication, type RUN to initiate motion, STOP to pause, or FLIP to change direction.
Disclaimer - I used the assistance of ChatGPT to write the Arduino software.
Setup and Control Via Micro Manager
Controlling a stepper motor through MicroManager using an Arduino turned out pretty tricky. The concept I ended up using is to kind of hijack a communication protocol of a commercial product to control it. This also ensured that there's a user interface for it in MicroManager (a normal z-axis movement interface). This idea is not mine, but since I had a really hard time finding it and making it work, I decided it's worth sharing.
- Upload the software to the Arduino. Note that you will need to define the step size in microns. For example, my motor makes a full turn in 2048 steps, and the focus knob moves 100 microns in a full turn, so each step is ~0.04883 microns. That's your maximal resolution!
- Note the COM used in for the Arduino, and close the Arduino IDE.
- Open MicroManager. Go to the Hardware Configuration Wizard (Devices -> Hardware Configuration Wizard).
- Look for the MarzhauserLStep, select the ZAxis: LStep Z Axis (see first image) and press Add.
- Setup the connection (see second image):
- At the top, select the right COM. In my case the Arduino is connected via COM6
- Set the port properties. I set these a bit different than usual. Most importantly, I allowed for a long AnswerTimeout of 5 seconds. I guess this won't be needed when using a faster board.
- Once finished, press OK.
- You should see the installed device with it's status 'OK'. See 3rd image.
- Finish the setup and save the configuration.
Once installed, you should be able to open the stage controls and change the Z-axis! As easy as that!
Make sure to perform the commands slowly - let the previous one end before sending a new one. Otherwise you'll get an error message (which is harmless, but annoying).
Disclaimer - I used the assistance of ChatGPT to write the Arduino software.
Downloads
Mount and Test
That's it! Once you're done with software and assembly, mount the setup onto the microscope. Make sure it grips the focus knob firmly. Go ahead and enjoy your motorized z-axis. You can now take z-stack images or move with sub-micron resolution, which you couldn't do by hand. I tested moving the motor back and forth, and found that it returned to the same position reliably. I'm sure it may accumulate errors over time, but that seems negligible compared to what we need.
Thanks for reading my instructable! I hope it helps! I'd love to hear your thoughts and comments if you have any :)