Shop04 Urmi
Shop04 Urmi
: 04
Experiment Name: Control and Analyze the Operation of DC Motors Using Arduino and L293D
Motor Driver IC.
Objectives:
• To control and analyze the operation of DC motors using Arduino Uno and L293D motor
driver IC.
• To implement control over motor speed and direction using PWM and digital output pins of
the Arduino.
• To understand and apply microcontroller-based real-time motor control with user inputs and
safety mechanisms.
Theory:
DC motors are widely used in robotics, automation, and control systems due to their simplicity,
efficiency, and ease of control. In embedded systems, microcontrollers like Arduino are commonly
used to control DC motors using H-bridge motor driver ICs such as the L293D. This experiment
explores how DC motors can be controlled using software and digital inputs, with additional real-
time decision-making based on external inputs (push buttons).
The L293D is a dual H-bridge motor driver IC that allows two DC motors to be controlled
independently in both forward and reverse directions. It takes low-power control signals from the
Arduino and delivers higher power output suitable for driving motors. It has the following key
features:
Sequential Motor Control: In the first task of the experiment, the Arduino is programmed to:
Conditional Activation Using Push Button: In the second task, a push button is introduced before
Motor B starts. The system waits for the user to press the button before Motor B is allowed to run.
This demonstrates digital input reading using digitalRead() and the use of control structures
like while() loops to introduce user-based control. The button is configured with INPUT_PULLUP,
which simplifies wiring by avoiding the need for external resistors.
Emergency Stop Functionality: In the third task, another push button is added as an emergency
stop mechanism. If this button is pressed at any point during operation (whether Motor A, Motor
B, or both are running), the system halts immediately and permanently. This feature mimics a real-
world safety system and shows how input polling within loops can provide real-time interrupt-like
behavior even without hardware interrupts.
Figure 4.02: Connections to control DC motors with L293D Motor Driver IC & Arduino
Required Apparatus:
Table 4.1: Table for Required Apparatus
Sl. Components Model Specifications Quantity
no
3V~12V(DC), Maximum torque: 800gf cm
1 DC motor HR0242 min (3V) No-load speed: 1:48 (3V time) 2
The load current: 70mA (250mA MAX)
(3V)
Chip: ATmega328P (8-bit AVR) Clock
Speed: 16 MHz, Flash Memory: 32 KB,
SRAM: 2 KB , EEPROM: 1 KB, Digital I/O
Pins: 14 (6 provide PWM output: 3, 5, 6, 9,
2 Arduino UNO R3
10, 11), Analog Input Pins: 6 (A0–A5, 10-bit 1
resolution) DC Current per I/O Pin: 20 mA
DC Current for 3.3V Pin: 50 mA
3 Motor Driver IC L293D Supply voltage= 36 V max Logic supply 1
voltage= 36 V max Input Voltage= 7 V max
Enable Voltage= 7V max Total Quiescent
Logic Supply current= 60 mA max Total
Quiescent Supply current= 60 mA max
4 Wheel 2
5 Chassis Plywood 1
6 DC source 3.7 V 2
7 Battery casing 2×1 1
8 Hot gun and Glue 1
9 Software Arduino IDE
10 Jumper wires Male to Male wire 15
11 Bread board 1
12 Multimeter UT33A+ 1
Circuit Diagram:
Figure 4.03: Circuit Diagram to control DC motors with L293D Motor Driver IC & Arduino
Experimental Setup:
Experimental Procedure:
• Motor and Wheel Assembly
▪ Attach the wheels to the shafts of the two DC gear motors.
▪ Mount the motors on the chassis securely using glue.
• Circuit Connections
▪ Insert the L293D IC onto a breadboard.
▪ Connect the motor terminals to the L293D:
o Motor A to pins 3 (OUT1) and 6 (OUT2)
o Motor B to pins 11 (OUT3) and 14 (OUT4)
▪ Connect L293D control pins to Arduino:
o IN1 (pin 2) → Arduino pin 8
o IN2 (pin 7) → Arduino pin 7
o IN3 (pin 10) → Arduino pin 2
o IN4 (pin 15) → Arduino pin 4
o ENA (pin 1) → Arduino pin 9 (PWM)
o ENB (pin 9) → Arduino pin 3 (PWM)
▪ Connect L293D power supply:
o Vcc1 (pin 16) → 5V from Arduino
o Vcc2 (pin 8) → External motor power (6V–12V battery)
o GND (pins 4, 5, 12, 13) → Common ground (Arduino and motor power)
• Arduino Setup
▪ Connect Arduino Uno to the computer via USB.
▪ Open Arduino IDE and upload the basic direction and speed control code.
• Motor Initialization
▪ In the setup() function, set all motor control pins as OUTPUT using pinMode()
and initialize motor states to OFF.
• Motor Control Logic Execution
▪ In the loop() function, call the directionControl() function to:
o Run both motors forward for 2 seconds
o Then reverse both motors for 2 seconds
o Then stop both motors
▪ Call the speedControl() function to:
o Gradually increase speed to max and then decrease to stop
o Keep the motor running in reverse during speed variation
• Testing and Observation
▪ Power on the setup.
▪ We observed the motors rotating in both directions and at varying speeds as
programmed.
Hands-on Learning Projects for Mastery of DC Motor Control with Arduino and L293D
Task No.: 01
Task Name: Designing Timed Sequential Control of Dual Motors in a Repetitive Cycle.
Objective:
• To implement a time-based motor control system where Motor 1 runs for a specified duration,
followed by Motor 2, and then both motors run together, forming a repeatable operational
cycle.
Code:
int enA = 9; void loop() {
int in1 = 8; analogWrite(enA, 255);
int in2 = 7; analogWrite(enB, 0);
int enB = 3; digitalWrite(in1, HIGH);
int in3 = 2; digitalWrite(in2, LOW);
int in4 = 4; digitalWrite(in3, LOW);
void setup() digitalWrite(in4, LOW);
{ delay(10000);
pinMode(enA, OUTPUT); analogWrite(enA,0);
pinMode(enB, OUTPUT); analogWrite(enB,255);
pinMode(in1, OUTPUT); digitalWrite(in1,LOW);
pinMode(in2, OUTPUT); digitalWrite(in2,LOW);
pinMode(in3, OUTPUT); digitalWrite(in3,HIGH);
pinMode(in4, OUTPUT); digitalWrite(in4,LOW);
digitalWrite(in1, LOW); delay(10000);
digitalWrite(in2, LOW); analogWrite(enA,255);
digitalWrite(in3, LOW); analogWrite(enB,255);
digitalWrite(in4, LOW); digitalWrite(in1,HIGH);
} digitalWrite(in2,LOW);
digitalWrite(in3,HIGH);
digitalWrite(in4,LOW);
delay(10000); }
Task No.: 02
Task Name: Implementing Conditional Activation in Timed Dual Motor Control.
Objective:
• To design a control system where Motor 2 activates only upon receiving a user input or signal
after Motor 1 stops, followed by simultaneous motor operation for a fixed duration, in a
continuous cycle.
Code:
int enA = 9; analogWrite(enB, 255);
int in1 = 8; digitalWrite(in3, HIGH);
int in2 = 7; digitalWrite(in4, LOW);
int enB = 3;
int in3 = 2; delay(10000);
int in4 = 4; analogWrite(enA, 255);
int buttonPin = 5; analogWrite(enB, 255);
void setup() { digitalWrite(in1, HIGH);
pinMode(enA, OUTPUT); digitalWrite(in2, LOW);
pinMode(enB, OUTPUT); digitalWrite(in3, HIGH);
pinMode(in1, OUTPUT); digitalWrite(in4, LOW);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT); delay(10000);
pinMode(in4, OUTPUT); }
pinMode(buttonPin,INPUT_PULLUP);
stopMotors();
} void stopMotors()
void loop() { {
analogWrite(enA, 255); digitalWrite(in1, LOW);
analogWrite(enB, 0); digitalWrite(in2, LOW);
digitalWrite(in1, HIGH); digitalWrite(in3, LOW);
digitalWrite(in2, LOW); digitalWrite(in4, LOW);
digitalWrite(in3, LOW); }
digitalWrite(in4, LOW);
delay(10000);
analogWrite(enA, 0); void stopMotorA()
stopMotorA(); {
bool buttonPressed = false; digitalWrite(in1, LOW);
while (!buttonPressed) { digitalWrite(in2, LOW);
if (digitalRead(buttonPin)==LOW){ }
buttonPressed = true;
}
}
Task No.: 03
Task Name: Developing an Interlock-Based Safety Control in Dual Motor Sequencing.
Objective:
• To integrate a safety mechanism into the motor control sequence where the entire process halts
upon detecting a danger signal, while preserving conditional and timed motor operation.
Code:
int enA = 9; analogWrite(enB,255);
int in1 = 8; digitalWrite(in3,HIGH);
int in2 = 7; digitalWrite(in4,LOW);
int enB = 3; runForDurationWithStopCheck(10000);
int in3 = 2; analogWrite(enA,255);
int in4 = 4; analogWrite(enB,255);
int startButtonPin = 5; digitalWrite(in1,HIGH);
int stopButtonPin = 6; digitalWrite(in2,LOW);
void setup() { digitalWrite(in3,HIGH);
pinMode(enA, OUTPUT); digitalWrite(in4,LOW);
pinMode(enB, OUTPUT); runForDurationWithStopCheck(10000);
pinMode(in1, OUTPUT); }
pinMode(in2, OUTPUT); void stopMotors() {
pinMode(in3, OUTPUT); digitalWrite(in1, LOW);
pinMode(in4, OUTPUT); digitalWrite(in2, LOW);
pinMode(startButtonPin, digitalWrite(in3, LOW);
INPUT_PULLUP); digitalWrite(in4, LOW);
pinMode(stopButtonPin, analogWrite(enA, 0);
INPUT_PULLUP); analogWrite(enB, 0);
stopMotors(); }
} void stopMotorA() {
digitalWrite(in1, LOW);
void loop() { digitalWrite(in2, LOW);
analogWrite(enA, 255); analogWrite(enA, 0);
analogWrite(enB, 0); }
digitalWrite(in1, HIGH); void emergencyStop() {
digitalWrite(in2, LOW); stopMotors();
digitalWrite(in3, LOW); while (true) {
digitalWrite(in4, LOW); }
runForDurationWithStopCheck(10000); }
analogWrite(enA, 0); void
stopMotorA(); runForDurationWithStopCheck(unsigned
bool buttonPressed = false; long durationMs) {
while (!buttonPressed) { unsigned long startTime = millis();
if (digitalRead(startButtonPin) while(millis()-startTime
== LOW) { <durationMs){
buttonPressed = true; if (digitalRead(stopButtonPin)==
} LOW){
If digitalRead(stopButtonPin)==LOW){ emergencyStop();
emergencyStop(); }
} }
} }
Results:
In this project, we used an Arduino and an L293D motor driver to control two DC motors. In Task
1, the right motor ran for 10 seconds, then the left motor for 10 seconds, and finally, both motors
ran together for another 10 seconds. In Task 2, we added user input—after each button press, the
motors ran in the same sequence. This showed how we can control motors step by step using
simple commands. In Task 3, we programmed the Arduino to accept a special command from the
serial monitor. When we typed "kill," the entire motor operation stopped immediately. This added
a safety feature to shut down the system quickly when needed.
Discussion and Conclusion:
This experiment helped us understand how to control DC motors in multiple ways using an
Arduino. We implemented motor operation in a sequence, used user input to trigger actions, and
added a serial command to stop the entire process. The use of serial monitor, push buttons, and
jumper wires provided a practical experience, similar to real-world automation systems. Overall,
it was a clear and effective way to learn the basics of motor control and system interaction.