Arduino Stepper Motor 28byj-48 Control Speed and Direction

by RonFrtek in Circuits > Arduino

878 Views, 4 Favorites, 0 Comments

Arduino Stepper Motor 28byj-48 Control Speed and Direction

Arduino Stepper Motor 28byj-48 Control Speed and Direction

In this tutorial we will learn how to move a stepper motor, change the speed with the potentiometer and change the direction using a button.

Watch the Video!

What You Will Need

stepper.jpg
pctdetail.775-114.1.jpg
mini_push_button.1471344052-600x435.png
VisuinoAdvrtisemenESPNowESP32C3-1.jpg
breadboard.png
djownload.jpg
jumper-wires.jpg
arduino.jpg
  • Arduino UNO (Or any other Arduino)
  • Stepper motor 28byj-48 & stepper motor driver board
  • Button
  • 1k ohm resistor
  • Potentiometer module
  • Jumper wires
  • Breadboard
  • Visuino program: Download Visuino


Brought by PCBWay

2022-08-26_13-41-18.jpg

Thank you PCBWay for supporting this tutorial and helping users learn more about electronics.

What I like about the PCBWay is that you can get 10 boards for approximately $5 which is really cost effective for professional made boards, not to mention how much time you save!

Go check them out here. They also offer a lot of other stuff in case you might need it like assembly3D printingCNC machining and a lot more.

The Circuit

2022-10-13_17-41-44.jpg
  • Connect Stepper Motor to Stepper Motor Driver
  • Connect Arduino pin [5V] to Driver Board pin [VCC]
  • Connect Arduino pin [GND] to Driver Board pin [GND]
  • Connect Arduino digital pin [8] to Driver Board pin [IN1]
  • Connect Arduino digital pin [9] to Driver Board pin [IN2]
  • Connect Arduino digital pin [10] to Driver Board pin [IN3]
  • Connect Arduino digital pin [11] to Driver Board pin [IN4]
  • Connect Arduino pin [5V] to breadboard positive pin [Red line]
  • Connect Arduino pin [GND] to breadboard negative pin [Black line]
  • Connect Arduino Digital pin [2] to the Resistor and button
  • Connect other side of the resistor to the breadboard pin [GND]
  • Connect Other pin of the button to the breadboard positive pin [5V]
  • Connect potentiometer pin [DTA] to arduino analog pin [A0]
  • Connect potentiometer pin [VCC] to the breadboard positive pin [5V]
  • Connect potentiometer pin [GND] to the breadboard pin [GND]



Start Visuino, and Select the Arduino UNO Board Type

Visuino-Select-Board-UNO.jpg
F5ZAEMUK36U3RS2.LARGE.jpg

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

In Visuino Add Components

2022-10-13_16-45-58.jpg
2022-10-13_16-45-28.jpg
2022-10-13_16-39-39.jpg
2022-10-13_16-00-56.jpg

Add "4 Wire Stepper Motor" component

Add "Debounce Button" component

Add "Toggle(T) Flip-Flop" component

Add "Map Range Analog" component

In Visuino Set Components

2022-10-13_16-47-46.jpg
2022-10-13_16-48-51.jpg
2022-10-13_16-48-30.jpg
  1. Select "MapRange1" and in the properties window set "Output Range" > "Max" to 500 <<this will be the maximum steps per second
  2. Select "Stepper1" and in the properties window select "Reversed" & click on the pin icon and select "Boolean SinkPin" and select "Steps Per Second" & click on the pin icon and select "Float SinkPin"

In Visuino Connect Components

2022-10-13_16-39-08.jpg
  • Connect Arduino Digital pin [2] to "Button1" pin [In]
  • Connect Arduino Analog pin [0] to "MapRange1" pin [In]
  • Connect "Button1" pin [Out] to "TFlipFlop1" pin [Clock]
  • Connect "TFlipFlop1" pin [Out] to "Stepper1" pin [Reversed]
  • Connect "MapRange1" pin [Out] to "Stepper1" pin [Steps Per Second]
  • Connect "Stepper1" pin [0] to Arduino digital pin [8]
  • Connect "Stepper1" pin [1] to Arduino digital pin [9]
  • Connect "Stepper1" pin [2] to Arduino digital pin [10]
  • Connect "Stepper1" pin [3] to Arduino digital pin [11]



Generate, Compile, and Upload the Arduino Code

FBR42I2KXBU01YW.jpg

In Visuino, at the bottom click on the "Build" Tab, make sure the correct port is selected, then click on the "Compile/Build and Upload" button.

Play

If you power the Arduino module, The motor will do will start to run and with the potentiometer you can change the speed. If you press the button the motor will change the direction.

Congratulations! You have completed your project with Visuino. Also attached is the Visuino project, that I created for this Instructable, you can download it here and open it in Visuino: https://www.visuino.eu