November 18th, 2026

My USB microscope lives on the print head of my Creality Ender 3 V2. The printer is a surprisingly good microscope stage: it moves X, Y and Z in fractions of a millimetre, it takes plain G-code over USB, and it's already sitting on my desk. This post covers how that turned into a motorized, 4K microscope rig. The printer scans the sample, an Arduino Nano and a servo turn the microscope's zoom dial through a 3D-printed gear, and a single web page drives all of it.

Everything I printed is free to download below: the current STL files, the OpenSCAD source, the Arduino firmware, an interactive 3D assembly view and the control page itself.

Rear view of the v20 microscope zoom drive render showing the servo slide, cradle, ring gear and leveler
The current v20 drive from behind: v18 base (green), microscope clamp and 44-tooth ring gear (gold), servo slide (blue), cradle (orange), stop bar and leveler (red/pink). Rendered from the actual STL files.

How it started: 640 × 480 and a lot of stitching

The first microscope on the printer was a small USB scope that shows up on Linux as a KJMSF03A. It works, but its camera tops out at 640 × 480, about 0.3 megapixels. So the first thing I built was a browser page that talks to the printer over Web Serial and shows the camera feed. Arrow keys move X/Y, + and − move Z, and Shift, Ctrl and Alt switch between 10 mm, 50 mm and 0.1 mm steps.

Because a single frame was so small, the page grew a mosaic scanner. The printer steps the scope across a 2 × 2, 3 × 3, 4 × 4 or custom grid with overlapping frames, and the page stitches them into one big image. An 8 × 8 grid of 640 × 480 frames came out at about 1800 × 1780 pixels. I also tried Fiji for the stitching. It worked, but it showed me the real limit was the camera.

Why I went 4K

With mosaics working, I asked the obvious question: is there a microscope like this, but 4K? The research turned up a catch. Many "4K" microscopes only save 4K photos to their own screen or app and stream much less over USB. Some lab-grade 4K scopes don't list Linux support at all. For my setup the camera had to stream real high-resolution video over USB on Linux and have a cylindrical body I could clamp to the print head.

Even plain 1080p is about 2.1 megapixels, nearly 7× the pixels of my 640 × 480 camera, and 4K is four times 1080p again. So I upgraded to a 4K WiFi/USB digital microscope (linked in the materials list) that advertises 3840 × 2160 USB video and that a buyer reported working on Ubuntu with no extra software. I treated the "4K" as something to verify: on USB 2.0 the 4K mode is compressed and runs at only a few frames per second, so 1080p is smoother for live focusing and 4K is best for snapshots. The control page has a resolution picker, a large preview and a fullscreen mode so you can actually see the full picture.

Motorizing the zoom

The printer handles X, Y and Z, but the microscope's zoom/focus dial is manual. I wanted the computer to turn it, too. I already had an Arduino Nano clone on a breakout board and a small 9 g SG90-style continuous-rotation servo on hand.

Getting from "I have a servo" to a drive that actually turns the dial took twenty-odd versions. The short version:

  • A split ring gear clamped to the dial came first. The clamp needed rework, so I switched to a rubber friction wheel on the servo pressing against the dial.
  • Over many versions the friction-wheel carrier gained a separate microscope carriage with 12 mm of front-to-back adjustment, a front Nano tray, a rear mounting loop that clips to the printer, proper servo screw supports, a lighter frame and an anti-sag brace.
  • When the new 4K microscope arrived, the wheel touched its dial perfectly, but the little SG90 couldn't turn it, and even a belt just slipped. So it was back to gears: a 44-tooth ring gear that clamps onto the 32.5 mm rubber dial.
  • The ring went through a dovetail version that was too tight to assemble, then a butt-joint version held together by a rubber band.
  • The SG90 still couldn't budge the stiff zoom, so I moved to a Feetech FS5113R standard-size continuous servo (about 13 kg·cm, versus roughly 1.8 kg·cm for the SG90), powered from its own 5 V 3 A supply.
  • v20 is the drive for that servo, with a 25-tooth pinion bolted to the servo's round horn and a jack-screw stop bar to set the mesh. v20b added cable notches to the cradle, and v20c added a levelling leg. The finished v20 drive turns the zoom dial perfectly, all the way through its range.

The whole messy middle, with every version's files and what went wrong, is in its own post (linked at the bottom). Here I'll stick to what works now.

