Introduction: Arduino Nano and Visuino: Control Stepper Motor With Buttons

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

  1. One Arduino compatible board (I use Arduino Nano, because I have one, but any other will be just fine)
  2. One 5V Stepper Motor with Driver Board (I used 28BYJ-48 stepper with ULN2003 driver board )
  3. One Breadboard
  4. 6 Female-Female jumper wires
  5. 3 Male-Female jumper wires
  6. 2 short Male-Male jumper wires

Step 2: Connect the Stepper Motor to the Arduino

  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

Step 3: Start Visuino, and Select the Arduino Board Type

To start programming the Arduino, you will need to have the Arduino IDE installed from here: 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 also needs to be installed.

  1. Start Visuino as shown in the first picture
  2. Click on the "Tools" button on the Arduino component (Picture 1) in Visuino
  3. When the dialog appears, select Arduino Nano as shown in Picture 2

Step 4: In Visuino: Add and Connect Stepper Motor Component

  1. Type "step" in the Filter box of the Component Toolbox then select the "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 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

  1. In Visuino, 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

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 diagram.

Step 7: Connect the Buttons to Arduino

  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 pins that ware connected in this step

Step 8: In Visuino: Enable the Pull-Up Resistors for the Button Pins, and Add Inverter Components

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, 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 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

  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

  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

  1. In Visuino, 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...

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 diagram.

Also attached is the Visuino project, that I created for this Instructable. You can download and open it in Visuino: https://www.visuino.com

Comments

author
darondc made it!(author)2017-06-06

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.

author
ChrisC634 made it!(author)2017-02-28

will not heat up the chip when no buttons pressed?

author
BoianM made it!(author)2017-02-28

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

author
BoianM made it!(author)2016-04-19

Thank you RyanL92 ! What you don't like?