0% found this document useful (0 votes)
108 views3 pages

DC Motor Control for Robotics

This document is an assignment to control robot movement using two DC motors. It outlines connecting the DC motors to an Arduino Uno board using an L293D H-bridge motor driver. The program code controls the direction and speed of each motor to move the robot forward, backward, left and right. The student tests the circuit in a TinkerCad simulation and observes the DC motors changing directions as intended.

Uploaded by

subhek00
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)
108 views3 pages

DC Motor Control for Robotics

This document is an assignment to control robot movement using two DC motors. It outlines connecting the DC motors to an Arduino Uno board using an L293D H-bridge motor driver. The program code controls the direction and speed of each motor to move the robot forward, backward, left and right. The student tests the circuit in a TinkerCad simulation and observes the DC motors changing directions as intended.

Uploaded by

subhek00
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

Tafila Technical University

College of Engineering
Department of Computer and Communication Engineering
Real-Time and Embedded Systems (0107445)

Assignment 4
Title DC Motor Control For Robot Movement
Student Name SUBHI MAHER SUBHI KURDIEH
Student ID Number 320200112106

Page 1

Objective

The objective is to control robot movement directions bycontrolling2DCmotors.

Apparatus

1.TinkerCad Simulation
2.Embedded board(ArduinoUno)
3.ArduinoIDEsoftware
4.2-DCMotors
5.1-754410/L293DHBridge Driver
6.Breadboard

Block Diagram / Circuit Schematics

Program Code
// Motor A connections
int enA = 9;
int in1 = 8;
int in2 = 7;
// Motor B connections
int enB = 3;
int in3 = 5;
int in4 = 4;

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);
}
Theory / Calculations/ Plots
Nothing was used.

Observation / Data / System under Test


Step1 Implement the elements using
Tinkercad and make sure of it
Step2 Write and Upload the code on
Tinkercad code field
Step3 We start simulating the circuit and
watch the changes in directions
Step4 We will notice the results on the DC
motor as a movement

Discussion / results

We will notice the results on the DC motor as a movement (forward, backward, left, right)
and we can control the movement period.

Conclusion and recommendations


I recommend to try this experiment on a real robot to see clearly the results and
accomplish the objective.

Page 2

You might also like