NEMA 17 Stepper Motor
Four wires of the NEMA 17 are colored differently. Normally wires are red, blue, green and black. Red and blue represents first coil and green and black represents second coil. In some motors blue is replaced with yellow and black with grey. If you are going to use NEMA 17 in a diy project first please make sure the correct coil pair with colors.
A4988 stepper motor driver
I explained each and every pin of of A4988 bipolar stepper motor driver in an another tutorial. Pin configuration and steeper motor rotation mode is also explained in the tutorial. I suggest you to please take that tutorial first in order to get familiarize with A4988 driver and its operations requirements. If you go through that small tutorial and its part on A4988 motor driver you can easily understand the code and circuit diagram below.
Project Circuit diagram
const char* ssid = “Your SSID”;
const char* password = “Your Wifi Password”;
In the setup function control pins are declared as output. Arduino ide serial monitor is initialized at 115200 baud rate. Server is started and web page IP is published. I will talk more about it after code. In the loop function the main program logic is running. In the loop function server is waiting for a client request. As soon as the server receives the client request it manipulates it and responds to request.
Just make the circuit and download the above code in it. Before uploading the code to nodemcu first make sure correct board is selected. After downloading the code in nodemcu open the arduino serial monitor from arduino ide. As soon as you open the serial monitor you will see nodemcu requesting your router for an IP assignment. After IP assignment nodemcu will start its server. After server startup the address of the server will be printed on serial monitor window. This address is actually the address of web page which contains the stepper motor controls. You have to enter this address in your browser to access the web page.
Web page has two buttons one is forward and the other is backward. If you press the forward button motor will move 50 steps a head. If you press backward motor will change its direction and start taking 50 steps backward. Recall we are using NEMA 17 stepper motor and it take 200 steps to complete one rotation. So if i move motor 50 steps on each button press. It means i am moving stepper motor shaft by 90 degree on each button press. A for loop is run 50 times to allow stepper motor to take 50 steps. So now in our case stepper motor is taking 4 steps to complete 360 degree rotation or 1 step to move 90 degree.
This tutorial is a simple tutorial on how to control stepper motor over WiFi using nodemcu WiFi module. In future you can test other modes of stepper motor rotation steps 1/4, 1/8 and 1/16 micro steps. You can also manually enter steps in web page and move the motor according to the entered number. A bar can be inserted in web page and motor position can be controlled through it using AJAX web development language.