Dec50122 Embedded Robotics - Pw4 (Procedure)
Dec50122 Embedded Robotics - Pw4 (Procedure)
SESSION 1 2023/2024
LECTURER’S NAME:
GROUP NO. :
1 LEARNING OUTCOMES (LO):
2 OBJECTIVE
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.
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
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
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);
void loop() {
directionControl();
delay(1000);
speedControl();
delay(1000);
}