Chapter 10 - Exploring Stepper Motors (28-BYJ-48) with an Arduino

Modest Maker
15 Dec 201727:26

Summary

TLDREste script ofrece una introducción a cómo controlar el motor paso a paso 28BYJ-48 con Arduino, una herramienta popular para proyectos de electrónica. Se discute la estructura del motor, su alto torque a baja velocidad y su uso en aplicaciones que requieren control preciso de posición y velocidad. Se explica cómo se organizan las bobinas en fases y cómo se activan secuencialmente para mover el rotor. Se presenta un diagrama esquemático del controlador ULN2003 y cómo se conecta a Arduino. Además, se incluye un ejemplo de código para controlar el motor, así como una discusión sobre la precisión y especificaciones técnicas del motor, incluyendo su relación de reducción de engranajes y el ángulo de paso. Finalmente, se menciona la biblioteca de Arduino para steppers y se comparan las secuencias de 4 y 8 pasos, así como se habla de las placas de motor (shields) como una alternativa para controlar motores.

Takeaways

  • 😀 El video es una introducción al control de motores paso a paso 28BYJ-48 con Arduino.
  • 🔧 Se utiliza un motor paso a paso popular y ampliamente disponible para demostraciones.
  • 📚 Se recomienda revisar capítulos 4, 5, 8 y 9 para comprender mejor este resumen.
  • 🤖 Los motores paso a paso son útiles para aplicaciones que requieren posicionamiento preciso y control de velocidad.
  • 🌀 Estos motores ofrecen alto torque a baja velocidad, pero tienen menos torque a alta velocidad y consumen corriente constante.
  • 🪢 El motor 28BYJ-48 es unipolar, con cuatro bobinas asociadas a cables de colores que se controlan mediante un driver ULN2003.
  • 🔌 El controlador ULN2003 utiliza transistores y diodos para conectar las bobinas al motor y se controla con señales de Arduino.
  • 🔋 Se debe verificar la especificación de voltaje y corriente del motor para asegurarse de que Arduino pueda manejar la carga.
  • 📝 Se muestra cómo conectar los pines de Arduino al controlador y un potenciómetro al pin analógico para control de velocidad.
  • 🔄 Se discuten las secuencias de pulsos necesarias para mover el motor en sentido horario e antihorario.
  • 🎛 El ángulo de paso del motor y la relación de reducción de engranajes son clave para la precisión en el posicionamiento del motor.
  • 🔄 Se menciona la posibilidad de desalineación o 'slippage' debido a la complejidad de los engranajes internos del motor.
  • 📚 Se presenta la biblioteca de Arduino para motores paso a paso, que simplifica el proceso de control del motor.
  • 🛠 Se mencionan alternativas como las shields de motor que facilitan la conexión y control de motores con Arduino.

Q & A

  • ¿Qué es un motor paso a paso y cómo funciona?

    -Un motor paso a paso es un tipo de motor DC que se puede controlar para moverse en pasos discretos, lo cual es ideal para aplicaciones que requieren una posición y control de velocidad precisos. Funciona a través de múltiples bobinas organizadas en fases que, al ser electrificadas secuencialmente, hacen girar la motor en pasos sucesivos.

  • ¿Por qué se usan motores paso a paso en lugar de otros tipos de motores?

    -Los motores paso a paso son útiles debido a su alta precisión y control de posición y velocidad, además de ofrecer un alto torque en precisión a bajas velocidades, algo que no es típico en los motores DC comunes.

  • ¿Cuáles son las desventajas de usar motores paso a paso?

    -Los motores paso a paso tienen menos torque a altas velocidades, consumen corriente constante independientemente de la carga, lo que significa que no son tan eficientes, y a diferencia de los servos, no tienen un mecanismo de retroalimentación para determinar su posición.

  • ¿Qué es el controlador de motor ULN2003 y cómo se utiliza con un motor paso a paso?

    -El controlador de motor ULN2003 es un chip que contiene transistores y diodos útiles para electrificar las bobinas múltiples de un motor paso a paso. Se utiliza para controlar la dirección y velocidad de la rotación al determinar la secuencia utilizada para llevar a tierra cada una de las bobinas.

  • ¿Cómo se conecta un motor paso a paso 28BYJ-48 a un Arduino?

    -El motor 28BYJ-48 es unipolar, y sus cables naranja, rosa, amarillo y azul están asociados con cuatro bobinas diferentes. Se conecta a un Arduino utilizando el chip de controlador de motor ULN2003, donde los pines de Arduino se conectan a este chip para controlar qué bobina se electrifica.

  • ¿Qué es la relación de reducción de engranajes y cómo afecta el motor paso a paso?

    -La relación de reducción de engranajes se refiere a cómo el eje del motor gira las salidas de engranajes. En el caso del motor 28BYJ-48, una relación de 1 a 64 significa que 64 revoluciones del eje del motor giran un eje de salida completo.

  • ¿Cuál es el ángulo de paso del motor paso a paso 28BYJ-48 y cómo se calcula?

    -El ángulo de paso del motor 28BYJ-48 es de 5.625 grados por paso en una secuencia de 8 pasos, resultando en 64 pasos por revolución. Se calcula dividiendo 360 grados entre el ángulo de paso por paso.

  • ¿Cómo se puede controlar la dirección y velocidad de un motor paso a paso con Arduino?

    -La dirección y velocidad de un motor paso a paso se pueden controlar mediante la secuencia y el tiempo de los impulsos en los pines de Arduino que están conectados al controlador de motor ULN2003.

  • ¿Qué es la biblioteca de motor paso a paso de Arduino y cómo se utiliza?

    -La biblioteca de motor paso a paso de Arduino permite construir objetos de tipo 'Stepper'. Al definir estos objetos, se le indica el número de pasos necesarios para una revolución en el eje de salida del motor y los pines de Arduino que están conectados al motor. La biblioteca proporciona funciones como 'step' para inducir rotación.

  • ¿Qué son las placas de motor y cómo facilitan el uso de motores con Arduino?

    -Las placas de motor, o motor shields, son hardware que se puede adjuntar a un Arduino que maneja todos los transistores, diodos y puentes H,简化了布线工作。 Proporcionan bibliotecas personalizadas que simplifican la escritura de programas para tus proyectos.

  • ¿Cómo se puede corregir el error de la posición del eje de salida debido al deslizamiento rotativo en un motor paso a paso?

    -El deslizamiento rotativo puede introducir un error de hasta tres grados en la posición del eje de salida. Para corregir esto, se puede calibrar el código agregando pasos adicionales, como se menciona en el script, para alcanzar los ángulos deseados.

