Vous êtes sur la page 1sur 20

Arduino Nano and Visuino: Control Stepper Motor

With Buttons
by BoianM (/member/BoianM/) 19K
(/member/BoianM/) 32
Follow
4
advertisement

Arduino Nano and Visuino: Control Stepper Motor …

Stepper motors are often used in Arduino projects, whenever something needs to be
moved or turned. In this Instructable, I will show you how easy it is to connect
Stepper Motor to Arduino Nano and control it with Buttons.

STEP 1: COMPONENTS

4 p 5 ? 
1. One Arduino compatible board (I use Arduino Nano (http://rover.ebay.com/rover/1/711-53200-19255-
0/1?
icep_ff3=9&pub=5575122344&toolid=10001&campid=5337793773&customid=&icep_uq=arduino+nano&ic
because I have one, but any other will be just fine)
2. One 5V Stepper Motor with Driver Board (I used 28BYJ-48 stepper (http://rover.ebay.com/rover/1/711-
53200-19255-0/1?
icep_ff3=9&pub=5575122344&toolid=10001&campid=5337793773&customid=&icep_uq=28BYJ-
48+stepper&icep_sellerId=&icep_ex_kw=&icep_sortBy=12&icep_catId=&icep_minPrice=&icep_maxPrice=&i
with ULN2003 driver board (http://rover.ebay.com/rover/1/711-53200-19255-0/1?
icep_ff3=9&pub=5575122344&toolid=10001&campid=5337793773&customid=&icep_uq=ULN2003+driver+
)
3. One Breadboard
4. 6 Female-Female jumper wires
5. 3 Male-Female jumper wires
6. 2 short Male-Male jumper wires

advertisement

STEP 2: CONNECT THE STEPPER MOTOR TO THE ARDUINO

4 p 5 ? 
4 p 5 ? 
1. If not already connected, plug the Stepper Motor connector into the Driver Board
2. Connect one end of Female-Female jumper wires(Blue, Green, Yellow and Orange wires) to the IN1 to
IN4pins of the Stepper Driver(Picture 1)
3. Connect Ground(Black wire), and Power(Red wire), to the Stepper Driver module (Picture 2)
4. Connect the other end of the Power wire(Red wire) to the 5V power pin of the Arduino board(Picture 3)
5. Connect the other end of the Ground wire(Black wire) to Ground pin of the Arduino board(Picture 3)
6. Connect the IN1 wire(Blue wire) to the Digital pin 4 of the Arduino board(Picture 4)
7. Connect the IN2 wire(Green wire) to the Digital pin 5 of the Arduino board(Picture 4)
8. Connect the IN3 wire(Yellow wire) to the Digital pin 6 of the Arduino board(Picture 4)
9. Connect the IN4 wire(Orange wire) to the Digital pin 7 of the Arduino board(Picture 4)
10. Picture 5 shows where are the Ground, 5V Power, and Digital 4 to Digital 7 pins of the Arduino Nano
(http://rover.ebay.com/rover/1/711-53200-19255-0/1?
icep_ff3=9&pub=5575122344&toolid=10001&campid=5337793773&customid=&icep_uq=arduino+nano&ic

STEP 3: START VISUINO, AND SELECT THE ARDUINO BOARD TYPE

4 p 5 ? 
To start programming the Arduino, you will need to have the Arduino IDE installed
from here: http://www.arduino.cc/ (http://www.arduino.cc/) .
Please be aware that there are some critical bugs in Arduino IDE 1.6.6.
Make sure that you install 1.6.7 or higher, otherwise this Instructable will not work!
The Visuino (https://www.visuino.com): https://www.visuino.com
(https://www.visuino.com) also needs to be installed.
1. Start Visuino (https://www.visuino.com) as shown in the first picture
2. Click on the "Tools" button on the Arduino component (Picture 1) in Visuino (https://www.visuino.com)
3. When the dialog appears, select Arduino Nano as shown in Picture 2

advertisement

4 p 5 ? 
STEP 4: IN VISUINO: ADD AND CONNECT STEPPER MOTOR COMPONENT

4 p 5 ? 
1. Type "step" in the Filter box of the Component Toolbox then select the "4 Wire Stepper Motor
(https://www.visuino.com/wiki/index.php?title=4_Wire_Stepper_Motor)" component (Picture 1), and
drop it in the design area
2. Click in the "Out" box containing the pins of the Stepper component to start connecting all the Out pins
at once (Picture 2)
3. Move the mouse over the "Digital" input pin of the "Digital[ 4 ]" channel of the Arduino component. The
Visuino (https://www.visuino.com) will automatically spread the wires so they will connect correctly to
the rest of the pins(Picture 2)
4. Optionally you can specify the Speed of the Stepper, by setting the value of the StepsPerSecond
property of the Stepper4Wire1 component (Picture 3)

STEP 5: GENERATE, COMPILE, AND UPLOAD THE ARDUINO CODE

4 p 5 ? 
1. In Visuino (https://www.visuino.com), Press F9 or click on the button shown on Picture 1 to generate
the Arduino code, and open the Arduino IDE
2. In the Arduino IDE, click on the Upload button, to compile and upload the code (Picture 2)

STEP 6: TEST THE STEPPER MOTOR

4 p 5 ? 
Picture 1 shows the connected and powered up stepper motor.
If everything is properly connected, the motor should start rotating.
On Picture 2 you can see the complete Visuino (https://www.visuino.com) diagram.

STEP 7: CONNECT THE BUTTONS TO ARDUINO

4 p 5 ? 
4 p 5 ? 
4 p 5
1. Place the 2 buttons on the Breadboard(Picture 1)
? 
2. Connect the Male end of one of the Male-Female wires(White wire) to one end of one of the
buttons(Picture 1)
3. Connect the Male end of another one of the Male-Female wires(Brown wire) to one end of one of the
second button (Picture 1)
4. Connect one of the short Male-Male jumper wires(Black wire) between the unconnected end of one of
the buttons and the Groundbus of the Breadboard(Pictures 2 and 3)
5. Connect the other one of the short Male-Male jumper wires(Black wire) between the unconnected end
of the second button and the Ground bus of the Breadboard(Pictures 2 and 3)
6. Connect Male end of the last Male-Female wire(Black wire) to the Ground bus of the
Breadboard(Picture 4)
7. Connect the other end of the Ground wire(Black wire) to the Ground pin of the Arduino (Picture 5)
8. Connect the other end of the Second Button wire(Brown wire) to the Digital pin 2 of the Arduino
board(Picture 5)
9. Connect the other end of the First Button wire(While wire) to the Digital pin 3 of the Arduino
board(Picture 5)
10. Picture 4 shows in Red the Arduino Nano (http://rover.ebay.com/rover/1/711-53200-19255-0/1?
icep_ff3=9&pub=5575122344&toolid=10001&campid=5337793773&customid=&icep_uq=arduino+nano&ic
pins that ware connected in this step

STEP 8: IN VISUINO: ENABLE THE PULL-UP RESISTORS FOR THE BUTTON PINS,
AND ADD INVERTER COMPONENTS

4 p 5 ? 
When connecting buttons to Arduino, we don't need resistors, as the digital pins of
Arduino, have optional Pull-Up resistors. I already made a tutorial on how to use
Arduino Pull-Up resistor (https://www.instructables.com/id/Arduino-Nano-Using-Pull-
Up-Resistor-With-Visuino/), and I will use the same here:
1. Select the Arduino component(Picture 1)
2. In the Object Inspector expand the "Digital" property, then the Digital[ 2 ] sub property, and set the value
of the IsPullUp sub property to True(Picture 1)
3. In the Object Inspector expand the Digital[ 3 ] sub property, and set the value of the IsPullUp sub
property to True(Picture 1)

When using Pull-Up resistors, the the values of the buttons are inverted - when the
button is pressed, the value is False, instead of True. To correct this, we need to add
Inverters in the code:
1. Type "inv" in the Filter box of the Component Toolbox then select the "Boolean Inverter" component
(Picture 2), and drop two of them in the design area
2. Connect the "Out" pin of the "Digital[ 2 ]" channel of the Arduino component to the "In" pin of the

4 p 5 ? 
Inverter1 component(Picture 3)
3. Connect the "Out" pin of the "Digital[ 3 ]" channel of the Arduino component to the "In" pin of the
Inverter2 component(Picture 4)
STEP 9: IN VISUINO: ADD AND CONNECT BOOLEAN OR COMPONENT

4 p 5 ? 
1. Type "or" in the Filter box of the Component Toolbox then select the "Boolean Or" component (Picture
1), and drop it in the design area
2. Connect the "Out" pin of the Inverter1 component to the "Pin[ 0 ]" Input pin of the Or1
component(Picture 2)
3. Connect the "Out" pin of the Inverter2 component to the "Pin[ 1 ]" Input pin of the Or1
component(Picture 3)

STEP 10: IN VISUINO: ADD ENABLED AND REVERSED PINS TO THE STEPPER
MOTOR COMPONENT, AND CONNECT THEM

4 | p 5
technology (/technology/) ? 
| gy gy

1. Select the Stepper component (Picture 1)


2. In the Object Inspector click on the Pin button at front of the Enabled property, and select "Boolean
SinkPin" (Picture 1)
3. In the Object Inspector click on the Pin button at front of the Reversed property, and select "Boolean
SinkPin" (Picture 2)
4. Connect the "Out" pin of the Or1 component to the "Enabled" input pin of the Stepper
component(Picture 3)
5. Connect the "Out" pin of the Inverter1 component to the "Reversed" input pin of the Stepper
component(Picture 4)

STEP 11: GENERATE, COMPILE, AND UPLOAD THE ARDUINO CODE

4 p 5 ? 
1. In Visuino (https://www.visuino.com), Press F9 or click on the button shown on Picture 1 to generate
the Arduino code, and open the Arduino IDE
2. In the Arduino IDE, click on the Upload button, to compile and upload the code (Picture 2)

STEP 12: AND PLAY...

4 p 5 ? 
ControlStepperWithButtonsInstructable.zip
(https://cdn.instructables.com/ORIG/FR3/BMGM/IIQECN46/FR3BMGMIIQECN46.zip)

Congratulations! You have completed the project.


Picture 1 shows the connected and powered up project.
If you press one of the buttons, the stepper will start to rotate, until you release the
button. If you press the other button the stepper will start rotating in opposite
direction, until you release the button, as you can see in the Video.
On Picture 2 you can see the complete Visuino (https://www.visuino.com) diagram.

4 p 5 ? 
Also attached is the Visuino (https://www.visuino.com) project, that I created for this
Instructable. You can download and open it in Visuino (https://www.visuino.com):
https://www.visuino.com (https://www.visuino.com)

advertisement

Download

4 Comments

w I Made It!  Comment

darondc (/member/darondc/)
(/member/darondc/) Reply

Using 4D Systems 35DCT and MEGA 2560 with realy and DC motor
How do set on time for DC motor? I press button and relay to on time DC motor for 1500ms
I can not find examples for relay control or millis timing.
2017-06-06

ChrisC634 (/member/ChrisC634/)
(/member/ChrisC634/) Reply

will not heat up the chip when no buttons pressed?


2017-02-28

4 p
BoianM (/member/BoianM/)
5 ? 
(/member/BoianM/) Reply

Should be just fine. The drivers are intended to power the motor as far as I know ;-)
2017-02-28

BoianM (/member/BoianM/)
(/member/BoianM/) Reply

Thank you RyanL92 (https://www.instructables.com/member/RyanL92) ! What you don't like?


2016-04-19

I More Comments

| Post Comment

Share what you make

New Instructable (/create/)

Teachers (/teachers/) About (/about/) Contact (/contact/)

TOS (http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=21959721) | Privacy


(http://www.autodesk.com/privacy) | Legal (http://usa.autodesk.com/legal-notices-trademarks/) | Sitemap
(/sitemap/) | Full Site (http://www.instructables.com)

© 2017

4 p 5 ? 

Vous aimerez peut-être aussi