Arduino – Week 2 – Stepper Motors

What is a stepper motor?

A stepper motor uses opposing electromagnets to create rotation. The different number of steps are determined by the number of poles on each the stator and the rotor.

https://www.elprocus.com/stepper-motor-types-advantages-applications/

There are several different types of stepper motor, depending on the use case and the size that is required. The main types are :

Permanent magnet stepper > These use permanent magnets in the rotor and electromagnets in the rotor, using attraction and repulsion to create rotation

Uses

Stepper motors can be used for all sorts of CNC controlled devices such as 3D printer or CNC routers.

Mechanical arms such as those used for assembly of cars etc will use stepper motors to obtain exact position repeatably

Any automated machinery that requires exact positions to be returned to, will use stepper motor as they are very precise int he increments of rotation that they can do.

How to drive a stepper motor

Wave forms that drive a stepper motor

Turning coils on and off > Transistors are electric dimmer switches which can be used as on off switches for stepper motors

 

Stepper Motors with Arduino – Getting Started with Stepper Motors

Stepper Motor Code

Setup code for the stepper motor initialises which pins are the outputs from the arduino

void setup() {

// initialize digital pin LED_BUILTIN as an output.

pinMode(13, OUTPUT);

pinMode(12, OUTPUT);

pinMode(11, OUTPUT);

pinMode(10, OUTPUT);

}

void loop() {
//STEP 1
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, HIGH);
delay(2);                                      // delay

//STEP 2
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
delay(2);                                      // delay

//STEP 3
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
delay(2);                                      // delay

//STEP 4
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
delay(2);                                     // delay

The loop will run through all of the bracketed coded indefinitely

delay(2) is the amount of ms left between that line of code and the next, which determines how fast or slow the motor will turn. The smaller the number, the faster it spins.

Print Friendly, PDF & Email

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*