v20 microscope zoom drive render: ring gear on the dial, FS5113R servo in its cradle, Nano tray and leveler
The v20 drive: the FS5113R (dark) sits in the orange cradle, and its 25-tooth pinion meshes with the gold 44-tooth ring on the microscope's zoom dial.

Explore the 3D assembly

The easiest way to understand how it goes together is the interactive viewer. You can orbit it, toggle each part, explode the view, zoom in on the gear mesh or the leveler, and slide the microscope and ring height through their adjustment range. It runs entirely in your browser.

Open the interactive 3D assembly (v20)

Tools required

  • A 3D printer with at least a 220 × 220 mm bed. I use an Ender 3 V2. The closest current equivalent is the Creality Ender 3 V3: Creality Ender 3 V3 on Amazon (paid link). It isn't in the Buy-all carts below, since most people building this already have a printer.
  • Digital calipers, to measure your microscope's barrel and dial and your servo horn
  • Small Phillips screwdriver and a 2.5 mm hex key (the EASTPUK kit includes a key)
  • Flush cutters or pliers for removing supports
  • A computer running Chrome or Edge, a USB cable for the printer and a USB-C cable for the Nano
  • Arduino IDE, to upload the firmware
  • Optional: a multimeter, to check the 5 V supply's polarity

Materials

Buy all parts: Amazon.com (US) (paid link) Buy all parts: Amazon.ca (Canada) (paid link)

Heads-up: Amazon may ask you to sign in before the items show up in your cart. The carts include the MG996R as the Amazon servo option. If you're getting the FS5113R from QKits instead, remove the MG996R from your cart. The 3D printer and the printed parts aren't in the carts.

As an Amazon Associate I earn from qualifying purchases. The Amazon links below are affiliate links, so if you buy through them I may earn a small commission at no extra cost to you.

PartWhat it's forQtyLink
Ninyoon 4K WiFi/USB digital microscope (50–1000X)The 4K camera. Its cylindrical body sits in the printed clamp and its zoom/focus dial gets the ring gear.1View on Amazon (paid link)
AYWHP Nano V3.0 3-pack (ATmega328P, CH340, USB-C)Runs the zoom firmware and drives the servo signal on D9. A 3-pack is handy: I went through two Nanos during this build.1 packView on Amazon (paid link)
EASTPUK M3 button-head screw assortment, 550 pcs (6–25 mm, nuts and washers)Every joint in the drive is M3: clamp, cradle, foot screws, stop bar, jack screw and leveler. This is the kit I used.1View on Amazon (paid link)
MG996R 360° continuous-rotation metal-gear servoAmazon alternative to the Feetech FS5113R (see below). The v20 cradle fits both.1View on Amazon (paid link)
5V 3A power supply with screw-terminal barrel adapterPowers the servo on its own supply, so the Nano and your USB port don't brown out.1View on Amazon (paid link)
OVERTURE PETG filament, 1.75 mm, 1 kgI printed the parts in PETG. It's tougher than PLA for the gear teeth and the pegs.1View on Amazon (paid link)
ELEGOO 120-piece Dupont jumper wire kit (M-M, M-F, F-F)Servo signal from D9, plus the ground jumper from the supply's − to a Nano GND pin.1View on Amazon (paid link)

Servo and power supply from QKits

The servo I actually used is the Feetech FS5113R continuous-rotation servo. Amazon doesn't carry it, so I bought it locally from QKits in Kingston, which also sells a matching 5 V supply. These are regular links, not affiliate links.

Also needed: a rubber band, hair tie or flat elastic up to about 4 mm wide for the ring gear's groove. The servo's own accessory bag supplies the round disc horn and its screws.

Printed parts (current version)

These are the current files: v18 base, v15 clamp and leveler, v19 ring gear, and the v20 servo drive with the v20b cradle. Print in PETG (preferred) with 4–5 walls, 40% gyroid infill and 5 top and 5 bottom layers, in the orientation each file is exported in. The base needs build-plate-only supports under the raised servo block only. The ring halves need supports under their two alignment pegs (tree supports are easiest), and the v20 parts and leveler need none.

Recommended filament: I used and recommend OVERTURE PETG, 1.75 mm, 1 kg. It holds up better than PLA on the gear teeth and pegs. Buy on Amazon.com (paid link) · Buy on Amazon.ca (paid link)

Download all current STLs + OpenSCAD source (.zip)

