Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

DC motor controller using rotary encoder

By Ashutosh Bhatt June 26, 2023

Controlling a DC motor means:

  • Start and stop the motor
  • Change the running direction of the motor as forward (CW) or reverse (CCW)
  • Vary motor speed (RPM)

All different types of DC motor controllers control the speed and direction of the motor. They use different types of input devices like

  • Two push-buttons (or maybe a single push button) are used to start and stop the motor
  • SPDT type switch is used to select motor direction as CW or CCW
  • Potentiometer is used to vary the speed of motor
  • In some controllers, two push-buttons are used to increase-decrease motor speed (instead of potentiometer)

So, all these DC motor controllers require push buttons, a potentiometer, an SPDT switch, and maybe other components to control the motor’s speed and direction.

But in this project, only one rotary encoder is used to control the DC motor fully.

Means we can

  • Vary motor speed
  • Alter motor direction and
  • Start / stop motor

With only one rotary encoder. The rotary encoder replaces all the above components like buttons, pot, switch, etc.

The project uses a rotary encoder with an Arduino NANO development board to control the DC motor’s speed and direction. It also uses a motor driver module (L293). The complete project can be built with few components – modules. So let us see how it is done

Let us first collect the required things

List of required items

Arduino NANO development board


12 V DC Motor


Motor driver module


Rotary encoder module


Now, we shall build the circuit first, and then we shall see its working and operation. It is straightforward to build this circuit because we have to connect only 3 modules. One can easily build it using only jumper wires and a breadboard. Here is the snap of the circuit.

Circuit diagram

As shown in the figure, the circuit is built using three modules – rotary encoder, Arduino NANO, and DC motor driver L298.

  • Rotary encoder module has 5 interfacing pins. Out of these 5 pins – 2 pins are for Vcc and Gnd, and they are connected with 5 V output and Gnd of Arduino board.
  • Its other 3 pins, SW, DI, and CLK, are connected with Arduino board digital pins D12, D2, and D3 respectively
  • DC Motor driver module is used to drive motor and provide required voltage and current to it. It has 4 inputs to drive 2 DC motors, out of which 2 inputs IN1 and IN2, are used.
  • The PWM outputs D5 and D6 of Arduino board are connected to these IN1 and IN2 that are used to drive motor
  • A 12 V DC motor is connected to OUT1 and OUT2 of the motor driver module, as shown
  • Arduino board and motor driver module both are given 12 V from the external power supply

Working of circuit

As I have said before, the most interesting thing about this circuit is, using this rotary encoder only, we can…

  • Run or stop the motor
  • Alter the direction of motor
  • Vary the speed of motor

I will first explain how the circuit works, and then I will explain how it is done.

  • Initially, when 12 V supply is applied to Arduino board and motor driver module both, the motor is stopped
  • The motor starts running in either direction (clockwise or anticlockwise) when rotary encoder switch is pressed. When switch is pressed again – the motor stops. Thus by alternatively pressing switch – motor runs or stops
  • While motor is running in clockwise direction, if we start rotating encoder in same direction (clockwise) – it will keep on increasing motor speed till it reaches to max.
  • Else while motor is running clockwise, and if we start rotating encoder in reverse direction (anticlockwise) – it will start decreasing motor speed till it stops
  • Now, as encoder is rotated anticlockwise further, the motor slowly start running in anticlockwise direction and keep on increasing speed to max in anticlockwise direction
  • Thus, motor speed increases and decreases in either direction by rotating encoder clockwise and anticlockwise
  • So one can easily set desire speed and direction of motor using only rotary encoder

To understand the working of the circuit in detail, first, we have to understand the workings of a rotary encoder.

Working of rotary encoder

The rotary encoder consists of a slotted disk connected to common ground pin C and two contact pins A and B, as shown in the figure.

When you turn the knob, A and B come in contact with the common ground pin C, in a particular order according to the direction in which you are turning the knob.

When they come in contact with the common ground, they produce signals. These signals are shifted 90° out of phase with each other as one pin comes in contact with the other pin. This is called quadrature encoding.

When you turn the knob clockwise, the A pin connects first, followed by the B pin. When you turn the knob counterclockwise, the B pin connects first, followed by the A pin.

By tracking when each pin connects to and disconnects from the ground, we can use these signal changes to determine how the knob is being rotated. You can do this by simply observing the state of B when A changes state.

When the A changes state:

  • if B and A are not equal, then the knob was turned clockwise
  • if B and A are equal, then the knob was turned counterclockwise

See the figure given below

So these A and B outputs are DI and CLK pins of the rotary encoder module. The Arduino checks pulse output from both and determines encoder is rotated clockwise or anti-clockwise.

If the motor is rotating clockwise at some speed and

  • Case 1 – encoder is also rotated clockwise, then Arduino will increase PWM width on D5 – so the motor speed will increase. if encoder is rotated clockwise continuously – the motor reaches maximum speed
  • Case 2 – if encoder is rotated anticlockwise, then Arduino will decrease PWM width on D5, so motor speed decreases. And rotating encoder anticlockwise continuously will make PWM width on D5 to 0 and stop the motor once. Continue to rotate encoder in the same direction, increasing PWM width on D6, and motor will start rotating anticlockwise. If anyone keeps on rotating encoder in anti-clockwise direction, the PWM width on D6 becomes max, and the motor reaches max speed in an anti-clockwise direction.

The circuit’s complete working and operation is based on the program downloaded into FLASH memory of Arduino microcontroller ATMega328. The program is written in C language using Arduino IDE. The program uses the DC_Motor library to vary DC Motor speed and direction. Please go through DC_Motor library documentation for more details. here is the program code


You may also like:


  • What types of motors are used in electric vehicles?

  • What are the different types of integrated circuits?

  • What is sensor fusion?

  • Stepper motor angle control using rotary encoder

  • Controlling a BLDC Motor with an ESC

  • Choosing motors for robots

Filed Under: Electronic Projects

 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: 5G Technology
This Tech Toolbox covers the basics of 5G technology plus a story about how engineers designed and built a prototype DSL router mostly from old cellphone parts. Download this first 5G/wired/wireless communications Tech Toolbox to learn more!

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Right Half Plane Zero
  • dc-dc converter in series
  • Single ended measuring ports and balanced antenna
  • Thermal modelling of repetitive power pulse
  • Permittivity and Permealibility in CST

RSS Electro-Tech-Online.com Discussions

  • Fun with AI and swordfish basic
  • Microinverters and storeage batteries?
  • FFC connector white
  • Is AI making embedded software developers more productive?
  • Can I make two inputs from one??

Featured – LoRa/LoRaWan Series

  • What is the LoRaWAN network and how does it work?
  • Understanding LoRa architecture: nodes, gateways, and servers
  • Revolutionizing RF: LoRa applications and advantages
  • How to build a LoRa gateway using Raspberry Pi
  • How LoRa enables long-range communication
  • How communication works between two LoRa end-node devices

Recent Articles

  • RPi Python Programming 21: The SIM900A AT commands
  • RPi Python Programming 22: Calls & SMS using a SIM900A GSM-GPRS modem
  • RPi Python Programming 23: Interfacing a NEO-6MV2 GPS module with Raspberry Pi
  • RPi Python Programming 24: I2C explained
  • RPi Python Programming 25 – Synchronous serial communication in Raspberry Pi using I2C protocol

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe