Motorized macro rail on the cheap

dsvilko

Senior Member
Note to the Picaxe forum members: I link here from a few other (non-electronics) forums so I explain some things you already know. Just skip that bits.

I love macro photography and as anyone who has ever tried it will know, extremely thin depth of field (here we are often talking about 0.1mm and below) can be a real problem as the object we are photographing is usually significantly larger. The higher the magnification you use the less of the photo ends up in sharp focus. This problem is typically solved by taking multiple photos with a slightly different focus point and later combining them to produce the final image where everything of importance is in focus. One such software is the excellent Zerene stacker that will do all the work for you. You still need to take a bunch of photos of the same object that differ only in the focus point - and by 'bunch' I mean sometimes more than 50!

For that reason I went to design an automatic macro rail that can very precisely move a small object back and forward a few centimeters. The macro rail had to be able to:
- move in user selectable steps from 0.01mm to about 1mm
- continuously slide (fast) for the initial focusing
- memorise the start and the end positions for the focus stack
- compensate for the 'slack' in sprockets when changing the direction
- control my Canon dSLR and automatically take the photos once everything has been set
- remember some settings between the runs (step size)
- I had to build it from easily available 'junk' as I wasn't prepared to pay more than $20
- simple and quick to build - no heavy machinery required
- controlled by a smallest and cheapest micro-controller I head - the Picaxe 08m
- remote controlled to minimize the possibility of accidentally moving the camera or the subject

I actually managed to do this utilising only the parts I already had in the house (so it didn't cost me a penny while similar rails can be bought for close to $500!). All I needed was an old, broken DVD-ROM drive (for a very nice rail it contains), a unipolar stepper motor (from an ancient 5.25" floppy drive - remember those?), the Picaxe 08m, and a few standard electronic components.

Here is the result:

First, watch the video!


(a bigger version).
IMPORTANT NOTE: I have made a mistake when drawing the diagram. The wire that connects the input pin 2 of the ULN2003A to the output pin 6 (veroboard strip 12 to 16) should be connected to ULN pin 1 (strip 11), not 2!

Ok, now forget my ugly scribble and download the excellent multi-layered Photoshop drawing that SteveD has made:
http://www.stevedargie.pwp.blueyonder.co.uk/Downloads/circuit.psd

Putting together the mechanical part of the project couldn't have been simpler. Apart from dissembling the CD-ROM all I had to do was superglue a plastic bottle cap to the first sprocket (that would normally be rotated by a small motor which I have actually left in place and simply not use) and add a unipolar stepper motor. These two are connected by a rubber band, and that's it! :) If you use a bipolar stepper you'll have to use a larger Picaxe and also rewrite the code so I don't recommend it.

The electronics are also quite simple and should provide little challenge to someone who knows how to solder. Buy a veroboard (stripboard), cut to size and just follow the circuit diagram.
Where there is an 'X' in the diagram cut the copper strip.
The IR receiver (that thing to the right/below the 08m) used is the TSOP1138. Wiring the stepper is a bit tricky as you have to guess the correct order of the wires. This is how you can do it:
1. Use a multimeter to measure the resistance between different pairs of wires. Two numbers should keep appearing - one resistance will be twice smaller than the other. If you have a 5 wire motor then there will be one wire that will give this 'half-resistance' to any other wire. Mark this wire. If you have a 6 wire stepper you will find two such wires with the difference that not all the wire pairs will be internally connected (there will be two sets of wires that are connected). Mark both these wires.
2. Glue a long paper 'pointer' to the stepper (so you can easily see in which direction it turns). Connect the previously marked wire(s) to the battery + side (4AA battery pack should work fine). Experiment connecting the 4 wires that are left to the battery - side, one at the time. The goal is to find the right sequence (1,2,3,4,1,2,3,4....) that will make the motor turn. Mark the wires 1,2,3 and 4.
3. When connecting the stepper to the board connect in order (from left to right): 1,3,2,4
Hopefully the sequence will be correct.

After you have put all of it together, it's time to program the micro-controller. How to do this is better explained in the Picaxe manual (free download from their site). Basically all you need is a serial (or USB to serial) cable and a diagram from the manual describing which wire to connect where (you need to connect three wires to the bottom left of the board, marked -, RX and TX). You also need to connect a 5V power supply (4 AA NiMH batteries work great). If you want you can also connect a small switch on the '+' wire from the battery.

Once everything is set, here is the code you need to send to your board:
Code:
' Macro focus rail driver
' Unipolar stepper (12V 1.8deg) connected to ULN2003A:
'    green, white, red, brown -> Out1-Out4
'    08m 2 -> ULN In2
'    08m 1 -> ULN In3
' Out4 -> optocoupler for shutter triggering (tip+, sleave-)
' IR detector codes:
'    CH+      back focus
'    CH-      front focus
'    NN       steps in one slide (in 0.01mm)
'    AV/TV    the next slide will be continuous (any key to interrupt)
'    Vol-     mark focus (front) and start moving focus back; mark focus end by any key
'		slide to the front of the stack
'    Power    start shooting

symbol slack = 5          ' how many micro steps to add when changing direction 
symbol steppause = 1   ' larger number will make it go slower 
'                                  - useful if you have a stepper with very few steps per revolution

symbol stepc     = b0
symbol s 	= b1
symbol i 	= b2
symbol direction = b3
symbol nsteps    = b4
symbol nframes   = b5
symbol nslide    = b6
symbol j	 = b7
symbol irflag    = b8
symbol olddir    = b9
symbol contflag  = b10

high 1
high 2
low 4

'           (nsteps)
eeprom 0, (20)

read 0, nsteps

contflag=0

main:
	infrain2
	if infra<10 then
		infra=infra+1
		infra=infra//10
		nsteps=infra*10
		pause 500
		infrain2
		infra=infra+1
		infra=infra//10
		nsteps=nsteps+infra
		write 0, nsteps
	elseif infra=37 then
		contflag=1
		pause 500
		infrain2
		pause 500
	endif
	select infra
	case 17 ' front focus
		direction=2
		gosub slide
	case 16 ' back focus
		direction=0
		gosub slide
	case 19 ' Vol-  - mark focus start
		nslide=0
		irflag=0
		pause 200
		do
			pause 200
			direction=0
			gosub slide
			nslide=nslide+1
			'pause 200
		loop while irflag=0
		pause 2000
		for j=1 to nslide
			direction=2
			gosub slide
		next j
		gosub slide
		direction=0
		gosub slide
	case 21 ' Power - start shooting run
		gosub shoot
		for j=1 to nslide
			direction=0
			gosub slide
			gosub shoot
		next j
	endselect
	'debug
	pause 500
	goto main

shoot:
	pause 5000    
	high 4	' shoot
	pause 400
	low 4
	pause 3000    ' wait before the next slide (exposure time)
	return

	
slide:
	if direction<>olddir then	' remove sprocket slack
		for i=1 to slack
			gosub onestep
		next i 
	endif
	irflag=0
lup:
	for i=1 to nsteps
		gosub onestep
		pause steppause
	next i
	if irflag=0 AND contflag=1 then goto lup
	contflag=0
	olddir=direction
	return

onestep:
'	s=direction*2
	stepc=stepc+direction-1
	let stepc=stepc // 4
	lookup stepc, (%00000110, %00000100, %00000000, %00000010), s
	let pins=s
	if pin3=0 then
		irflag=1
	endif
	'pause 1
	return
The rail is completely controlled through an IR remote (any universal remote that can be programmed to use Sony TV codes). You simply type in a two digit number to change the size of one slide (as it happens, almost exactly in 0.01mm units in my case). CH+/- will make one forward/backward slide. If you press the AV/TV key before the CH then the slide is continuous in that direction until any key is pressed. Once you have moved your object to a starting position of a focus stack you press the Vol-. That starts the gradual slide which you are supposed to interrupt (any key press) when the end point of the focus stack is reached. The rail will then reset to the starting position remembering the number of steps needed. The Power button starts the take-the-shot, move, take-the-shot... loop.

Once all the photos have been taken you use a Zerene stacker (or similar software) to make the focus stack. These programs are usually designed to be used even with hand-held photos so giving them such a perfect series usually results in a perfect stack even on 'full automatic'.

There you have it :) A useful project for macro photographers with an extremely easy to put together mechanics (old CD/DVD-ROMS or writers are easily obtainable) and a few cheap electronic parts. Once you have all the parts the whole thing can be put together over the weekend.

Here is just one example of a small 4mm speck of soil from a potted plant. This is how one frame looks like:


Notice the extremely thin 'slice' that is in focus (about 0.12mm wide)! And here is a result from a stack of 35 photos taken 0.09mm apart:

I believe the difference is obvious :)

As an added bonus the exactly same setup can be used to automatically build a 360deg product rotation animations! :)
 
Last edited:

techElder

Well-known member
That's really slick!

I'm assuming you clip the 'subject' there in the center. How do you handle the background for the macro shot?

It is hard to tell from your photo what exactly is moving.

How about some of the resulting photos?
 

dsvilko

Senior Member
That's really slick!

I'm assuming you clip the 'subject' there in the center. How do you handle the background for the macro shot?
With the depth of field (how much is 'sharp' on the photo) measured in 1/10mm, all I can say is 'what background?' :) Everything more distant than 1cm behind the subject is completely destroyed by the background blur. You can only decide which colour background you want and put something (anything) of that colour there.

As for mounting the subject, you are right. For now there is a simple clip that can either hold the subject or as L profile to rest the subject on.
 
Last edited:

julianE

Senior Member
This is an amazing project. I've been wanting to do something like it for ages. Bravo.

Are you using the CD motor or did you install a different motor?

I will be taking apart a bad cd drive as soon as I get home. I burn a lot of DVD backups and regularly have to replace the drives. I think the mechanical parts are fine, since they can read the media, the issue is in the writing...glad I did not toss them out.
 

dsvilko

Senior Member
This is an amazing project. I've been wanting to do something like it for ages. Bravo.

Are you using the CD motor or did you install a different motor?

I will be taking apart a bad cd drive as soon as I get home. I burn a lot of DVD backups and regularly have to replace the drives. I think the mechanical parts are fine, since they can read the media, the issue is in the writing...glad I did not toss them out.
The mechanics are almost certainly fine. I have decided not to use the original solar motor because it's much harder to precisely control than the unipolar stepper I am using. I didn't even bother removing the original motor. All I did was glue a plastic bottle cap onto the large sprocket the motor is connected to and screw the stepper to the board using one of the existing holes (it's held by just one screw but it's completely solid). Add a rubber band and you are done :) Couldn't be simpler. It your DVD is anything like mine you can finish the mechanical part in 10 minutes.

Old CD/DVD drives are a simply amazing source of mechanical parts (motors, rails, sprocket assemblies...). The same drive that 'donated' it's rail assembly previously gave me enough parts to build a 1-D automatic panorama head:
http://www.youtube.com/watch?v=UFjerJWB5Hs (from the early stage of development)
 

eclectic

Moderator
Excellent and congratulations.

A non-Picaxe question:
What software did you use for
the combination shot in post #3?


e
 

dsvilko

Senior Member
Excellent and congratulations.

A non-Picaxe question:
What software did you use for
the combination shot in post #3?
Thanks!
I have used a evaluation copy of the Zerene stacker. As this is my first stack with this software I am sure there is a lot of room for improvement.
 

eclectic

Moderator
Thanks!
I have used a evaluation copy of the Zerene stacker. As this is my first stack with this software I am sure there is a lot of room for improvement.
But it's still an excellent first attempt. :)

Thanks for the info,
and congratulations again.

e
 

dsvilko

Senior Member
But it's still an excellent first attempt. :)

Thanks for the info,
and congratulations again.

e
Well, it the software could dream, the Zerene stacker would dream of stacking such a perfect series of photos, already precisely aligned and equally spaced in focus points :) It's no wonder that even without fiddling with advanced settings I got a decent result.
My next task is finding a subject with enough detail to look interesting on that scale. Typically nothing man-made comes close and in a dead of winter the 'natural stuff' is not readily available. :(
 

julianE

Senior Member
I just picked up a broken DVD unit and took it apart. I see it has small 2 terminal motors and I guess they are not accurate enough. I found this at sparkfun,

http://www.sparkfun.com/products/9238

Looks like it might be more then needed.

Any suggestions for other suppliers in the US of appropriate motor for this project?

I have some tiny stepper motors I got from Electronic Goldmine that can be driven directly from the picaxe. I would think they are too weak and most likely not fine enough.

Manuka speaks of them in this thread.

http://www.picaxeforum.co.uk/showthread.php?t=12975

Thanks.
 

dsvilko

Senior Member
I just picked up a broken DVD unit and took it apart. I see it has small 2 terminal motors and I guess they are not accurate enough. I found this at sparkfun,

http://www.sparkfun.com/products/9238
Looks like it might be more then needed.

It looks like mine (12V but works 'fine' at 5V and about 150mA) just check that it's not bipolar. I don't know if a bipolar stepper can be driven using only two uC pins (4 is much more common). You may have to use a larger chip. I only had 08m (and 20x2 which I am still reluctant to put in any permanent project).

I have some tiny stepper motors I got from Electronic Goldmine that can be driven directly from the picaxe. I would think they are too weak and most likely not fine enough.
I would not be so sure. The force needed to rotate the largest sprocket is extremely small. By mounting an even larger disk on it and using an even smaller cylinder on the stepper you can get a higher resolution and use a lesser torque. The 0.01mm resolution is not really needed for magnifications below 5:1. You could even be fine with what you've got.
 

julianE

Senior Member
Dsvilko,

Thanks for all the info. You are so right about all the parts available in the cd rom drive. The first one I took apart is a very old unit, industrial strength. It had a solar motor and an optical interrupt wheel for control. I wonder if there is a way that can be used. The second one I opened surprised me more, it already had a stepper motor for laser movement. It's the bipolar type so I found an L293D to control it with. I can hear the motor being energized but it's still not moving, must not have the firing order right. I had it moving by manually energizing the coils. First time I used an L293. I think I'll just attach a couple regular motors and see if I can control them just to make sure I have everything connected right.

Thanks again for sharing.
 

dsvilko

Senior Member
Dsvilko,

Thanks for all the info. You are so right about all the parts available in the cd rom drive. The first one I took apart is a very old unit, industrial strength. It had a solar motor and an optical interrupt wheel for control. I wonder if there is a way that can be used. The second one I opened surprised me more, it already had a stepper motor for laser movement. It's the bipolar type so I found an L293D to control it with. I can hear the motor being energized but it's still not moving, must not have the firing order right. I had it moving by manually energizing the coils. First time I used an L293. I think I'll just attach a couple regular motors and see if I can control them just to make sure I have everything connected right.

Thanks again for sharing.
My CD-ROM also head a solar motor with optical feedback for motor positioning. It could probably be made to work with a bit more powerful Picaxe (no way you can do in on 08m). Unipolar stepper control (with just two uC pins!) is a lot simpler and possibly more precise.
CD-ROM with a stepper? Cool!
 

julianE

Senior Member
After attaching individual regular brushed motors and troubleshooting I got the L293 to work. The little CD stepper works a charm. I am using a 20X2 on the breadboard, an overkill but I have a few of them. I still have plenty more to do, as of now it moves the motor back and forth.

I'm thinking of uses for the motor/tray assembly, I'm probably going to remove it for this project.
 

dsvilko

Senior Member
Magnificent.
Genuine applause on your
"short" making skills as well.
Thank you! :)
This was actually both my first video recorded with something other than a mobile phone (borrowed the sister's 500D for this task) and my first attempt at video editing. As I didn't have any advanced video editing software installed I did all the editing from the Linux command line :) Endless fun:

Code:
mencoder -nosound -ovc lavc -lavcopts \ 
vcodec=mpeg4:mbd=1:vbitrate=1800 MVI_9233.MOV -endpos 5 \  
MVI_9225.MOV -endpos 23 MVI_9229.MOV -ss 11 -endpos 3 \ 
MVI_9225.MOV -ss 24 -endpos 6 MVI_9229.MOV -ss 2 -endpos 5 \ 
MVI_9225.MOV -ss 40 -endpos 10 MVI_9227.MOV -ss 1 -endpos 5 \ 
~/stack-test/resultfile.avi  MVI_9231.MOV -o out.avi
 

techElder

Well-known member
You are one tough act to follow!

I really enjoyed your talents and tip my photographic hat to you to!
 

