Experiment 5: Controlling DC Motor Using Transistor Driver Circuit
Appearance
Experiment 5: Controlling DC Motor Using Transistor Driver Circuit
Objective
To control a DC motor's speed using PWM output from Arduino through a transistor driver circuit.
Task
- Connect DC motor through to Arduino.
- Use
analogWrite()to vary motor speed. - Implement a simple ramp-up or potentiometer-based speed control.
⚠️ Important Note:
1. Connect only the Arduino Uno (without any component connections) to the computer via USB.
2. Upload the code to the Arduino.
3. Disconnect the Arduino from the computer and remove the USB cable.
4. Make all component connections using patch cords as per the circuit diagram.
5. Then connect the 9V adapter to provide external power supply to the Arduino.
Circuit Diagram (without LCD)

Circuit Diagram (with LCD)

Board Connections (without LCD)

Board Connections (with LCD)

Circuit Connections (without LCD)
| Component/Pin | Connect To (Arduino) |
|---|---|
| DC Motor (via driver) | Output of Transistor Driver Circuit |
| Potentiometer (Vout) | A0 |
| Motor Input A1 | D5 |
| Motor Input A2 | D6 |
| Motor Enable (PWM) | D9 |
Code
// © 2025, Cognifront. Member of The IoT Kits Family.
// Experiment 5: Controlling DC Motor Using Transistor Driver Circuit
// with Serial Monitor output for potentiometer and motor speed
// Define analog input pin connected to the potentiometer
const int Pot = A0;
// Define motor control pins
const int motorA1 = 5; // Motor driver input A1 (direction control)
const int motorA2 = 6; // Motor driver input A2 (direction control)
const int enableA = 9; // Motor driver enable pin (PWM speed control)
void setup() {
// Start Serial communication for debugging and monitoring
Serial.begin(9600);
// Configure potentiometer pin as input (optional for analogRead)
pinMode(Pot, INPUT);
// Configure motor control pins as outputs
pinMode(motorA1, OUTPUT);
pinMode(motorA2, OUTPUT);
pinMode(enableA, OUTPUT);
}
void loop() {
// Read potentiometer value (range 0–1023 from ADC)
int potVal = analogRead(Pot);
// Map potentiometer range to motor speed range (0–255 for PWM)
int speed = map(potVal, 0, 1023, 0, 255);
// Set motor direction: A1 HIGH, A2 LOW → rotate in one direction
digitalWrite(motorA1, HIGH);
digitalWrite(motorA2, LOW);
// Control motor speed using PWM signal on enable pin
analogWrite(enableA, speed);
// Display potentiometer value and motor speed on Serial Monitor
Serial.print("Potentiometer Value: ");
Serial.print(potVal);
Serial.print(" | Motor Speed (PWM): ");
Serial.println(speed);
// Small delay for readability in Serial Monitor
delay(200);
}
Circuit Connections (with LCD)
| Component/Pin | Connect To (Arduino) |
|---|---|
| DC Motor (via driver) | Output of Transistor Driver Circuit |
| Potentiometer (Vout) | A0 |
| Motor Input A1 | D5 |
| Motor Input A2 | D6 |
| Motor Enable (PWM) | D9 |
| LCD VCC | 5V |
| LCD GND | GND |
| LCD SDA | A4 |
| LCD SCL | A5 |
Code
// © 2025, Cognifront. Member of The IoT Kits Family.
// Experiment 5: Controlling DC Motor Using Transistor Driver Circuit
// Added: Display potentiometer value and motor speed on 16x2 I2C LCD
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// I2C address for many modules is 0x27. If nothing appears, try 0x3F.
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Define analog input pin connected to the potentiometer
const int Pot = A0;
// Define motor control pins (using a transistor/H-bridge style driver)
const int motorA1 = 5; // Motor driver input A1 (direction control)
const int motorA2 = 6; // Motor driver input A2 (direction control)
const int enableA = 9; // Motor driver enable pin (PWM speed control)
void setup() {
// Start Serial communication for debugging and monitoring
Serial.begin(9600);
// Configure potentiometer pin as input (optional for analogRead)
pinMode(Pot, INPUT);
// Configure motor control pins as outputs
pinMode(motorA1, OUTPUT);
pinMode(motorA2, OUTPUT);
pinMode(enableA, OUTPUT);
// Initialize LCD
lcd.init(); // initialize the lcd (some libraries use begin(), init() works for common LiquidCrystal_I2C)
lcd.backlight(); // turn on backlight
lcd.clear();
// Initial display header
lcd.setCursor(0, 0);
lcd.print("Pot: ");
lcd.setCursor(0, 1);
lcd.print("Speed: ");
}
/*
🔌 LCD CONNECTIONS (16x2 I2C Display with Arduino UNO)
------------------------------------------------------
LCD Pin → Arduino Pin
----------------------------
GND → GND
VCC → 5V
SDA → A4 (I2C Data line on UNO)
SCL → A5 (I2C Clock line on UNO)
*/
void loop() {
// Read potentiometer value (range 0–1023 from ADC)
int potVal = analogRead(Pot);
// Map potentiometer range to motor speed range (0–255 for PWM)
int speed = map(potVal, 0, 1023, 0, 255);
// Set motor direction: A1 HIGH, A2 LOW → rotate in one direction
digitalWrite(motorA1, HIGH);
digitalWrite(motorA2, LOW);
// Control motor speed using PWM signal on enable pin
analogWrite(enableA, speed);
// Display potentiometer value and motor speed on Serial Monitor
Serial.print("Potentiometer Value: ");
Serial.print(potVal);
Serial.print(" | Motor Speed (PWM): ");
Serial.println(speed);
// Display on LCD (update only necessary parts; pad with spaces to clear previous digits)
lcd.setCursor(5, 0); // after "Pot: "
lcd.print(potVal);
lcd.print(" "); // pad to clear older digits
lcd.setCursor(7, 1); // after "Speed: "
lcd.print(speed);
lcd.print(" "); // pad to clear older digits
delay(200); // Small delay for readability
}
Observation
- As the potentiometer value increases, the PWM duty cycle on pin D9 increases.
- The motor speed changes smoothly in proportion to the potentiometer position.
- Direction remains constant because A1 is HIGH and A2 is LOW.
Conclusion
The DC motor speed can be controlled effectively using PWM output from Arduino and a transistor driver circuit. The potentiometer provides an analog input for real-time speed adjustment, demonstrating a simple method for variable motor speed control.