Jump to content

Experiment 5: Controlling DC Motor Using Transistor Driver Circuit

From cognifront
Revision as of 03:44, 9 October 2025 by Siraj (talk | contribs)

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

  1. Connect DC motor through to Arduino.
  2. Use analogWrite() to vary motor speed.
  3. 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

Circuit Diagram

Board Connections

Board Connections

Circuit Connections

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);          
}

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.