julianE

Senior Member
You are kidding! When compared to most projects here, this one is _extremely_ simple. I don't understand half of the post on this forum! :) This is stuff for us, beginners :)
It's such an elegant solution...i guess elegance is not just for tailors.

what is that lens you have on the camera, looks like an old Jena or a russian clone?

I hope to finish my rail before the month ends, work has been taking up way too much of my time.

Excellent project.
 

dsvilko

Senior Member
what is that lens you have on the camera, looks like an old Jena or a russian clone?
Yep, it's a Zeiss Jena 50mm 'zebra' f/2.8 + another even older Zeiss 50mm 2.8 (from a non-SLR film camera) totally disassembled to a bare OTA and used as a high-quality dioptre. Think it's something like 2:1, with tubes up to 3.5:1. Nice setup and was virtually free. :) Luckily for me, macro photography doesn't have to be an expensive hobby :)
 

dsvilko

Senior Member
In case anyone is in the process of building this, a very important note:
I have made a mistake when drawing the diagram. The wire that connects the input pin 2 of the ULN2003A to the output pin 6 (veroboard strip 12 to 16) should be connected to ULN pin 1 (strip 11), not 2!
 

RogerTango

Senior Member
Ummm... MENCODER. :) I also use FFMPEG... depending on the source and the desired processing.

I liked your vid, very nice job on the vid, and the project!
 

jimiam

New Member
I'm new at this stuff but would love to try and build this circuit. There are, however a couple of things I don't follow on the schematic.
Where do the pins at 8/6, 8/7, 3/6, 1/12, 1/13 and 1/20 connect? I see the labels 1,2,4,2,1,4 but don't understand them.
Also I presume the symbol at 6/9-6/10 is
a capacitor. Does the motor determine the size of it? I'm lost here too, sorry. Thanks for your help and thanks alot for sharing the circuit.
 
Last edited:

dsvilko

Senior Member
I'm new at this stuff but would love to try and build this circuit. There are, however a couple of things I don't follow on the schematic.
Where do the pins at 8/6, 8/7, 3/6, 1/12, 1/13 and 1/20 connect? I see the labels 1,2,4,2,1,4 but don't understand them.
Also I presume the symbol at 6/9-6/10 is
a capacitor. Does the motor determine the size of it? I'm lost here too, sorry. Thanks for your help and thanks alot for sharing the circuit.
You are right about the capacitor just be careful that you connect it the right way around (as it's bipolar). As for the connections, you connect the same numbers together - 1 goes to 1 and so on.
Here you have a complete component list:
http://www.diyphotography.net/create-an-automated-macro-rails-for-image-stacking
 

jimiam

New Member
You are right about the capacitor just be careful that you connect it the right way around (as it's bipolar). As for the connections, you connect the same numbers together - 1 goes to 1 and so on.
Here you have a complete component list:
http://www.diyphotography.net/create-an-automated-macro-rails-for-image-stacking
Thanks so much for the info and quick reply. Of course, "connect the pins", DUH, that makes all the sense in the world now. :D Nothing like a little input/output to clear things up. A good thing you mentioned the cap too, I thought a bipolar cap could be connected either way. The link you gave is great as well! Again, thanks so much for overlooking my ignorance. Have a great week!
 

dsvilko

Senior Member
Thanks so much for the info and quick reply. Of course, "connect the pins", DUH, that makes all the sense in the world now. :D Nothing like a little input/output to clear things up. A good thing you mentioned the cap too, I thought a bipolar cap could be connected either way. The link you gave is great as well! Again, thanks so much for overlooking my ignorance. Have a great week!
I am also a beginner in all this uC stuff and people here have helped me immensely!
I should have said polarized capacitor as I believe that's the correct term but yes, if you get a electrolitic capacitor be careful which way you plug it in (one lead should be marked with + or -).
You did notice the notice :) below the diagram concerning the mistake I made? Just checking...
 

hippy

Technical Support
Staff member
Radial electrolytic capacitors should be marked with a stripe near one leg showing it is "-" ...

http://www.semielectronics.com/store/images/Rubycon_1000uf_25v.jpg

Axial electrolytic should have the arrow of that stripe pointing towards the "-" with the 'pinched-in' end as "+" ...

http://images.sabob.com/products/images/1/100uF_450V_Axial_Electrolytic_Capacitors_Pack_of.jpeg

I rarely go by length of legs as indication as you don't always know where the component came from. The legs may have been trimmed to the same length or the component salvaged from other equipment. Most polarised components have some physical attribute other than leg length to identify which way round they should go.
 

jimiam

New Member
I am also a beginner in all this uC stuff and people here have helped me immensely!
I should have said polarized capacitor as I believe that's the correct term but yes, if you get a electrolitic capacitor be careful which way you plug it in (one lead should be marked with + or -).
You did notice the notice :) below the diagram concerning the mistake I made? Just checking...
Yes, I did see your edit. I have most of the components now but will need to get the cap and the veroboard. The ic's are in the mail. Can hardly wait to get started.
 

jimiam

New Member
Radial electrolytic capacitors should be marked with a stripe near one leg showing it is "-" ...

http://www.semielectronics.com/store/images/Rubycon_1000uf_25v.jpg

Axial electrolytic should have the arrow of that stripe pointing towards the "-" with the 'pinched-in' end as "+" ...

http://images.sabob.com/products/images/1/100uF_450V_Axial_Electrolytic_Capacitors_Pack_of.jpeg

I rarely go by length of legs as indication as you don't always know where the component came from. The legs may have been trimmed to the same length or the component salvaged from other equipment. Most polarised components have some physical attribute other than leg length to identify which way round they should go.
Thanks for the input and links hippy. I can understand the logic about being careful using leg length. It's always a good idea to confirm things.
 

ebswift

New Member
Given this is pretty-much my first electronics project and my first picaxe project I built a VSM simulation in order to understand this better. It'll probably help for other people constructing the circuit too; it only omits a couple of things from the real-world circuit, but that's mainly due to the lack of those bits in VSM. Where items are omitted, other components are substituted for the purpose of clarity (e.g. a green LED where the opto-isolator was).

The design plus simulation project can be downloaded from my site here (proper attributions are included):

http://www.ebswift.com/Articles/Electronics/Picaxe/MacroRail/

The simulation itself goes through a sequence of pressing buttons on the infrared remote and closes with simulating the automated shutter release sequence.
 

dsvilko

Senior Member
Hi Can someone please share the schematic cos i can't understand this one
Thanks
What don't you understand? It's a veroboard (stripboard, protoboard) diagram with vertical strips. Each column represents one copper strip that is isolated from other columns. The 'X' marks the spots where you have to cut the vertical copper strip.
Do you have a particular part of the diagram that you would like to see explained better?
 

Marcio21

New Member
Is it possible for you to share some photos of the veroboard from the top and bottom please, so I can understand it better?

Thank you very much in advance for your help.
 

dsvilko

Senior Member
Is it possible for you to share some photos of the veroboard from the top and bottom please, so I can understand it better?

Thank you very much in advance for your help.
I assure you there is no chance that you'll get a clearer 'picture' from such photos than from a tidy diagram (only a tight bunch of overlapping wires). It really is quite simple. Each dot is a solder point, either for a wire or a chip pin. Short wire connections are marked in blue ink and longer wires in red ink. Wires of the same number (1,2,4) should be connected together. A few people have already successfully replicated my circuit so the diagram should be correct (apart from a small error I mention below the diagram).
Cut a veroboard to size (or use a protoboard), mark the 1-10 rows and 1-22 columns and simply follow the diagram.
 

bogdandediu

New Member
Hi.Is there any chance of using another microchip other than picaxe ones?And if there is is it posible to use the same code as you did?
Can you point me to some other chips?The thing is i can't find picaxe's over here :(
Thanks in advance :)
 

hippy

Technical Support
Staff member
Welcome to the PICAXE forum bogdandediu.

And it is a PICAXE forum, so while this and other projects could be done with a different micro we focus on the PICAXE here. You should be able to import PICAXE into Romania. Check out www.techsupplies.co.uk and other dealers.
 

Marcio21

New Member
Hello everyone,

Do you have the HEX file, as I don't have the picaxe cable? So I can upload the source code with the pickit 2.

Thank you in advance for your help.
 
Last edited:
Top