Outlines

00:00

🤖 Introducción al control de motores paso a paso con Arduino

El primer párrafo presenta una introducción al control de motores paso a paso 28BYJ-48 utilizando Arduino. Se menciona que la presentación se basa en recursos en línea y es la última en una serie de 10 capítulos para un espacio de hackers en Tucson, Arizona. Se sugiere que los capítulos 4, 5, 8 y 9 sean revisados para comprender mejor este resumen. Los motores paso a paso son DC que se controlan en pasos discretos, ideales para aplicaciones que requieren posicionamiento preciso y control de velocidad. A pesar de su alto torque en bajas velocidades, presentan desventajas como menor eficiencia a altas velocidades y la falta de un mecanismo de retroalimentación de posición. Se describe cómo funcionan los motores paso a paso, con múltiples bobinas organizadas en fases que, al ser activadas secuencialmente, hacen girar el motor. Además, se introduce el uso del controlador de motor ULN 2003 para gestionar la activación de las bobinas.

05:02

🔌 Configuración y conexión del motor paso a paso a Arduino

Este párrafo se enfoca en la configuración y conexión del motor paso a paso al Arduino. Se discuten las especificaciones de voltaje y corriente que soporta el motor, indicando que no se necesita una fuente de alimentación externa si no hay carga significativa. Se describe el proceso de conexión de los pines del Arduino al controlador del motor y el uso de un potenciómetro conectado a un pin analógico para controlar la velocidad del motor. Se sugiere el uso de un código de ejemplo y se ofrece un enlace al mismo en el sitio web del presentador. Se detalla cómo se encierra todo en una caja para una demostración más práctica y cómo se realiza la conexión entre los pines del Arduino y el controlador del motor, así como el potenciómetro.

10:04

🔄 Funcionamiento y control del motor paso a paso

El tercer párrafo explica cómo funciona el motor paso a paso y cómo controlarlo. Se describe el proceso de generación de un campo magnético al aplicar corriente a las bobinas, lo que induce el movimiento del rotor. Se ilustra cómo se puede controlar la dirección y velocidad del motor variando la secuencia y el tiempo de encendido de los pines del Arduino. Se detalla el código utilizado para inducir movimientos en sentido horario y antihorario, y se muestra cómo se activan las bobinas a través de los pines del Arduino. Además, se menciona la utilización de LEDs en el controlador del motor para visualizar el funcionamiento del motor.

15:04

📏 Precisión y especificaciones del motor paso a paso

Este segmento se centra en la precisión y especificaciones técnicas del motor paso a paso. Se discute el concepto de relación de reducción de engranajes, que indica cómo muchas vueltas del eje del motor son necesarias para una vuelta en el eje de salida. Se calcula que 64 pasos del eje del motor resultan en una vuelta completa del eje de salida. Se describe el ángulo de paso del motor, que es la cantidad de rotación que produce cada paso en el eje del motor, y cómo esto se traduce en pasos necesarios para una vuelta completa del eje de salida. Se realiza un cálculo para determinar la cantidad de secuencias de pasos que deben ser llamadas para obtener una vuelta completa o parcial del eje de salida.

20:05

🔍 Solución de problemas y consideraciones adicionales

En este párrafo, el autor narra su experiencia al enfrentarse a un problema de precisión en el motor paso a paso. Después de varias pruebas y ajustes, se descubre que hay un margen de error debido al deslizamiento rotativo en el eje de salida, lo que puede introducir una diferencia de hasta tres grados. Esto llevó al autor a calibrar su código añadiendo pasos adicionales para alcanzar ángulos precisos. También se menciona la biblioteca de motores paso a paso incluida en el software de Arduino, que simplifica el proceso de construcción de objetos 'stepper' y el control de los mismos, aunque utiliza una secuencia de cuatro pasos en lugar de la secuencia de ocho pasos que se había estado utilizando hasta ese momento.

25:24

🛠️ Uso de shields de motor y conclusiones

El sexto y último párrafo habla sobre los shields de motor, que son piezas de hardware que se pueden adjuntar a Arduino para manejar transistores, diodos y puentes H,简化布线过程. Se hace hincapié en la importancia de revisar las especificaciones y limitaciones de potencia de cualquier shield que se considere, y se comparan opciones de proveedores confiables con clones más baratos disponibles en línea. Se concluye la serie de 10 capítulos desarrollada para el hackerspace, animando a los espectadores a dar like y suscribirse para futuras demostraciones y códigos asociados con las invensiones del presentador.

Mindmap

Keywords

💡Arduino

Arduino es una plataforma de prototipado de hardware de código abierto que permite a los diseñadores y artistas crear proyectos interactivos a través de la programación de circuitos electrónicos. En el video, Arduino se utiliza para controlar un motor paso a paso 28BYJ-48, mostrando cómo este dispositivo puede ser utilizado en proyectos de electrónica para lograr movimientos precisos y control de velocidad.

💡Motor paso a paso 28BYJ-48

El motor paso a paso 28BYJ-48 es un tipo de motor que se mueve en pasos discretos, lo que lo hace ideal para aplicaciones que requieren una posición y control de velocidad precisos. En el video, se detalla cómo controlar este motor utilizando un Arduino, destacando su popularidad y disponibilidad para proyectos de electrónica.

💡Unipolar

Un motor unipolar es aquel en el que todas las bobinas están conectadas a un solo tap central de voltaje común, a diferencia de los motores bipolares que tienen bobinas separadas. En el video, se menciona que el 28BYJ-48 es un motor unipolar, lo que significa que para activar una bobina se conecta su extremo a tierra, un concepto clave para entender cómo se controla el motor.

💡Controlador de motor ULN2003

El controlador de motor ULN2003 es un chip que contiene transistores y diodos, utilizados para controlar la conexión de múltiples bobinas en un motor paso a paso. En el video, se describe cómo este chip permite el control del motor 28BYJ-48 desde un Arduino, mediante señales que activan los transistores y, por ende, la secuencia de bobinas energizadas.

💡Potenciometro

Un potenciometro es un dispositivo de control analógico que varía la resistencia en una circuito a medida que se rota o se desliza. En el contexto del video, se utiliza un potenciometro para controlar la velocidad y dirección del motor paso a paso, permitiendo al usuario ajustar la velocidad de rotación del motor a través de un Arduino.

💡Resolución de paso

La resolución de paso se refiere a la cantidad de pasos que un motor paso a paso puede realizar para dar una vuelta completa. En el video, se discute cómo la resolución de paso varía entre secuencias de 4 y 8 pasos, afectando tanto la precisión del movimiento como la torque del motor.

💡Relación de reducción de engranajes

La relación de reducción de engranajes es la proporción entre las revoluciones del eje del motor y las revoluciones del eje de salida. En el video, se explica que una relación de reducción de 1 a 64 significa que se necesitan 64 revoluciones del eje del motor para obtener una revolución en el eje de salida, lo que es crucial para entender cómo se traducen los pasos del motor en movimientos más amplios.

💡Secuencia de paso

Una secuencia de paso es la forma en que se activan las bobinas de un motor paso a paso para lograr un movimiento. En el video, se describen dos tipos de secuencias de paso: la secuencia de 4 pasos y la de 8 pasos, donde cada una tiene implicaciones para la resolución y el torque del motor.

💡Biblioteca de motor paso a paso de Arduino

La biblioteca de motor paso a paso de Arduino es un conjunto de funciones predefinidas que facilitan el control de motores paso a paso sin necesidad de programar cada paso manualmente. En el video, se menciona cómo esta biblioteca simplifica el proceso de control del motor 28BYJ-48, permitiendo al usuario enfocarse en la lógica del movimiento en lugar de los detalles de hardware.

💡Placa de motor

Una placa de motor, o motor shield, es un accesorio que se puede conectar a un Arduino para facilitar el control de motores. En el video, se discuten las ventajas de usar una placa de motor, como la simplificación del proceso de conexión y la inclusión de bibliotecas personalizadas, aunque también se advierte sobre las posibles limitaciones de potencia y calidad en diferentes marcas.

Highlights

Introduction to controlling the 28BYJ-48 stepper motor with Arduino.

Stepper motors are suitable for precise positioning and speed control applications.

28BYJ-48 is a unipolar stepper motor with four coils controlled via a common 5V center tap.

ULN2003 motor driver chip explanation for managing multiple coils in stepper motors.

Wiring the Arduino to control the stepper motor direction and speed.

Explanation of stepper motor phases and how they induce motion in the rotor.

Use of a potentiometer to control motor speed in the demonstration setup.

Demonstration of the stepper motor's rotation and control using Arduino code.

Understanding the gear reduction ratio and its impact on output shaft rotation.

Calculating the number of motor shaft steps needed for a full output shaft revolution.

Difference between 4-step and 8-step sequences for stepper motors.

Adjustments needed for using the Arduino stepper library with the 28BYJ-48.

Practical demonstration of the stepper motor making full and half revolutions.

Issue of rotational slip in stepper motors and its effect on precision.

