Arduino Lesson 16. Stepper Motors: Search Adafruit
Arduino Lesson 16. Stepper Motors: Search Adafruit
Arduino Lesson 16. Stepper Motors: Search Adafruit
Stepper Motors | Adafruit Learning System
Search Adafruit
SHOP
BLOG
LEARN
FORUMS
VIDEOS
SIGN IN
CLOSE MENU
0 Items
Sign In
SHOP
BLOG
LEARN
FORUMS
VIDEOS
LEARN ARDUINO LEARN ARDUINO (17 of 18)
Arduino Lesson 16.
Stepper Motors
Learn Arduino, Lesson 16. Stepper
Motors
Overview
Parts
Breadboard Layout
Arduino Code
Stepper Motors
Other Things to Do
Single Page
Download PDF
Contributors
Simon Monk
Feedback? Corrections?
Arduino Code
SIMON MONK
The following sketch uses the Serial Monitor, so once the sketch is installed and running, open the Serial Monitor and enter a number of 'steps'. Try a value of about 500,
this should cause the motor to turn through about 360 degrees. Enter 500 and it will turn back in the reverse direction.
The Stepper library is included in newer distributions of the Arduino IDE you may need to upgrade.
Copy Code
1. /*
2. Adafruit Arduino ‐ Lesson 16. Stepper
3. */
4.
5. #include <Stepper.h>
6.
7. int in1Pin = 12;
8. int in2Pin = 11;
9. int in3Pin = 10;
10. int in4Pin = 9;
11.
12. Stepper motor(512, in1Pin, in2Pin, in3Pin, in4Pin);
https://learn.adafruit.com/adafruitarduinolesson16steppermotors/arduinocode 1/4
2/18/2016 Arduino Code | Arduino Lesson 16. Stepper Motors | Adafruit Learning System
12. Stepper motor(512, in1Pin, in2Pin, in3Pin, in4Pin);
13.
14. void setup()
15. {
16. pinMode(in1Pin, OUTPUT);
17. pinMode(in2Pin, OUTPUT);
18. pinMode(in3Pin, OUTPUT);
19. pinMode(in4Pin, OUTPUT);
20.
21. // this line is for Leonardo's, it delays the serial interface
22. // until the terminal window is opened
23. while (!Serial);
24.
25. Serial.begin(9600);
26. motor.setSpeed(20);
27. }
28.
29. void loop()
30. {
31. if (Serial.available())
32. {
33. int steps = Serial.parseInt();
34. motor.step(steps);
35. }
36. }
As you might expect, there is an Arduino library to support stepper motors. This makes the process of using a motor very easy.
After including the 'Stepper' library, the four control pins 'in1' to 'in4' are defined.
To tell the Arduino Stepper library which pins are connected to the motor controller, the following command is used:
Copy Code
1. Stepper motor(768, in1Pin, in2Pin, in3Pin, in4Pin);
The first parameter is the number of 'steps' that the motor will take to complete one revolution. The motor can be moved by one step at a time, for very fine positioning.
Serial communications is then started, so that the Arduino is ready to receive commands from the Serial Monitor.
Finally the following command sets the speed that we wish the stepper motor to move, when we subsequently tell it how many steps to rotate.
Copy Code
1. motor.setSpeed(10);
The 'loop' function is very simple. It waits for a command to come in from the Serial Monitor and converts the text of the number sent into an int using 'parseInt'. It then
instructs the motor to turn that number of steps.
BREADBOARD LAYOUT STEPPER MOTORS
Last updated on 20150504 at 04.27.11 PM Published on 20121220 at 10.29.07 AM
$4.95
Small Reduction Stepper Motor 5VDC 32Step 1/16 Gearing
Add To Cart
$2.95
Dual HBridge Motor Driver for DC or Steppers 600mA L293D
Add To Cart
$3.95
Premium Male/Male Jumper Wires 40 x 6" (150mm)
Add To Cart
$5.00
Halfsize breadboard
Add To Cart
https://learn.adafruit.com/adafruitarduinolesson16steppermotors/arduinocode 2/4
2/18/2016 Arduino Code | Arduino Lesson 16. Stepper Motors | Adafruit Learning System
$24.95
Arduino Uno R3 (Atmega328 assembled)
Add To Cart
ADD ALL TO CART
RELATED GUIDES
LEDS
LEDS / LED STRIPS
ADAFRUIT PRODUCTS / GEMMA
Animated NeoPixel Glow Fur Scarf
Wrap up in light and motion
The perfect accessory to keep you warm and get you noticed. 6 different customizable animated color modes suit your mood or your outfit. This is a beginner project
that's so versatile and fun that even advanced makers will want one.
ERIN ST BLAINE
LEARN ARDUINO
Arduino Lesson 10. Making Sounds
Learn Arduino, Lesson 10. Making Sounds
This is Lesson 10 in the Learn Arduino Adafruit series. In this lesson, you will learn how to make sounds with your Arduino. First you will make the Arduino play a
'musical' scale and then combine this with a photocell, to make a Theraminlike instrument that changes the pitch played as you wave your hand over the photocell.
SIMON MONK
LEARN ARDUINO
Arduino Lesson 9. Sensing Light
Learn Arduino, Lesson 9. Sensing Light
This is Lesson 8 in the Learn Arduino Adafruit series. In this lesson, you will learn how to measure light intensity using an Analog Input. You will then build on lesson 8
and use the level of light to control the number of LEDs to be lit.
SIMON MONK
SENSORS / CAMERA
POPULAR
TTL Serial Camera
Snap, Snap!
This guide is for our new TTL serial camera module with NTSC video output. These modules are a nice addition to a microcontroller project when you want to take a
photo or control a video stream. The modules have a few features built in, such as the ability to change the brightness/saturation/hue of images, autocontrast and auto
brightness adjustment, and motion detection.
LADY ADA
×
OUT OF STOCK NOTIFICATION
YOUR NAME
https://learn.adafruit.com/adafruitarduinolesson16steppermotors/arduinocode 3/4
2/18/2016 Arduino Code | Arduino Lesson 16. Stepper Motors | Adafruit Learning System
YOUR NAME
YOUR EMAIL
NOTIFY ME
CONTACT
SUPPORT
DISTRIBUTORS
EDUCATORS
JOBS
FAQ
SHIPPING & RETURNS
TERMS OF SERVICE
PRIVACY & LEGAL
ABOUT US
ENGINEERED IN NYC Adafruit ®
"Meaning can easily be confused with structure. Structure is a good approximation, but not the same" Claudia Perlich
https://learn.adafruit.com/adafruitarduinolesson16steppermotors/arduinocode 4/4