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!
Step 1: What You Will Need
- 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
Step 2: Brought by PCBWay
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 assembly, 3D printing, CNC machining and a lot more.
Step 3: The Circuit
- 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]
Step 4: Start Visuino, and Select the Arduino UNO Board Type
The Visuino: https://www.visuino.com also needs to be installed. Download Free version or register for a Free Trial.
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
Step 5: In Visuino Add Components
- Add “4 Wire Stepper Motor” component
- Add “Debounce Button” component
- Add “Toggle(T) Flip-Flop” component
- Add “Map Range Analog” component
Step 6: In Visuino Set Components
- Select “MapRange1” and in the properties window set “Output Range” > “Max” to 500 <<this will be the maximum steps per second
- 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“
Step 7: In Visuino Connect Components
- 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]
Step 8: Generate, Compile, and Upload the Arduino Code
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.
Step 9: 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 tutorial, you can download it and open it in
Visuino: https://www.visuino.com
Download stepper-run-cont-speed.zip