Using motor shields for simplified stepper motor control with Arduino.

Recommendations for purchasing motor shields and considerations for specifications.

Conclusion of the 10-part series on Arduino with a call to action for feedback and subscription.

Transcripts

play00:00

hello and welcome to this introduction

play00:01

to Arduino in this chapter I'll

play00:04

demonstrate how to control the popular

play00:05

and widely available 28 byj 48 stepper

play00:08

motor with your Arduino this

play00:11

presentation borrows from many online

play00:12

sources so thanks in advance to all of

play00:15

you who posted your own research online

play00:16

to help me reverse engineer how these

play00:18

little motors work this is the final

play00:21

chapter in a 10 part series developed

play00:23

for local hackerspace here in Tucson

play00:25

Arizona if you haven't already I

play00:27

recommend reviewing chapters 4 5 8 and 9

play00:30

in order to get the most out of this

play00:32

summary but if you're short on time

play00:34

don't worry too much about it so this is

play00:38

the setup that I'll be using throughout

play00:40

this presentation to demonstrate

play00:42

steppers these are just DC motors that

play00:45

can be controlled so that they move in

play00:46

discrete steps and for this reason

play00:48

they're great for applications that

play00:50

require precise positioning and speed

play00:52

control they also offer hight torque in

play00:55

precision at low speed which is not

play00:58

typical of common DC motors on the

play01:01

downside they have less torque at

play01:02

high-speed draw constant current

play01:05

independent of load so they're not as

play01:07

efficient and unlike servos have no

play01:09

feedback mechanism for determining their

play01:12

position also understanding and

play01:14

programming these can be a little tricky

play01:15

which is why broke steppers out from

play01:17

chapter 9 on motors and servos in order

play01:22

to help the move in discrete steps

play01:23

stepper motors have multiple coils that

play01:26

are organized in groups called phases

play01:29

surrounding magnets on a rotor by

play01:32

energizing each phase in sequence the

play01:35

motor will rotate one step at a time

play01:39

here's a simple conceptual model of how

play01:41

these steppers work in this simple

play01:44

demonstration we have a magnet on a

play01:46

rotor adjacent to a coil that has no

play01:48

current flowing through it as such

play01:50

there's nothing to induce motion of the

play01:52

magnet however if we apply current to

play01:57

the coil the magnetic field generated by

play01:59

that coil will attract the magnet

play02:01

attached to the rotor until the magnetic

play02:04

fields are aligned

play02:06

now if we Orient many of these coils

play02:09

around our magnet you can see how we can

play02:12

pulse those coils to induce continuous

play02:14

movement in the rotor these are two

play02:16

examples of how we might drive a stepper

play02:19

motor each method has its benefits and

play02:21

limitations as we'll discuss shortly I

play02:26

haven't seen stepper motors included in

play02:28

most starter kits so if you'd like to

play02:30

play with 128 byj 48 stepper is a good

play02:34

place to start these appear to be quite

play02:36

popular for use with Arduinos and

play02:38

there's plenty of documentation online

play02:39

on how to do the same the 28 byj 48 is a

play02:44

unipolar stepper in this stepper the

play02:47

orange pink yellow and blue leads are

play02:49

associated with one of four different

play02:51

coils as shown in the schematic on the

play02:53

right all of the coils are attached to a

play02:56

common 5 volt Center tap which is what

play02:58

makes this a unipolar stepper with this

play03:04

stepper we can determine which coil to

play03:05

energize by pulling the terminal end of

play03:08

a coil of interest to ground

play03:18

as will demonstrate shortly we can

play03:21

control the direction of rotation by

play03:22

determining the sequence used to ground

play03:24

each one of these coils

play03:27

so how do you manage which coil to

play03:30

ground

play03:30

well this stepper usually comes with a

play03:33

ul n 2003 motor driver chip this chip

play03:37

contains a series of transistors and

play03:39

diodes useful for grounding the multiple

play03:41

coils in your stepper motor as was

play03:44

described in chapter 9

play03:46

specifically by pulsing transistors with

play03:49

signals from your Arduino pins

play03:53

here's a schematic of the uln 2003 with

play03:57

some annotations to help explain how the

play03:59

current flows on the left you can see we

play04:01

have four Arduino pins attached to the

play04:03

motor driver chip you can use any GPIO

play04:07

pins on your Arduino for the same on the

play04:10

right we have for motor coils attached

play04:12

to a common 5 volt tab the common tab is

play04:15

the design used for unipolar motors

play04:17

although these coils have a 5 volt

play04:20

potential the coils cannot ground

play04:22

because of the transistors in the uln

play04:25

2003 as such there's no current flowing

play04:28

through the coils we can change this by

play04:31

sending some current to the transistor

play04:33

vo one of the Arduino pins this allows

play04:36

the potential running through the coil

play04:38

to ground thus inducing current flow

play04:41

through the respective coil the

play04:44

resulting magnetic field in the coil

play04:45

will induce movement in stepper motor we

play04:48

can control the direction and speed of

play04:50

the stepper depending on the sequence

play04:51

and timing for the firing of those

play04:54

Arduino pins as will be demonstrated

play04:56

shortly

play04:59

when exploring the stepper with Arduino

play05:01

we should check the specifications for

play05:03

the voltage and the current draw for

