SMRTTECH 3CC3 · Cloud Computing and Internet of Things
Lab 6:Introduction to Stepper Motors
From serial commands to stepper motor motion using Arduino IDE, LabVIEW, and VISA.
Pre-lab: Arduino IDE installLab: 3 hoursHardware: external motor powerCommunication: VISA Serial
Central question
How does a typed command from LabVIEW become controlled stepper motor motion through Arduino firmware?
LabVIEW HMIRPM, revolutions, direction.
Command stringComma-delimited message.
VISA serialWrite to Arduino COM port.
Arduino parserExtract speed, turns, direction.
Stepper libraryConvert to motor steps.
Driver and motorExternal power creates motion.
Prepare
Scenario and objectives
You are building a local motion-control node that receives commands from a LabVIEW HMI, sends those commands over serial to Arduino firmware, and uses a motor driver plus external power supply to move a stepper motor in controlled increments.
Stepper motor model: energized windings act on the permanent-magnet rotor.Sequential winding states produce controlled, incremental shaft steps.
Learning goals
Build and drive a stepper motor with Arduino and LabVIEW.
Compile and upload Arduino firmware.
Send and parse serial data between LabVIEW and Arduino.
Explain the motor driver and external power supply.
WARNING: the stepper motor may heat up during operation. This can be normal, but use caution before touching the motor after it has been energized.
Use a screwdriver to adjust the power adaptor output to 9 V. Mount the breadboard power supply board correctly and use its regulated 5 V output to power the motor driver circuit.
Set the external adapter to 9 V before connecting it to the breadboard power board.Confirm the breadboard power-board orientation and jumper positions.Align positive pins with the red rail and negative pins with the blue rail.Connect the adapter barrel jack to the breadboard power board before motor testing.
STOP - verify polarity before powering. Reversing the breadboard power supply board can reverse project power and damage hardware.
Checkpoint 2
Build the stepper motor driver circuit
Build the circuit using the stepper motor, stepper motor driver, external power supply, breadboard power supply board, Arduino Mega, and jumper wires.
Connect Arduino pins 8–11 to driver inputs IN1–IN4. The driver receives motor power from the external 5 V rail.Verify the driver wiring, motor connector, supply rails, and Arduino ground.
Arduino pin
Driver pin
Checked
Notes
Digital 8
IN1
Digital 9
IN2
Digital 10
IN3
Digital 11
IN4
If power or motion is abnormal: switch off the external supply before touching wiring. Recheck 9 V adaptor selection, power-board polarity, regulated rails, common ground, and the D8-D11 to IN1-IN4 mapping before powering again.
Create a new sketch, paste the provided firmware, verify it, and upload it to the Arduino Mega.
The firmware uses the standard Arduino Stepper.h library, initializes serial communication at 9600 baud, reads a command string until newline, parses comma-separated values, and commands the stepper motor.
Set the baud rate to 9600, enter a command such as 10,1.5,1, and send it to the Arduino.
Use the syntax RPM,Number Revolutions,Direction. For example, 10,1.5,1 requests 10 RPM, 1.5 revolutions, and clockwise direction.
Close the Serial Monitor before running the LabVIEW VI. By default, only one client can use the same serial port at one time.
Command sent
Expected motion
Actual observation
Motor heat or lock-up?
If a Serial Monitor command does not produce safe motion
Stop sending commands and switch off motor power if the motor stalls, locks, or becomes hot. Verify 9600 baud, two comma delimiters, the newline setting, direction as 1 or -1, and a conservative RPM before changing one item and retesting.
The user selects RPM, revolutions, and direction, then sends the command to Arduino.
Front-panel elements
OK Button named Message Arduino.
Stop button.
String control named Revolutions.
Vertical toggle named Direction with Clockwise and Counter clockwise labels.
RPM meter with scale 5 to 20.
Sent Msg indicator for the exact command string.
Reasoning prompts
Why should students see the exact string sent to Arduino?
Why is direction represented as 1 or -1?
Why does RPM have a practical range?
What might happen if RPM is too low or too high?
Checkpoint 6
Use LabVIEW VISA Serial to write commands
Configure the serial port, use a loop and Case Structure, and close VISA after the loop.Concatenate RPM, a comma, revolutions, a comma, and direction into the string written to Arduino.
A. Serial functions
Add Configure Port, Set Buffer Size, Write, and Close from Data Communication - Protocols - Serial. Set VISA Resource Name to the Arduino serial port.
B. Case Structure
Use the Message Arduino button to decide whether to build and send a command string. In the false case, carry wires through.
C. Concatenate Strings
Use five inputs: RPM string, comma, Revolutions, comma, Direction string.
D. Convert RPM
Change the RPM meter from Indicator to Control and wire it through Number to Decimal String.
E. Select direction
Use Select to output string constant 1 for clockwise and -1 for counter-clockwise.
F. Test
Close Arduino Serial Monitor, run the VI, send commands, and observe motor motion.
RPM
Revolutions
Direction
Expected sent string
Actual sent string
Observed motion
If Serial Monitor works but LabVIEW VISA does not
Close Serial Monitor, verify the VISA Resource Name, confirm the command contains both commas and the required line ending, and check that VISA Write is in the True case. Keep the proven firmware and hardware unchanged while testing one LabVIEW correction at a time.
Extend
Replace revolutions with an angle command
Replace the Revolutions control with an Angle control. Instead of entering 0.5, 1, or 2 revolutions, the user enters 180, 360, or 720 degrees.
Angle command
Equivalent revolutions
Expected steps at 2048 steps/rev
How you modified LabVIEW
180 degrees
0.5
1024
360 degrees
1
2048
720 degrees
2
4096
Convert angle to revloutions in LabVIEW before concatenating the serial string.