0% found this document useful (0 votes)
51 views5 pages

Dec50122 Embedded Robotics - Pw4 (Procedure)

Dec50122,Embedded Robotics pw4,Politeknik Seberang Perai (PSP)

Uploaded by

JustShareIt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
0% found this document useful (0 votes)
51 views5 pages

Dec50122 Embedded Robotics - Pw4 (Procedure)

Dec50122,Embedded Robotics pw4,Politeknik Seberang Perai (PSP)

Uploaded by

JustShareIt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
You are on page 1/ 5

ELECTRICAL ENGINEERING DEPARTMENT

SESSION 1 2023/2024

DEC50122 – EMBEDDED ROBOTIC

PRACTICAL WORK 4 : DC Motor /Servo Motor Speed & Control

PRACTICAL WORK DATE :

LECTURER’S NAME:

GROUP NO. :
1 LEARNING OUTCOMES (LO):

a) CLO2: design the concept of robot positioning, identification and communication in


mobile robot control according to a standard robot organization regulation (C6, PLO3)
b) CLO3: manipulate the application of sensor and actuator, robot identification and
communication during practical work based on land mobile robot design (P4, PLO5)

2 OBJECTIVE

At the ends of this session, students should able to

a) Design/Show mobile robot driving method using DC motor.


b) Identify the concept of Stop, Forward, Reverse, Left and Right.
c) Develop a program/ sketch to control the mobile robot.

3 THEORY
Servo motor works on PWM (Pulse width modulation) principle, means its angle of rotation is
controlled by the duration of applied pulse to its Control PIN. Basically servo motor is made up
of DC motor which is controlled by a variable resistor (potentiometer) and some gears. High
speed force of DC motor is converted into torque by Gears. We know that WORK= FORCE X
DISTANCE, in DC motor Force is less and distance (speed) is high and in Servo, force is High
and distance is less. Potentiometer is connected to the output shaft of the Servo, to calculate
the angle and stop the DC motor on required angle.
L293D is a 16 pin motor driver IC consist of quadruple half H drivers. It can simultaneously
control the direction and speed of two DC motors. L293d is a suitable device to use for stepper
motors, gear motors etc.

The IC has an operating voltage range from 4.5 V to 36 V. The L293 and L293D models can
drive current up to 1A and 600mA respectively.

L293D pin diagram

The IC L293D works with an H bridge arrangement, which can alternate the polarity across a
load or change the direction of the current.
5 PROCEDURE

TASK 1: SERVO MOTOR

a) Connect the circuit as shown below.

Schematic Diagram

b) Next, connect the potentiometer to pin analog A0, GND and =5V to complete the
circuit.
c) Then, Write the following code and compile and observe the result.

#include <Servo.h>

Servo myservo;
int value;
double angle;

void setup()
{
Serial.begin(9600);
myservo.attach(9);
}

void loop()
{
value = analogRead(A0);
angle = map(value, 0, 1023, 0, 180);
Serial.println(angle);
myservo.write(angle);
delay(15);
}

TASK 2 : DC MOTOR

a) Build the circuit according to the circuit below.


b) Write the code, compile and observe the result

int enA = 3;
int in1 = 6;
int in2 = 5;
// Motor B connections
int enB = 9;
int in3 = 11;
int in4 = 10;

void setup() {
// Set all the motor control pins to outputs
pinMode(enA, OUTPUT);
pinMode(enB, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);

// Turn off motors - Initial state


digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
}

void loop() {
directionControl();
delay(1000);
speedControl();
delay(1000);
}

// This function lets you control spinning direction of motors


void directionControl() {
// Set motors to maximum speed
// For PWM maximum possible values are 0 to 255
analogWrite(enA, 255);
analogWrite(enB, 255);

// Turn on motor A & B


digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
delay(2000);

// Now change motor directions


digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
delay(2000);

// Turn off motors


digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
}

// This function lets you control speed of the motors


void speedControl() {
// Turn on motors
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);

// Accelerate from zero to maximum speed


for (int i = 0; i < 256; i++) {
analogWrite(enA, i);
analogWrite(enB, i);
delay(20);
}

// Decelerate from maximum speed to zero


for (int i = 255; i >= 0; --i) {
analogWrite(enA, i);
analogWrite(enB, i);
delay(20);
}

// Now turn off motors


digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
}

You might also like