
- Suggested Learning Resources
- ACE-Lab Shop
- …
- Suggested Learning Resources
- ACE-Lab Shop
- Suggested Learning Resources
- ACE-Lab Shop
- …
- Suggested Learning Resources
- ACE-Lab Shop
DC Motor Speed Measurement with an Encoder Exercise | ACE-Lab DC Motor Speed Measurement with an Encoder
This exercise introduces encoder-based speed measurement for a DC motor controlled by an Arduino Uno and Maker Drive motor driver. A PWM input signal is applied to the motor, while encoder counts are captured in Simulink and converted into revolutions per minute. The measured RPM data can then be used to analyse the motor response and develop a mathematical model of the system.
Introduction video for the DC Motor Speed Measurement with an Encoder exercise, supporting the Arduino Uno, Maker Drive, encoder feedback, and Simulink workflow.1. Learning Outcomes
After completing this exercise, learners should refer back to these outcomes and check that they can connect the motor system, explain encoder-based speed measurement, configure Simulink data capture, and use measured RPM data for modelling.
Assemble the DC motor control circuitBuild a circuit using an Arduino Uno, Maker Drive motor driver, external power supply, and encoder feedback.
Explain encoder speed measurementDescribe how encoder counts can be used to calculate the rotational speed of a DC motor in revolutions per minute.
Configure Simulink for PWM and encoder captureApply a PWM input signal and capture encoder-based speed data from the motor using Simulink.
Use measured RPM data for modellingUse the measured speed response to develop and evaluate a mathematical model of the motor system.
2. Hardware Set-Up
This circuit builds on the previous motor-driver exercise by controlling a DC motor using an Arduino Uno and Maker Drive motor driver, with additional wiring for encoder feedback. The Arduino sends signals to the Maker Drive to control the motor speed, while the 9V battery provides the higher-power supply needed to operate the DC motor. The Arduino and motor driver must share a common ground so that the control signals are correctly recognised.
Required hardware:
- Arduino Uno
- Maker Drive motor driver board
- DC motor with encoder
- 9V battery and clip
- Breadboard
- Breadboard wires, various
- USB cable
Set-up guidance
Begin by setting up the circuit in the same way as the previous exercise: connect the motor to the Maker Drive output terminals and connect the 9V battery to the motor power input. Then add the Arduino control wires to the Maker Drive input pins so that the Arduino can set motor direction and use PWM to vary motor speed.
Figure 1: Hardware set-up for DC Motor Speed Measurement using an Encoder, showing the DC motor, Maker Drive motor driver, Arduino Uno, 9V battery, breadboard, and encoder/control wiring. 1Connect the DC motor wires to the Maker Drive motor output terminals. Use one motor channel, such as M1A and M1B.
2Connect the 9V battery positive wire to the Maker Drive motor power input, usually labelled VIN, VM, or +.
3Connect the 9V battery negative wire to the Maker Drive GND terminal.
4Connect a GND pin on the Arduino to the Maker Drive GND. This is essential because both boards need a shared reference voltage.
5Connect the Arduino 5V pin to the Maker Drive logic supply pin if required by the board.
6Use the breadboard to organise the shared 5V and GND connections if needed.
7Connect the Arduino control pins to the Maker Drive input pins. These wires are used to control the motor direction and speed.
8Connect the Maker Drive motor input pins for the selected motor channel to suitable Arduino digital or PWM pins.
9Check that the motor is connected only to the Maker Drive output terminals and not directly to the Arduino.
10Connect the Arduino to the computer using the USB cable.
3. Simulink Set-Up and Results
A 5 V step input, represented by a PWM value of 255, is applied to pin 9 of the Arduino and used to drive the connected DC motor. Simulink also captures input and output data so that the motor speed response can be inspected and used for modelling.
Apply the PWM input
Use a value of 255 to represent a 5 V step input and apply this signal to Arduino pin 9 using the PWM block.
Log the input voltage data
Within the Scope block Configuration Properties, open Logging, select Log data to workspace, and set Save format to Structure with time.
Use Goto blocks for data capture
Use Goto blocks to capture the input voltage step data and, later in the model, the speed output data.
Encoder speed principle: The encoder measures motor position in discrete counts. By analysing the change in position over a sampling interval, the motor speed can be estimated in RPM.Figure 2: Input voltage applied to the DC motor with an encoder. The model applies a PWM value of 255 to Arduino pin 9 and uses Goto and Scope blocks for data capture. Configure the encoder
Configure the encoder on the DC motor so that Simulink can determine the revolutions per minute of the motor from encoder counts.
Calculate counts per second
Use the change in position over the sampling interval to estimate speed. The Backward Euler approximation converts the signal from counts per second to revolutions per second.
Convert to revolutions per minute
Use a gain block to convert revolutions per second to revolutions per minute.
Account for the encoder and gear ratio
Use gain terms to account for the gear ratio of 1:298 and the encoder's 12 impulses per revolution.
Check direction if needed
If the motor spins in the opposite direction, swap the motor wires on the Maker Drive output terminals or change the direction logic in the code.
Backward Euler relationship: The position change is evaluated as (yₖ − yₖ₋₁) / Tₛ. The delayed sample can be represented using z⁻¹yₖ = yₖ₋₁.Figure 3: Encoder data capture and configuration using Simulink. The encoder counts are processed using a unit delay and gain blocks to estimate motor speed in RPM. Figure 4: Encoder data capture and configuration using Simulink with the main gain components combined. The scope output shows encoder counts per second and the RPM response used for modelling. 4. Additional Exercise
Use the revolutions per minute output data obtained from the Simulink scope to develop a mathematical model that captures the key dynamics of the motor system.
Develop a mathematical model
Use the measured input-output data to develop a model that captures the main behaviour of the motor response.
Compare measured and model outputs
Plot the measured RPM output data alongside the model output data so that the two responses can be compared visually.
Calculate the model fit
Assess the model accuracy by calculating the mean squared error between the measured RPM output and the model output.
5. Concluding Remarks
This exercise introduced the use of encoder feedback to measure the speed of a DC motor controlled by an Arduino Uno and Maker Drive motor driver. By applying a PWM input and processing the encoder counts in Simulink, the motor speed can be estimated in RPM and displayed for analysis.
The additional modelling task extends the practical work by using the measured data to develop a mathematical model of the motor response and assess its accuracy using the mean squared error.
Advancing automatic control engineering (ACE) education through global collaboration


