⚙️ DC Motor Speed Control (Arduino + L293N)
A microcontroller-based system to control a 12V DC motor using PWM with two programmable speed patterns—ideal for industrial motion control and automation labs.
Circuit & Simulations



🎯 Objectives
Design and implement a microcontroller-based system that operates a DC motor with varying and constant speeds based on defined timing patterns, simulating industrial processes where precise speed control is critical.
🧩 Problem Description
Pattern 1 — Smooth Ramp
- Gradually increase speed to maximum within 1.5 minutes.
- Gradually decrease speed back to zero within the next 1.5 minutes.
- Turn OFF the motor.
Pattern 2 — Step-wise Doubling
- Slow speed for 30s → double for 30s → double again for 30s.
- Reduce speed in reverse order with the same delays.
- Turn OFF the motor.
🛠️ System Description
- Microcontroller: Arduino Uno (ATmega328P) — 8-bit MCU with 6 PWM channels.
- Motor Driver: L293N H-bridge — bidirectional control with PWM speed control.
- Motor: 12V brushed DC motor, continuous rotation, PWM capable.
- Power: 12V DC for motor, 5V regulated for Arduino.
- Software: Arduino IDE (development) and Proteus (simulation).
Arduino Pin | Motor Driver Pin | Function |
---|---|---|
D9 (ENA) | ENA | PWM signal for speed control |
D13 (IN1) | IN1 | Motor direction control |
D12 (IN2) | IN2 | Motor direction control |
GND | GND | Common ground |
5V | Vcc (logic) | Logic power (if required) |
💻 Arduino Source Code
// Arduino Code for DC Motor Control
const int ENA = 9; // PWM pin for speed control
const int IN1 = 13; // Direction control
const int IN2 = 12; // Direction control
// Speed parameters (PWM values 0-255)
const int speed1 = 50; // Minimum speed to overcome friction
const int speed2 = 255; // Maximum speed
void setup() {
pinMode(ENA, OUTPUT);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
// Initial direction (forward)
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
Serial.begin(9600);
}
void loop() {
Serial.println("Pattern 1:");
Pattern1();
delay(5000); // Pause between patterns
Serial.println("Pattern 2:");
Pattern2();
delay(5000); // Pause before repeating
}
void printSpeed(int speed) {
analogWrite(ENA, speed);
Serial.print("Speed set to: ");
Serial.print(speed);
Serial.print(" (");
Serial.print(map(speed, 0, 255, 0, 100));
Serial.println("%)");
}
// Pattern 1: Constant acceleration and deceleration
void Pattern1() {
const unsigned long rtime = 90000; // 1.5 minutes in ms
const int steps = 100;
// Ramp up
for (int i = 0; i <= steps; i++) {
int speed = map(i, 0, steps, speed1, speed2);
printSpeed(speed);
delay(rtime / steps);
}
// Ramp down
for (int i = steps; i >= 0; i--) {
int speed = map(i, 0, steps, speed1, speed2);
printSpeed(speed);
delay(rtime / steps);
}
// Turn off
printSpeed(0);
Serial.println("Motor OFF");
}
// Pattern 2: Double speed every 30s
void Pattern2() {
const unsigned long sTime = 30000; // 30 seconds
int baseSpeed = 60; // ~25% of max
int speedLevels[] = { baseSpeed, baseSpeed*2, baseSpeed*4, baseSpeed*2, baseSpeed, 0 };
for (int i = 0; i < 6; i++) {
printSpeed(speedLevels[i]);
Serial.print("Step "); Serial.print(i + 1);
Serial.print(" - Speed: "); Serial.println(speedLevels[i]);
delay(sTime);
}
Serial.println("Motor OFF");
}
📈 Simulation Results
- Pattern 1: Smooth acceleration to peak over 90s and symmetric deceleration to zero.
- Pattern 2: Step-wise speed doubling every 30s, then mirrored down to OFF.
🌍 Importance & Use Cases
This controller demonstrates techniques used in conveyors, pumps, fans, and process lines, where precise speed profiles reduce mechanical stress, improve throughput, and enable repeatable automation cycles.
🔗 Repository
MIT Licensed — Feel free to use, modify, and improve. ⭐ the repo if this helped!