Jump to content

Experiment 5: Controlling DC Motor Using Transistor Driver Circuit

From cognifront
Revision as of 07:32, 18 August 2025 by Samrat277 (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.

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

// 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() {
  // 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);          
}

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.