play05:05

this stepper we can expect maximum

play05:07

current draw of three hundred and twenty

play05:09

milli amps which is just under what we

play05:11

can pull off our five volt pin when

play05:13

running our Arduino off a USB cable so

play05:17

assuming nothing else is plugged into

play05:19

our dwee no and we're not putting a

play05:22

significant load on the motor we

play05:23

shouldn't need an external power supply

play05:25

although many online references may

play05:28

recommend using auxiliary power which is

play05:31

fine to demonstrate stepper logic

play05:34

I'll use this code source to one of the

play05:36

forums on steppers source to the Arduino

play05:39

Creative Commons website this along with

play05:42

other sketches will demonstrate our copy

play05:44

to my own website in the description of

play05:46

this video first let's go over how to

play05:49

wire things up

play05:52

notice that will be using pins 8 9 10

play05:55

and 11 of your Arduino to control the

play05:57

stepper through the controller board and

play06:00

will also be using a potentiometer wire

play06:01

to analog pin number 2 also notice that

play06:05

the control board power input is wired

play06:07

to the 5 volt pin on the Arduino which

play06:11

can provide us with up to 400 milliamps

play06:12

when running off USB or 9 hundred

play06:16

milliamps when plugged to an auxiliary

play06:17

power supply for my demonstration I've

play06:22

encased this whole thing in a box hot

play06:24

glued some piano wire to a motor shaft

play06:25

and added a template that lets me follow

play06:28

the angle of rotation of the motor this

play06:31

isn't necessary but it's a relatively

play06:33

inexpensive way to create something

play06:35

concrete that you can use to play with

play06:37

over time if you're interested in

play06:40

reproducing some of the demonstrations

play06:42

that are coming up you can download the

play06:44

code and the template for the 360

play06:46

degrees circle from my website found in

play06:49

the description of this video

play06:53

the Arduino is conveniently hidden

play06:56

inside the box and the wiring to the uln

play06:58

2003 is fed through a hole in the back

play07:02

of the box

play07:04

this shows how we wire the Arduino

play07:07

digital pins to the motor driver and

play07:13

this shows how to wire a potentiometer

play07:15

to analog pin 2 on this particular

play07:17

Arduino if your Arduino doesn't come

play07:20

with the second 5 volt pin like this one

play07:22

you may have to attach things through a

play07:24

breadboard as was shown in the original

play07:27

wiring diagram a few slides back

play07:30

next let's break down the sketch right

play07:34

at the top of the sketch is where we

play07:35

define our global variables

play07:39

we build these variables for controlling

play07:41

our steppers specifically through pins

play07:43

eight nine ten and eleven on the arduino

play07:47

and as we mentioned previously we have

play07:52

our potentiometer wired up to analog pin

play07:55

number two

play07:57

and finally we have two variables motor

play08:00

speed and pot value that will help us

play08:02

set the speed of the motor as well as

play08:04

store data from our potentiometer

play08:08

and here's our setup block here we're

play08:11

defining the Arduino pins attached to

play08:12

the motor driver as output pins these

play08:15

pins will engage the transistors in the

play08:17

motor driver chip resulting in specific

play08:19

coils being grounded in much the same

play08:22

way we were grounding the DC motor coil

play08:24

in our chapter 8 demonstration by

play08:27

grounding the coil will induce a

play08:29

magnetic field that induces the motor to

play08:31

turn and here's the loop part of our

play08:35

sketch the first thing we do is check

play08:37

the value of our potentiometer and store

play08:39

it in the variable pot value we then use

play08:44

a conditional to see if pot value is

play08:46

greater than or less than 535 which

play08:49

determines whether to call the clockwise

play08:51

or counterclockwise function

play08:56

the variable pot value is also used to

play08:59

calculate a value for the variable motor

play09:01

speed

play09:03

as mentioned earlier the sequence of

play09:06

pulses on the stepper motor coils will

play09:08

determine the direction of rotation here

play09:10

we can see how to induce a clockwise

play09:13

motion on the stepper by pulsing the

play09:15

four color-coded leads coming off the

play09:17

motor our sketch will induce the

play09:19

sequence by setting those leads attached

play09:21

to our dueño pins

play09:23

8 9 10 and 11 either high or low where

play09:27

the dashes in this table indicate high

play09:29

and the blanks indicate low

play09:33

and this is the code where we'll do that

play09:36

I'll also include a snapshot of our

play09:39

motor pin definitions so we know which

play09:40

leads are being pulled high or low as we

play09:43

go through this sequence finally I'll

play09:47

also add a physical diagram of the

play09:49

stepper motor itself so that we can see

play09:51

how coils are being energized to induce

play09:53

motion on the rotor before we walk

play09:57

through this just take notice that this

play09:59

function uses the motor speed value we

play10:01

calculated in our loop to calculate a

play10:04

delay between each step this gives us a

play10:07

way to control how fast that stepper

play10:09

motor turns as it's moving clockwise

play10:13

here you can see that the first step of

play10:16

the sequence shows that will only be

play10:17

setting motor pin for high which is

play10:20

attached to the orange lead and coil

play10:22

number four in the stepper the other

play10:24

pins will be kept low by creating a

play10:27

magnetic field in coil for the steppers

play10:29

rotor is induced to move next will

play10:33

engage both motor pins four and three

play10:35

this continues the clockwise motion in

play10:38

the stepper now let's continue firing

play10:41

the noted pins in the half step

play10:43

switching sequence to keep that motion

play10:45

going

play10:52

you

play11:01

and here is the total sequence shown in

play11:04

the table for the half step switching

play11:06

sequence for clockwise rotation

play11:10

well that's fine for clockwise rotation

play11:12

but what if I want to induce

play11:14

counterclockwise rotation for this let's

play11:17

move the clockwise function to the side

play11:19

and compare it to the counterclockwise

play11:20

function here you can see that the

play11:23

counterclockwise function is essentially

play11:25

reversing the order that those pins are

play11:27

being fired in essence this is the same

play11:30

as starting with a step seven in our

play11:33

step sequencing table and essentially

play11:36

what we're doing is running that

play11:37

sequence backwards and by running a

play11:40

clockwise sequence backwards this will

play11:43

induce a counter clockwise sequence in

play11:45

the Stuber

play11:48

and here's the example stuffer one

play11:51

sketch we've just outlined in action as

play11:54

mentioned in my description of the code

play11:55

you can see here that I'm controlling

play11:57

the direction and speed of the stepper

play11:59

motor using the potentiometer a really

play12:03

nice thing about the uln 2003 motor

play12:05

driver chip that comes with the steppers

play12:07

that we can actually see the pins that

play12:09

are being said I via suite of LEDs a

play12:12

nice bonus for exploring out these

play12:14

steppers work and if you listen closely

play12:18

it almost sounds like like a little

play12:20

motorcycle or the closest automotive

play12:24

analogy I can come up with is it's kind

play12:26

of like a rotor under a distributor cap

play12:29

that's essentially making contact with

play12:33

the spark plugs in an engine just kind

play12:35

of cool

play12:37

and this is the example stepper to

play12:39

sketch here I've set the motor speed to

play12:41

a large constant and this increases the

play12:43

pause between each steps so that you can

play12:45

see which pins are firing via the LEDs

play12:48

on the motor driver chip well that's

play12:53

fine for turning things forwards or

play12:55

backwards but what about all that

play12:57

precision positioning that steppers are

play12:59

known for in order to take advantage of

play13:02

that capability we need to delve a

play13:03

little deeper into the stepper

play13:05

specifications for this motor the specs

play13:08

indicate a gear reduction ratio of 1 to

play13:11

64

play13:14

well what does this mean to understand

play13:16

this it might help if we take the motor

play13:18

apart

play13:20

gear reduction has to do with the way

play13:23

the motor shaft drives the output shaft

play13:25

via a series of gears one two sixty four

play13:29

means that sixty-four revolutions of the

play13:31

motor shaft translates to one revolution

play13:34

of the output shaft if you study the

play13:37

gears you can kind of see how multiple

play13:39

turns of the motor shaft would be needed

play13:41

to create one revolution of the output

play13:43

shaft but there's an easier way to

play13:45

visualize this

play13:48

effectively the work of all those gears

play13:50

is the same as having a small gear

play13:52

driving a larger gear via chain although

play13:55

this drawing is not to scale you can see

play13:57

that it would take many revolutions of

play13:58

the small gear to generate one

play14:01

revolution of the larger gear in the

play14:03

case of our stepper motor it takes 64

play14:06

revolutions of the motor shaft gear to

play14:09

generate one revolution of the output

play14:12

shaft

play14:14

in order to control the motor precisely

play14:16

we also have to understand the step

play14:18

angle for our stepper the specifications

play14:21

indicate that each step generates five

play14:23

point six to five degrees of rotation on

play14:25

the motor shaft in an eight step

play14:28

sequence resulting in 64 steps per

play14:31

revolution now that's a lot of

play14:33

information so in order to understand

play14:36

how this might translate to other Stuber

play14:38

motors let's break this down a little

play14:41

further

play14:43

specifically this means that each step

play14:45

in an eight step sequence will generate

play14:49

five point six to five degrees of

play14:51

rotation in our stepper motor shaft for

play14:53

this particular sequence

play14:58

since five point six to five degrees is

play15:01

a fraction of the total 360 degrees

play15:04

needed for a full rotation the next

play15:06

question is how many of those five point

play15:10

six to five degrees steps do we need to

play15:12

complete one full revolution of the

play15:15

stepper motor shaft

play15:18

well we know that one revolution of the

play15:22

motor shaft is equal to 360 degrees and

play15:25

we're also told that each step produces

play15:28

five point six to five degrees of

play15:30

rotation if that's the case then 360

play15:34

degrees can be divided by five point six

play15:37

to five degrees per step and that gives

play15:40

us 64 steps so that tells us that

play15:44

sixty-four steps will result in one

play15:47

revolution of the motor shaft which

play15:50

matches the specification given for this

play15:53

particular motor

play15:55

well now that we understand how to

play15:58

control the motor shaft we'll next want

play16:00

to understand the number of motor shaft

play16:02

steps it takes to generate one

play16:03

revolution of the output shaft this is

play16:06

important because anything we attach to

play16:08

the stepper will be via the output shaft

play16:10

not the motor shaft here we can see it

play16:14

takes 4096 steps of the motor shaft to

play16:18

generate one revolution of the output

play16:20

shaft that's fine but again it really

play16:24

helps to understand how they come up

play16:25

with these numbers if we want to

play16:27

understand how to control other steppers

play16:29

outside of this one

play16:31

well we know it takes 64 revolutions of

play16:34

our motor shaft to generate one

play16:36

revolution in our output shaft let's

play16:39

write that down as our first term as we

play16:43

just calculated we also know it takes 64

play16:46

steps to generate one revolution of our

play16:48

motor shaft if we multiply these two

play16:51

terms together we get 4096 steps

play16:54

necessary to generate one revolution in

play16:57

our output shaft as per the given motor

play17:00

specification

play17:04

while that's fine for calculating the

play17:07

steps I need to induce a full 360 degree

play17:09

turn of my output shaft but in my sketch

play17:12

I have this sequence of eight steps

play17:14

embedded in a function so it's necessary

play17:17

to ask how many times do I have to call

play17:20

this full sequence to generate a full

play17:22

revolution of the output shaft well I

play17:25

know that 4096 steps will generate one

play17:29

revolution of the output shaft and I

play17:32

also know that one half step sequence is

play17:34

made up of eight steps so if I do the

play17:37

math on this this means that I have to

play17:39

call this sequence 512 times to generate

play17:43

one revolution of the output shaft

play17:48

okay so that's fine for a full turn but

play17:50

what if I wanted just a half a turn or

play17:53

180 degrees on the output shaft here's

play17:56

the math for that one I already know

play17:59

that I need five hundred and twelve

play18:01

sequences to generate one revolution of

play18:03

my output shaft if I only want half a

play18:06

revolution of the output shaft I just

play18:09

multiply it accordingly when I do the

play18:11

math I get 256 sequences so that's the

play18:15

same as calling that clockwise function

play18:17

256 times in my program and here's some

play18:23

code to test the math you can see that

play18:25

in the first for loop

play18:26

I'm calling the clock wise function 512

play18:28

times which should generate a full 360

play18:31

degree turn in my hub foot shaft in a

play18:35

clockwise motion and then I call the

play18:37

counterclockwise function 512 times

play18:39

which should bring the pointer on my

play18:42

output shaft all the way back to 0 and

play18:44

then I test the same clockwise and

play18:48

counterclockwise functions using 256

play18:51

which should cause a 180 degree turn

play18:55

forward clockwise and then bring it back

play18:58

to 0 so now let's demonstrate the

play19:03

example stepper 3 sketch which includes

play19:06

those 4 loops that I just summarized the

play19:08

first thing I'm gonna do is try to get

play19:10

this thing lined up I'm gonna reset it

play19:12

and uploading and there goes my first

play19:17

for loop clockwise and here it comes

play19:21

back now something interesting is going

play19:25

to happen you'll notice it didn't come

play19:27

back all the way back to 0 here's the

play19:30

180 forward here's the 180 back so that

play19:35

seems a little short to

play19:39

so this really bugged me because after

play19:44

all I mean we just walked through all

play19:46

these calculations and talked about how

play19:48

precise these stuffers can be and how

play19:50

you can control them with a great deal

play19:52

of precision so really rack my brain to

play19:55

figure out what was going on here so

play19:57

what happened first it took note of this

play20:01

little disclaimer that shows that the

play20:02

gear reduction ratio is actually smaller

play20:04

than 1 to 64 but if this were the source

play20:07

of the error the step angle would be

play20:09

larger and my code should be

play20:10

overshooting the full and half circle

play20:13

not undershooting it specifically if you

play20:16

do the math with more precise gear

play20:18

reduction ratio you're going to get 510

play20:21

sequences instead of 512 for a full

play20:24

circle and yet the code I tested has 512

play20:28

and still wasn't closing the circle so

play20:31

this isn't the source of the problem

play20:32

well I checked the wiring in the event

play20:35

coil wasn't firing correctly or in the

play20:37

right order that was ok then I tried

play20:40

slowing down the motor speed by an order

play20:43

of magnitude in the event the coils were

play20:44

firing too quickly and skipping a step

play20:46

that didn't help so then I even tried

play20:49

testing a second stepper and controller

play20:51

board to ensure there wasn't something

play20:53

wrong with the one I had set up

play20:55

originally I didn't have any luck so

play20:57

something else must be going on

play21:01

finally I came across this thread by an

play21:04

individual who tested several variations

play21:05

of these steppers most important he drew

play21:08

my attention to the fact that because of

play21:10

all the gearing in this motor there's an

play21:13

opportunity for what's known as

play21:14

rotational slip in the position of the

play21:16

output shaft as such this can introduce

play21:19

plus or minus three degrees of error

play21:22

this prompted me to calibrate my code

play21:25

and after many tests I observed a need

play21:27

to add four additional steps to get very

play21:30

close to what I was expecting for my

play21:31

half and full circle so this is just

play21:34

something to keep in mind when playing

play21:35

with this particular stepper if you're

play21:37

trying to land on a specific angle with

play21:40

your code next let's briefly talk about

play21:44

the Arduino stepper library included

play21:46

with our Arduino software this library

play21:50

lets us construct objects of type

play21:52

stepper when we first define these

play21:54

objects note that we need to tell it the

play21:56

number of steps needed to generate one

play21:58

revolution in our output shaft in this

play22:02

case we've already calculated that to be

play22:04

4096 we also need to specify the Arduino

play22:08

pins that are attached to our stepper

play22:10

motor by using this library and the

play22:13

stepper constructor to create a my

play22:15

stepper object we now have access to

play22:17

functions like step for inducing

play22:19

rotation when using this function we

play22:22

just need to indicate how many steps the

play22:24

object my stepper should take when we

play22:27

execute this line of code having such a

play22:30

library eliminates us from having to

play22:31

write complicated functions since these

play22:34

are already included in the stepper dot

play22:36

H library but it certainly doesn't hurt

play22:38

that we went through the code since now

play22:40

you have a better understanding of how

play22:41

these little Stoppers are controlled

play22:45

and reviewing the stepper motor

play22:46

specifications notice that we're given

play22:48

the heads-up that the Arduino stepper

play22:51

library uses something known as a four

play22:53

step sequence rather than the eight step

play22:56

sequence we've been experimenting with

play22:57

up to this point

play23:01

so what's the difference well when

play23:03

running the eight step sequence

play23:05

sometimes we're grounding one coil

play23:08

and sometimes we're grounding too this

play23:12

gives us the ability to produce a

play23:13

smaller step angle and thus greater

play23:16

resolution but we do lose some torque

play23:18

relative to the four step sequence we'll

play23:20

discuss next

play23:22

when using a four-step sequence we're

play23:25

always firing two coils this improves

play23:28

our torque and speed performance but at

play23:30

the expense of greater power demand and

play23:32

a lower stepping resolution

play23:36

so instead of using the 8 step sequence

play23:40

specifications we need to follow the 4

play23:42

step sequence which results in double

play23:45

the step angle from five point six to

play23:47

five degrees to eleven point two five

play23:48

degrees because the step angle has

play23:51

doubled we only need half as many steps

play23:54

to make a full revolution of our output

play23:56

shaft or 2048 steps rather than 4096

play24:02

steps

play24:05

in fact you can find an example sketch

play24:08

in the arduino ide called stepper one

play24:10

revolution but we'll have to make a few

play24:12

modifications to get it to work with the

play24:14

28 byj 48 stepper for starters we need

play24:18

to tell the sketch how many steps we

play24:19

need per revolution of our stepper

play24:22

output shaft here you can see that 200

play24:25

is defined but for our stepper running

play24:27

in 4 step sequence the steps will

play24:29

actually be 2048 also the library

play24:34

included with the arduino software

play24:35

expects the stepper to be wired a little

play24:37

differently so we'll need to modify this

play24:40

as well as shown

play24:42

finally the speed is much too high

play24:44

relative to what the stepper can handle

play24:47

so we want to make sure that the speed

play24:49

is set to 12 or less I've saved this

play24:53

code as stepper 1 revolution

play24:55

2 for download from my website let's

play24:58

save this code and give it a spin

play25:24

finally we can't close out our

play25:26

discussion of motors without mentioning

play25:28

motor shields this is hardware that you

play25:30

can attach to your Arduino that takes

play25:32

care of all those transistors diodes and

play25:34

H bridges thus saving you the trouble of

play25:36

having to do much of the wiring yourself

play25:38

if you're purchasing from reputable

play25:40

dealers like Adafruit or spark fun

play25:42

you'll get the added benefit of custom

play25:44

libraries that greatly simplify writing

play25:46

sketches for your inventions

play25:50

one thing that you want to pay attention

play25:51

to are the general specifications and

play25:54

power limitations of the shield that

play25:56

you're investigating for this one

play25:58

offered by Adafruit you can see that we

play26:00

have 1.2 amp power limitation per Bridge

play26:03

it allows up to 3 amps for brief periods

play26:06

of up to 20 milliseconds but you

play26:08

certainly wouldn't want to exceed that

play26:09

or you'd risk burning out your equipment

play26:13

you can find clones at a much lower cost

play26:16

on sites like eBay but don't count on

play26:18

getting the great customer service

play26:19

online form support or the satisfaction

play26:22

of knowing that you're supporting

play26:24

innovative companies like out of fruit

play26:25

or spark fun having said that I'll admit

play26:28

I sometimes purchase from eBay but make

play26:30

sure to pay close attention to

play26:31

specifications of what's being purchased

play26:34

for instance here you can see that this

play26:36

shield only supports half the peak

play26:38

current of the board sold by Adafruit so

play26:42

I hope this chapter in the series has

play26:44

given you enough information to start

play26:46

playing with steppers and exploring this

play26:48

stepper library that comes with your

play26:49

Arduino software this concludes the 10

play26:52

part series developed for 0 craft so if

play26:55

you found this series helpful please

play26:56

give this video a thumbs up thanks for

play26:59

watching and please consider subscribing

play27:01

for future demonstrations and code

play27:04

associated with some of my own

play27:05

inventions until next time

play27:13

[Music]

play27:23

[Music]

Rate This

5.0 / 5 (0 votes)

Related Tags
ArduinoMotor Paso a PasoControl de MotoresTutorialHackerspaceEjemplos de CodigoPotenciometroDriver ULN2003ProgramacionTaller de Robótica
Do you need a summary in English?