Arduino Nano and Visuino: Control Stepper Motor with Buttons

Written by: roboguru

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.

Please note that the annotation on some of the pictures in this Instructable will work correctly on some browsers only after you click on the image to expand it.

Please make sure you click on the image to see the annotation showing the correct spot on the image!

Step 1: Components

Picture of 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 withULN2003 driver board )
  3. One Breadboard
  4. Female-Female jumper wires
  5. 3 Male-Female jumper wires
  6. 2 short Male-Male jumper wires

Step 2: Connect the Stepper Motor to Arduino

Picture of Connect the Stepper Motor to ArduinoDSC02315.JPG567db7d845bcebeceb000307.jpegDSC02305.JPGArduinoStepperPins.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 theArduino board(Picture 3)
  6. Connect the IN1 wire(Blue wire) to the Digital pin 4 of the Arduinoboard(Picture 4)
  7. Connect the IN2 wire(Green wire) to the Digital pin 5 of the Arduinoboard(Picture 4)
  8. Connect the IN3 wire(Yellow wire) to the Digital pin 6 of the Arduinoboard(Picture 4)
  9. Connect the IN4 wire(Orange wire) to the Digital pin 7 of the Arduinoboard(Picture 4)
  10. Picture 5 shows where are the Ground5V Power, and Digital 4 to Digital 7 pins of the Arduino Nano

Step 3: Start Visuino, and select the Arduino Board type

Picture of Start Visuino, and select the Arduino Board type

To start programming the Arduino, you will need to have the Arduino IDEinstalled 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 1.6.5, otherwise this Instructable will not work!

The Visuinohttps://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) inVisuino
  3. When the dialog appears, select Arduino Nano as shown in Picture 2

Step 4: In Visuino: Add and connect Stepper Motor component

Picture of In Visuino: Add and connect Stepper Motor componentComponentStepperConnect.pngComponentStepperSetSpeed.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 "Outbox 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 Stepper component(Picture 3)

Step 5: Generate, Compile, and Upload the Arduino code

Picture of Generate, Compile, and Upload the Arduino codeArduino 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)

Step 6: Test the Stepper Motor

Picture of Test the Stepper MotorVisuinoDiagramStepperCrop.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.

Step 7: Connect the Buttons to Arduino

Picture of Connect the Buttons to ArduinoDSC02322.JPGDSC02324.JPGDSC02320.JPGArduinoButtonsPins.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 theBreadboard(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 busof 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 theDigital 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

Picture of In Visuino: Enable the Pull-Up resistors for the button pins, and add Inverter componentsComponentInverter.pngComponentInverterConnect1.pngComponentInverterConnect2.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 onhow 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 toTrue(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 Arduinocomponent to the "In" pin of the Inverter1 component(Picture 3)
  3. Connect the "Out" pin of the "Digital[ 3 ]" channel of the Arduinocomponent to the "In" pin of the Inverter2 component(Picture 4)

 

 

 

 

Step 9: In Visuino: Add and connect Boolean Or component

Picture of In Visuino: Add and connect Boolean Or componentComponentOrConnect1.pngComponentOrConnect2.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)

 

 

 

 

Step 10: In Visuino: Add Enabled and Reversed pins to the Stepper Motor component, and connect them

Picture of In Visuino: Add Enabled and Reversed pins to the Stepper Motor component, and connect themComponentStepperAddReversed.pngComponentConnectEnabled.pngComponentConnectReversed.png

  1. Select the Stepper component(Picture 1)
  2. In the Object Inspector click on the Pin button at front of the Enabledproperty, and select "Boolean SinkPin" (Picture 1)
  3. In the Object Inspector click on the Pin button at front of the Reversedproperty, 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

Picture of Generate, Compile, and Upload the Arduino codeArduino 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)

 

 

 

 

Step 12: And play...

Picture of And play...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 Visuinohttps://www.visuino.com

http://www.instructables.com/files/orig/FR3/BMGM/IIQECN46/FR3BMGMIIQECN46.zip

 

 

Leave a Reply