0% found this document useful (0 votes)
77 views6 pages

Mechatronics System Design - MECA 443 Lab Experiment 3 - Position Control Using An Encoder

The document describes an experiment to control the position of a DC motor using an encoder. A mechanical encoder is used to measure the rotation of the motor shaft and convert it to digital signals read by an Arduino Nano microcontroller. The user inputs a distance value, and the motor rotates until the encoder registers that distance in rotations has been reached, then stops. Materials used include a DC motor, mechanical encoder, Arduino Nano, motor driver. The number of encoder ticks corresponding to 2.5 cm of travel was measured and used to program the motor to stop after reaching that point.

Uploaded by

Ali Challak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views6 pages

Mechatronics System Design - MECA 443 Lab Experiment 3 - Position Control Using An Encoder

The document describes an experiment to control the position of a DC motor using an encoder. A mechanical encoder is used to measure the rotation of the motor shaft and convert it to digital signals read by an Arduino Nano microcontroller. The user inputs a distance value, and the motor rotates until the encoder registers that distance in rotations has been reached, then stops. Materials used include a DC motor, mechanical encoder, Arduino Nano, motor driver. The number of encoder ticks corresponding to 2.5 cm of travel was measured and used to program the motor to stop after reaching that point.

Uploaded by

Ali Challak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Mechatronics System Design– MECA 443 Lab

EXPERIMENT 3 – POSITION CONTROL USING AN ENCODER


Reine Hammad1, Ali Challak2, Ibrahim Oueidat3
1
Rafik Hariri University, College of Engineering, Department of Mechanical and Mechatronics

ABSTRACT
The aim of this experiment is to control a DC motor using an encoder. In this experiment, the degrees of
rotation as well as the direction of rotation of the DC motor are set by the user. The system should work
as follows: The user inputs a value that corresponds to a distance, i.e., 3 cm. The motor runs clockwise
and travels the distance entered by the user before it stops.
Keywords: DC motor, Motor drive, Mechanical encoder, Arduino Nano.

1. INTRODUCTION

The aim of this experiment is to perform an essential step during the initialization process
which is homing. In this experiment, a limit switch will be used to set a reference for the
system. The speed of the motor is set in the program. The system works as follows. When the
system is turned on, the motor starts rotating until it reaches a limit switch that is placed at
one end of the system. When the limit switch is reached, the motor stops. This sets a
reference point for the system. At this point, the motor starts running at the opposite
direction until it hits another limit switch which stops the motor to indicate that the maximum
traveling distance was reached.

FIGURE 1-Block Diagram

2. MATERIALS AND METHODS


2.1 Materials
 Arduino NANO:
Arduino NANO (figure 1) is one of the small and complete
boards of Arduino family. It is based on the ATmega328.
It has the same functionality of other Arduino boards but
in different package. The speed of its clock is 16 MHZ. It
contains 22 digital pins (six of them is PWM) and 8 analog
pins. Its operating voltage is 5 V. It contains 32 Kb
flash memory, and it can be connected to the PC by a FIGURE 2- ARDUINO NANO
USB cable. [1]

 DC motor:
12 volt DC motor is a rotary motor which can
convert the direct current into mechanical
energy or convert mechanical energy into DC
power. It means that the 12 volt DC motor can
1 FIGURE 3- DC motor
interconvert electric energy and mechanical energy. When it is operated as a DC
motor, electric energy is converted into mechanical energy. [2]

 Mechanical encoder:
A mechanical encoder is an electromechanical
device that converts position or movement into
a signal or signals that can be read by an
electronic circuit or processor system... [3]

FIGURE 4- mechanical encoder

 Motor drivers:
Motor drivers acts as an interface between the motors and
the control circuits. ... So the function of motor drivers is
to take a low-current control signal and then turn it into a
higher-current signal that can drive a motor. [4]

FIGURE 5- Motor drivers

2.2 Principle of operations :


 The aim of this experiment is to control a DC motor using an encoder. Where the de-
grees of rotation as well as the direction of rotation of the DC motor are set by the
user. So, the distance we took is 2.5cm where we should count the number of ticks
through the measured distance (2.5cm). thus, we found the relation between the dis-
tance traveled by the motor, number of ticks, and the mechanical rotary encoder. to
reach our aim we did the following:
 First, we measured the 2.5 cm distance on the belt that connects the motor and the
encoder (it rotates in ccw direction).
 Second, as the belt starts rotating the encoder starts reading the number of ticks for
the 2.5 cm distance to be reached. Where, the number of ticks was 25 using a serial
monitor.
 Finally, we added this value to our code and used the if else condition so the when it
exceeds 25 ticks or 2.5 cm the motor stops.
 If we changed the direction of rotation to cw, the count will change when it comes less
than 25 ticks the motor starts functioning again.

2
FIGURE 6- FLOWCHART

3. RESULTS AND DISCUSSION

3
3.1 Simulation

3
6

FIGURE 6- SIMULATION OF THE


CIRCUIT

3.2 Components
TABLE 1 shows the components numbering and naming used in the circuit.
Component’s Number Component’s Name
1 NI ELVIS
2 NANO Arduino
3 DC motor
4 Motor driver
5 mechanical encoder
TABLE 1: COMPONENTS USED IN THE CIRCUIT

3.4 Wiring
o Connect the two limit switches to pin 2, 3 in the Arduino NANO
o Take common ground between the Arduino and motor driver and the switches
o Connect the DC Motor to the motor drive
o Connect IN1 to pin 4 and IN2 to pin 5
4
4. Tinkercad stimulation

5. CONCLUSION
In brief, we reached our objective to use an encoder to control the position of a DC
motor. Where, the degrees of rotation as well as the direction of rotation of the DC motor are
set by the user. So that, the user inputs a value that corresponds to a distance and we
measured the number of ticks through the given distance so the motor will stop when the
distance is reached. This is done using various materials like 12V DC motor, mechanical
encoder, Arduino NANO, motor drive.

REFERENCES
[1] http://www.tecoelectric.com/blog/12-volt-dc-motors-definition-and-structure/
[2] https://www.arrow.com/en/categories/electromechanical-encoders/mechanical-encoders
[3] https://www.arduino.cc/en/pmwiki.php?n=Main/ArduinoBoardNano
[4] https://sproboticworks.com/blog/choosing-the-right-motor-driver

APPENDIX

int count=0;
int outputA = 6;
int outputB = 5;
int motor1 = 2;
int motor2 = 3;
int currentstateA;
int currentstateB;
int previousstateA;
float distance = 2.5;
5
int finalcount = 25;

void setup()
{
pinMode(motor1,OUTPUT);
pinMode(motor2,OUTPUT);
pinMode(outputA,INPUT);
pinMode(outputB,INPUT);
Serial.begin(9600);
previousstateA = digitalRead(outputA);

void loop()
{
currentstateA = digitalRead(outputA);

if(currentstateA != previousstateA)
{
currentstateB = digitalRead(outputB);
if(currentstateA != currentstateB)
count++;

else
count--;
Serial.println(count);
}
if (count < finalcount)
{
analogWrite(motor1, 0); //right
analogWrite(motor2, 150);
}
else{
analogWrite(motor1, 0); //stop
analogWrite(motor2, 0);
}

previousstateA=currentstateA;
}

You might also like