Building a photography macro rail for focus stacking (Part 3 - Control with Blynk)

Hi and welcome to the third part in this series where I try not to electrocute myself or set fire to things in order to do some funky photography stuff.

Part 1 is here
Part 2 is here.

This is one of the coolest bits of this project - working out how to control the stepper motor with Blynk. Blynk (available from is an app that allows you to connect up with an absolute ton of IoT platforms and devices, one of which is the Arduino.

It's a bit hard to judge how much detail to put into posts like these so will give an overview and if you have any questions, please feel free to ask in the comments

Installation and configuration


The Blynk app in my project connects to a laptop on the same wifi network as my phone. The laptop is running a Blynk server which in turn connects over USB to the Arduino. The Arduino in-turn connects to the electronics on the breadboard as shown in the previous post and tells the motor to change direction or spin.

It's pretty easy to install Blynk to work on a local network with wifi; you need the app on your mobile device and the associated libraries on the server machine

I'm not going to go into detail about installation etc. as all of that detail is available on the Blynk site. What I will say is that getting the Blynk server to run on my mac was a bit of a pain to start with as it kept choosing the wrong port and device by default. The command I have to run from the scripts folder is

sudo ./ -c /dev/cu.usbmodem14201 -p 9443

This runs a local blynk server on port 9442 using device cu.usbmodem14201 which is the USB port that my Arduino is plugged into. Once you have the running you end up with the below output.

Screenshot 20191015 at 13.51.11.png

So let's move onto creating the Blynk app and telling it how to get the Arduino to do things.

The basic functionality that I want the app to do in the first version is

  • Move the guide rail forwards and backwards
  • Have a manual mode where you set the distance you want to move forward and the number of photos you want to take
  • Have an auto mode where you set the start and end positions of the rail and the number of photos you want to take and the Arduino works out the distance and steps automatically


To the right here you can see my Blynk app in "design mode". It's created using a drag and drop UI on the phone. You add buttons and other widgets and then assign them with "Virtual Pins" that can be communicated with from the Arduino code. For example, V0 is the button I'm using to move the motor forward and in the Arduino code this is handled like this

   move forward
  int pinValue = param.asInt();
  if (pinValue == 1)
    moveForward = true;
    moveForward = false;

So all im doing is setting a variable called moveForward to be true or false depending on if this button is pressed. It is the main Arduino loop that is constantly checking this value to see if it needs to move the motor forwards or not as shown in this code snippet here. the loop() is called continually from within the Arduino. You can also see the moveBackward variable check which calls move(false) to move the motor backwards and a runIt variable that is set by the "GO" button which calls runProcess() and does all the clever work.

void loop()

  if (moveForward)

  if (moveBackward)


  if (runIt)
    runIt = false; // stop it running more than once

The move() function is called for both move backwards or move forwards as well as the runProcess() clever stuff to move things around and looks like this.

void move(bool forwards)
  if (forwards)
    digitalWrite(dirPin, HIGH);
    digitalWrite(dirPin, LOW);

  digitalWrite(stepPin, HIGH);
  digitalWrite(stepPin, LOW);

  if (forwards)

It checks the direction passed into the function and then tells the Arduino to in turn tell the stepper motor driver to set the direction by setting HIGH or LOW on the dirPin. Then it sets the stepPin to HIGH and LOW to move the motor one step. The last bit keeps track of the current step position. I keep a track of step position so that I know where the start and end points are in full auto mode.

So for all of the controls on the page, a variable in the Arduino code is set and the loop does things depending on those variable values. I really don't want to go into every single bit of code. I'd rather just demonstrate what the system does at the moment. If you want to look at the code in its current state, you can check it out on github at

Here is a video demonstration of some of the UI features and the system working in AUTO mode. I've added in an LED to simulate the camera shutter being fired.

The next step is to get hold of the guide rail and get this all set up with the stepper motor that comes with that. It could take a few weeks to get here from the USA.

Thanks for reading. Looking forward to getting this hooked up to an actual rail very soon. I'll be back to posting photos for the next few weeks.


Comments 8

This post was shared in the Curation Collective Discord community for curators, and upvoted and resteemed by the @c-squared community account after manual review.
@c-squared runs a community witness. Please consider using one of your witness votes on us here

15.10.2019 23:46

nice progress, hopefully you don't get the same delivery driver delivering the rail as your camera :joy: @tipu curate

16.10.2019 18:59
16.10.2019 18:59

awesome project :) i did bought a mini cnc from ebay, 2 years ago. that uses nema17 too i think. it has A4988 driver too. minimum resolution it can do is 0.01mm.

17.10.2019 13:25

This post has been voted on by the SteemSTEM curation team and voting trail. It is elligible for support from @curie and @minnowbooster.

If you appreciate the work we are doing, then consider supporting our witness @stem.witness. Additional witness support to the curie witness would be appreciated as well.

For additional information please join us on the SteemSTEM discord and to get to know the rest of the community!

Please consider using the app and/or including @steemstem in the list of beneficiaries of this post. This could yield a stronger support from SteemSTEM.

17.10.2019 14:54

Wow your project is going fast!
The Blynk software looks pretty damn easy to create beautiful things together with Arduino. Never knew it was that easy!

Looking forward to part 4!😎

22.10.2019 12:45

Still researching the right rail and where to get it from. Accuracy can be a problem with the cheaper ones.

22.10.2019 17:11