FilePartPrintNotes and key dimensions
base_v18_reinforced.stlFixed carrier: Nano tray, rear mounting loop and the rails the clamp slides on1v18. Nano pocket 63.2 × 38.8 × 18.2 mm with 2.2 mm walls. Rear loop opening 23.6 × 13 mm, 6 mm thick. About 40–45 g printed. Supports on the build plate only, under the raised block.
microscope_clamp_v15.stlIndependent microscope clamp (carriage)1Bore Ø33.3 mm for a Ø32.7 mm barrel, 4 mm wall, 10 mm tall, 0.8 mm split with an M3 clamp bolt. Two M3 locks in parallel slots give 12 mm of front-to-back travel.
ring_half_v19_bore32.5.stlRing gear half, butt joint (default bore)2v19. 44 teeth, module 1.3, Ø59.8 mm, 25 mm tall. Print the same file twice, turn one 180°, and hold the halves together with a rubber band or hair tie in the 4 mm groove.
ring_half_v19_bore32.2.stlRing gear half, snug bore(alt) 2Use these if the 32.5 mm ring spins on the dial.
ring_half_v19_bore32.8.stlRing gear half, easy bore(alt) 2Use these if the 32.5 mm ring is a struggle to get on.
slide_v20.stlServo drop slide (foot and column)1v20. About 49.5 × 48 × 91 mm. Bolts to the base's servo-foot block with two M3 foot screws.
cradle_v20b_m3nut.stlServo cradle for a standard-size servo (default)1v20b. Fits the FS5113R or an MG996R. 6 mm cable notches in both end walls, open at the bottom. Takes M3 screws with nuts in the side slots.
cradle_v20b_m3pilot.stlServo cradle, pilot holes(alt) 12.5 mm pilots for M3 self-tappers or the servo kit's own screws.
cradle_v20b_m25nut.stlServo cradle, M2.5 with nuts(alt) 1Same cradle for M2.5 hardware.
cradle_v20b_m25pilot.stlServo cradle, M2.5 pilots(alt) 1Same cradle for M2.5 self-tappers.
stop_bar_v20.stlCentre-distance stop bar1Holds an M3 × 20 jack screw that pushes the slide to set the gear mesh, and stops the pinion from being shoved out of mesh.
pinion_v20_25T_horn25.0.stl25-tooth pinion for a 25 mm round disc horn (default)11.76:1 to the 44T ring. 44.95 mm centre distance. 6.2 mm centre hole and 4 holes on a 14 mm circle.
pinion_v20_25T_horn24.0.stl25-tooth pinion for a 24 mm disc horn(alt) 1Measure your servo's round horn and pick the closest size.
pinion_v20_25T_horn20.0.stl25-tooth pinion for a 20 mm aluminium disc horn(alt) 1For an M3-tapped 25T aluminium horn.
pinion_v20_22T_horn20.0.stl22-tooth pinion, 20 mm horn only(optional) 12.0:1 for a bit more torque, but the servo body clears the ring by only 0.8 mm. Stick with the 25T unless you need it.
leveler_brace_leg_v15.stlLeveler (anti-sag brace leg)140 mm leg, 4 mm thick. Bolts to the rib on the base's rear arm and swings from 90° to 270°. An M3 levelling screw in the foot pushes against the printer carriage. Print flat, no supports.

Picking a pinion: measure the outside diameter of the round disc horn that came with your servo and print the closest pinion (25, 24 or 20 mm). Each pinion's recess is the horn diameter + 0.3 mm, so it centres on the horn.

Fit warning: these parts were modelled from my caliper measurements of my microscope (Ø32.7 mm barrel, Ø32.5 mm rubber zoom dial) and my servo. If your microscope's barrel or dial is a different size, measure before you print. The OpenSCAD source in the zip lets you change the sizes and re-export.

Wiring

  • Servo red → 5 V supply +
  • Servo brown → 5 V supply −
  • Servo orange (signal) → Nano pin D9
  • Ground jumper: supply − → any GND pin on the Nano. Without it, the servo has no signal reference and just sits there. That's exactly what happened to me the first time.
  • The Nano stays powered over USB from the computer. Don't connect the supply's + to the Nano, and don't run a big servo from the Nano's 5 V pin. A stalling servo can draw enough current to reset the Nano.

