Arduino Nano and Visuino: Control Stepper Motor With Buttons

by BoianM in Circuits > Arduino

48000 Views, 44 Favorites, 0 Comments

Arduino Nano and Visuino: Control Stepper Motor With Buttons

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.

Components

56820916937ddbd3320003a0.jpeg
  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

Connect the Stepper Motor to the Arduino

DSC02314.JPG
DSC02315.JPG
567db7d845bcebeceb000307.jpeg
DSC02305.JPG
ArduinoStepperPins.jpg
  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 IN4 pins 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

Start Visuino, and Select the Arduino Board Type

SelectBoard.png
SelectBoard.png

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

In Visuino: Add and Connect Stepper Motor Component

ComponentStepper.png
ComponentStepperConnect.png
ComponentStepperSetSpeed.png
  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)

Generate, Compile, and Upload the Arduino Code

GenerateCtopped.png
Arduino IDE1.png
  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)

Test the Stepper Motor

568209764fbadee385000214.jpeg
VisuinoDiagramStepperCrop.png

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.

Connect the Buttons to Arduino

DSC02328.JPG
DSC02322.JPG
DSC02324.JPG
DSC02320.JPG
DSC02300.JPG
ArduinoButtonsPins.jpg
  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 Ground bus 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

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

SetPullUp.png
ComponentInverter.png
ComponentInverterConnect1.png
ComponentInverterConnect2.png

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)

In Visuino: Add and Connect Boolean or Component

ComponentOr.png
ComponentOrConnect1.png
ComponentOrConnect2.png
  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)

In Visuino: Add Enabled and Reversed Pins to the Stepper Motor Component, and Connect Them

ComponentStepperAddEnabled.png
ComponentStepperAddReversed.png
ComponentConnectEnabled.png
ComponentConnectReversed.png
  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)

Generate, Compile, and Upload the Arduino Code

GenerateCtopped.png
Arduino IDE2.png
  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)

And Play...

5682075c4936d4b9310002de.jpeg
VisuinoDiagramCropped.png

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