How to use an Arduino stepper motor

The following guide is about to give you a brief introduction to the stepper motors. These motors can move a really small degree by step, which makes them suitable for projects that require to be precise. First, in this guide, you can learn about the working method of stepper motors. Then, in a step by step guide, you will learn how you can connect to your Arduino and control them from the computer with Ozeki 10. Let's get started right now.

What is a stepper motor?

A stepper motor is a motor controlled by a series of electromagnetic coils. The center shaft has a series of magnets mounted on it, and the coils surrounding the shaft are alternately given current or not, creating magnetic fields which repulse or attract the magnets on the shaft, causing the motor to rotate.

How does a stepper motor work?

Stepper motors can turn an exact amount of degrees (or steps) as desired. This gives you total control over the motor, allowing you to move it to an exact location and hold that position. It does so by powering the coils inside the motor for very short periods of time. The disadvantage is that you have to power the motor all the time to keep it in the position that you desire.

All you need to know for now is that, to move a stepper motor, you tell it to move a certain number of steps in one direction or the other, and tell it the speed at which to step in that direction. There are numerous varieties of stepper motors. The methods described here can be used to infer how to use other motors and drivers which are not mentioned in this tutorial. However, it is always recommended that you consult the datasheets and guides of the motors and drivers specific to the models you have.

Arduino stepper motor wiring diagram

wiring diagram for arduino stepper motor
Figure 1 - Wiring diagram of Arduino Stepper Motor

How to use an Arduino stepper motor in Ozeki

Stepper Motor Multi Controller connection is capable to transfer commands to your stepper motors from any selected Ozeki connection. Stepper motors are the most precise motors available. You can command them to move exactly 1.8/16 = 0.1125 degrees/step in each direction. Movement commands consist of the required steps and speed to turn motors. You can also setup motor movement endstops. To use the Stepper Motor in Ozeki, you first need to download Ozeki Robot Developer. Ozeki Robot Developer will install the Arduino libraries needed to use this sensor efficiently.

Download Ozeki Robot Developer

Download Ozeki Robot Developer

After Ozeki Robot developer is installed, you need to upload the Stepper Motor control code to your Arduino. You can find the code and download instructions on the following pages. The upload process includes two steps: first you need to format the EEPROM of the arduino, then you need to upload the control code. The procedure is very simple, it only takes a few seconds.

Upload the Stepper Motor code to Arduino Mega 2560
Upload the Stepper Motor code to Laser Cutter
Upload the Stepper Motor code to Ozeki Matrix

The arduino motors and Ozeki will communicate over the USB port using the Ozeki Stepper Motor protocol. This protocol makes it possible for you to use the motor directly on your PC. You will be able to control this motor through the web based user interface or you will be able to communicate with it using Ozeki Chat. You can read more about chat control on the following page.

How to communicate with the Stepper Motor using chat

It is important to understand chat control, because when you build a robot, the way you wish to control this motor is by sending and receiving messages. If you open the Ozeki Robot Developer app, you will see, who you can write a C#.Net program to work with this motor.

Connection steps

  1. Connect the Stepper motor to the Arduino by following the wiring diagram
  2. Attach the Arduino board into your computer with an USB data cable
  3. Check the COM ports in Windows device list
  4. Open the Arduino application on your computer
  5. Upload example code to the microcontroller
  6. Open https://localhost:9515 in your browser
  7. Choose the connection of Stepper motor
  8. Set speed and degree to test the Stepper motor

System overview

The system we suggest consists of a stepper motor, that is wired to the analog port of your Arduino. The Arduino will be responsible for reading data from this device in real-time. The brain of the system will be running on a PC (Figure 2). On the PC, Ozeki 10 will be able to manage the communication. You can easily run Ozeki 10 using a webbrowser

system configuration of stepper motor connecting to pc using arduino
Figure 2 - System configuration of stepper motor connecting to PC using Arduino

Prerequisites

  • Stepper motor(s)
  • DRV8825 or A4988 stepper motor driver(s)
  • Endstop(s)
  • Ozeki 10 installed on your computer
  • Programmable board (Arduino Mega plus RAMPS v1.4, Ozeki Stepper Motor Controller Module
    or Laser Cutter Controller Board)
  • USB cable is needed between the board and your computer

Step 1 - Wire the stepper motor to your Arduino

You can see how to wire the stepper motors to any of the following boards:

After wiring, please plug the board to your computer!

Step 2 - Upload code to the microcontroller

(Here is the code to upload)

The following step is to upload a code to the microcontroller that will operate on the stepper motor. To do that, you need to open the Arduino application on your computer. Here, first you have to check the port, that the stepper motor is properly connected to your computer. Then, you just need to go the link above, copy the code and paste it in the Arduino application. Lastly, just click on Upload in Arduino and the code will be uploaded to the microcontroller.

Step 3 - Start Ozeki 10 to try the stepper motor

After that you connected your Arduino to your Raspberry Pi, now you can try out the stepper motor. For that, you need to open the GUI (Graphical User Interface) of Ozeki 10. That can be done by typing localhost:9513 to your webbrowser and hit Enter. Here, Ozeki 10 automatically detects the connected devices, so once you connected the stepper motor, you will be able to see it in the list of connections. All you have to do here, is to open the connection, and try the stepper motor.

Step 4 - Configure the stepper motor in Ozeki 10

In order to configure your stepper motor (attached to your Arduino) in Ozeki 10, that is installed on your computer, you need to open the graphical user interface (GUI) of Ozeki 10. You can open the GUI by entering the URL of the computer into your webbrowser. For example, if our PC has an IP address of 192.168.1.5, we would enter http://192.168.1.5:9513 into our webbrowser.

Step 5 - Understand the stepper motor protocol

The Stepper Motor Multi Controller can communicate with Ozeki through the following protocol.

References:
https://www.tutorialspoint.com
http://www.tigoe.com

More information