Assembly instructions

  1. Print and clean up the parts. Snip the base's supports off sideways rather than prying against the rails. The thin sections are where an earlier version snapped.
  2. Mount the base. The base's rectangular mounting loop takes the clamp that holds the microscope to the printer's print head. On my printer, the microscope sits on the left side of the head.
  3. Fit the microscope clamp. Slide the clamp over the microscope barrel below the zoom dial and snug its M3 clamp bolt. Set it on the base's rails with its two M3 lock bolts, finger-tight for now.
  4. Put the ring gear on the dial. Press the two ring halves together around the zoom dial, pegs into sockets, and seat a rubber band or hair tie in the middle groove. Start with the 32.5 mm bore. Use 32.2 if it spins, or 32.8 if it's a fight to get on.
  5. Bolt in the stop bar at the outboard ends of the base block's slots. Drop an M3 nut into its trap and thread in the M3 × 20 jack screw. Then set the slide's foot on the block, with the stop bar inside the foot window, and fit the two foot screws loosely.
  6. Mount the servo in the cradle. Lower it in from the top, with the ears on the end shelves, and lay the cable into whichever end notch it comes out of. Fasten the ears with 4 × M3 × 12–16 screws and nuts, or with the kit screws on the pilot-hole cradle.
  7. Fit the pinion. Run the servo to its stop point once, press on the round disc horn and fit the horn screw. Bolt the pinion to the horn, recess side down, with 4 × M3 × 8 for an aluminium horn or M2/M2.5 × 8 self-tappers for a plastic one.
  8. Join the cradle to the slide. Slide 4 M3 nuts into the channels in the cradle's outboard wall and fit 4 × M3 × 18–20, finger-tight. Slide the cradle until the pinion covers the ring's upper toothed band, with its top about 0.5 mm above the ring, then tighten.
  9. Set the mesh. With the foot screws loose, turn the jack screw (hex key through the column hole) until the pinion just meshes. You want a hair of backlash when you rock the ring by hand, and no binding all the way round. Then tighten the foot screws, and turn the dial through its full range by hand before powering up.
  10. Fit the leveler. Bolt the brace leg to the rib on the base's rear arm with 2 × M3 × 12 screws and washers into the rib's nut traps. Press or heat-set the nuts, since the traps are tight. Swing the leg anywhere from 90° to 270° and tighten. Drop an M3 nut into a foot slot, thread an M3 × 16–20 levelling screw through it with a jam nut under the head, and turn it until the tip just touches the printer carriage with the mount level. Then lock the jam nut.
  11. Wire it up as above, then plug the Nano into your computer.
  12. Upload the firmware (below), open the control page, connect the printer and the zoom drive, and test small zoom nudges before long moves.

The control page

The microscope control page is a single HTML file that runs in your browser. It connects to the printer and the Nano with Web Serial and to the microscope as a webcam. It does:

  • X/Y/Z jogging from the keyboard or buttons, a Go-to position and Return to last position
  • Live camera preview up to 4K, snapshots tagged with the X/Y/Z position, a large preview and fullscreen
  • Mosaic scans with calibration, stitching, and an option to lock exposure and white balance during scans
  • Zoom drive controls (Page Up / Page Down or the buttons) for the servo-driven zoom
  • Click-to-centre: click a spot in the live view and the printer moves to centre it, refining its calibration with every click

Open the control page Download microscope-control.html Download page + firmware (.zip)

