Daniel Rossi
Published © GPL3+

Control DC motor with NPN transistor & Arduino PWM

An easy way for controlling the rotation speed of a DC motor by using PWM signal from arduino and a NPN transistor

BeginnerFull instructions provided30 minutes61,436
Control DC motor with NPN transistor & Arduino PWM

Things used in this project

Hardware components

General Purpose Transistor NPN
General Purpose Transistor NPN
×1
Arduino UNO
Arduino UNO
×1
Multi-Turn Precision Potentiometer- 1k ohms (25 Turn)
Multi-Turn Precision Potentiometer- 1k ohms (25 Turn)
×1
9V battery (generic)
9V battery (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Schematics

new schematics updated on 25th January 2022.

Added:
- base pull-down resistor
- motor current limit resistor

Code

Arduino PWM for motor speed control

C/C++
//credits: Daniel Rossi, I.T. Engineering student from Modena(IT)
//YouTube: Https://youtube.com/c/ProjectoOfficial?sub_confirmation=1

/*
duty cycle in arduino is represented by a 8 bit value: 0 - 255
0 --> 0%
127 -->50%
255 --> 100%
*/

#define pwm 3
#define pot A0

void setup() {
  // put your setup code here, to run once:
  pinMode(pwm,OUTPUT);
  pinMode(pot,INPUT);
  Serial.begin(9600);
  //safety speed reset of the motor
  analogWrite(pwm,0);

}

void loop() {
  // put your main code here, to run repeatedly:
  float val = analogRead(pot);
  float duty = map(val,0,1023,0,255);
  analogWrite(pwm, duty); //here's how to generate PWM signal from Digital arduino pin
  Serial.println(duty);
}

Arduino On Off motor control

C/C++
//credits: Daniel Rossi, I.T. Engineering student from Modena(IT)
//YouTube: Https://youtube.com/c/ProjectoOfficial?sub_confirmation=1
#define pwm 3

void setup() {
  // put your setup code here, to run once:
  pinMode(pwm,OUTPUT);
  digitalWrite(pwm,LOW);

}

void loop() {
  digitalWrite(pwm,HIGH);
  delay(500);
  digitalWrite(pwm,LOW);
  delay(500);
}

Credits

Daniel Rossi

Daniel Rossi

7 projects • 24 followers
PhD Candidate in ICT @ AImageLab - University of Modena and Reggio Emilia Instagram: @officialprojecto

Comments