Requirements: desktop Chrome or Edge (Firefox and Safari don't support Web Serial), loaded over HTTPS or from a local file. It only talks to the printer, Nano and camera plugged into your computer. Nobody can drive your printer through the website. The first time, you pick the serial ports and allow the camera. Calibration and settings are saved in your browser for that site. The printer needs to accept Marlin-style G-code (the Ender 3 V2 does), and the Nano needs the v2 zoom firmware below. On Linux you may need permission to open the serial ports (for example, adding yourself to the dialout group). Keep the bed and nozzle heaters off while scanning.

Arduino firmware

The Nano runs a small non-blocking sketch that turns serial commands into timed servo pulses on D9. In the Arduino IDE, choose Arduino Nano and, for most CH340 clones, the ATmega328P (Old Bootloader) processor (try the other one if the upload fails). Upload, then open the Serial Monitor at 115200 and send ?. It should answer with an OK STATUS v2 ... line. On Ubuntu, if the CH340 Nano keeps disappearing, sudo apt remove brltty removes a braille driver that's known to grab it.

Download zoom_servo.ino (v2)

/*
 * zoom_servo.ino v2 — low-jitter continuous-rotation SG90 zoom drive (Nano, D9)
 *
 * v2 changes: fully non-blocking loop. Serial is parsed byte-by-byte into a
 * fixed buffer (no String, no readStringUntil, no timeouts). Pulse end is a
 * micros() deadline checked every loop pass, independent of partial lines.
 * STOP is honoured immediately, even mid-pulse. A Z command while a pulse is
 * active is rejected (ERR BUSY) instead of queued. SPD/DIR are RAM-only;
 * EEPROM is written only by TRIM and SAVE. The servo is attached with the
 * neutral (trim) value pre-loaded, never a default/random pulse, holds neutral
 * for HOLD ms after a pulse, then detaches.
 *
 * Note: the Servo library emits one pulse per ~20 ms frame, so the real
 * run window is quantised to ~20 ms; very short pulses (<40 ms) may not move
 * the motor at all or may vary mechanically.
 *
 * Wiring: servo signal -> D9, V -> 5V, G -> GND. Serial 115200, CR/LF lines.
 * Commands (case-insensitive, optional trailing "#id" echoed in reply):
 *   Z+ <ms> [spd] [#id]   run zoom-in for ms (1..30000), spd 1..90 (default SPD)
 *   Z- <ms> [spd] [#id]   run zoom-out
 *   STOP | S 0            neutral now, cancel pulse
 *   S <spd>               continuous run -90..90 (until STOP)
 *   SPD <1..90>           default speed (RAM)
 *   DIR <1|-1>            direction (RAM)
 *   TRIM <1300..1700>     neutral us (saved to EEPROM)
 *   HOLD <0..5000>        ms to hold neutral before detach (RAM, default 400)
 *   SAVE                  save SPD/DIR/TRIM to EEPROM
 *   ? | STATUS            status
 * Replies: "OK Z+ ms=.. spd=.. us=.. act_us=.. [#id]" when the pulse ENDS
 * (act_us = measured time between run and neutral writes); "ERR ...".
 */

// ...

int speedToUs(int spd) {
  if (spd > 90) spd = 90; if (spd < -90) spd = -90;
  return trimUs + (spd * 500) / 90;
}
void ensureAttached() {
  if (!attached) {
    servo.writeMicroseconds(trimUs);   // preload neutral BEFORE attach
    servo.attach(SERVO_PIN, 1000, 2000);
    servo.writeMicroseconds(trimUs);
    attached = true;
  }
}
void neutral() {           // safe stop; keep attached and start hold timer
  if (attached) servo.writeMicroseconds(trimUs);
  curSpeed = 0;
  holding = attached; holdStart = millis();
}
// ... (full sketch in the download)

Notes on the firmware:

  • Continuous servos don't have a perfect stop point, so TRIM sets the neutral pulse (1300–1700 µs, around 1500) and saves it to EEPROM. Nudge it until the servo stays still.
  • After each move the sketch holds neutral for HOLD ms and then detaches the servo. It never sends a random pulse at attach, and STOP works even mid-move.
  • The Servo library sends one pulse every ~20 ms, so very short moves (under about 40 ms) may not turn the motor at all.
  • The sketch's header comment dates from the SG90 version and shows the servo's V on the Nano's 5 V. For the FS5113R or MG996R, use the separate-supply wiring above. The code and commands are the same.

Notes and caveats

  • This is a hobby build designed around my microscope and my printer. The parts were checked in CAD for collisions and gear mesh, but the clamp and dial sizes are specific to my scopes, so measure yours.
  • The stronger servo is the key to turning a stiff zoom dial, and on my rig the FS5113R turns it perfectly. Through the 25T pinion, the design works out to roughly 19–26 kg·cm at the dial (about 5× the geared SG90). If yours stalls, check that the supply is 5 V 3 A and the ground jumper is in, and stop right away: holding a stall heats the servo and can reset the Nano.
  • USB 2.0 limits how fast 4K video can stream. Expect a low frame rate at full 4K.
Earlier versions and failed concepts

It took twenty-odd versions to get here: a split ring gear, a long run of friction-wheel carriers, a base that snapped, a dovetail ring that wouldn't go together, and a servo that just wasn't strong enough. If you want the back story or the old files, see Microscope Build: Failures and Iterations, or grab every old version in one archive zip. Those files are kept for reference only. Print the current set above.

Posted In:

ABOUT THE AUTHOR:
Software Developer always striving to be better. Learn from others' mistakes, learn by doing, fail fast, maximize productivity, and really think hard about good defaults. Computer developers have the power to add an entire infinite dimension with a single Int (or maybe BigInt). The least we can do with that power is be creative.
Shop: