Hackster is hosting Hackster Holidays, Ep. 5: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 5 on Friday!
Techatronic
Published

DC Motor Speed Control Using Arduino

In this project, we are controlling the speed of a DC motor using a motor driver module and Arduino.

BeginnerProtip1 hour59,021
DC Motor Speed Control Using Arduino

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
DC motor (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
9V battery (generic)
9V battery (generic)
×1
Single Turn Potentiometer- 10k ohms
Single Turn Potentiometer- 10k ohms
×1
SparkFun Full-Bridge Motor Driver Breakout - L298N
SparkFun Full-Bridge Motor Driver Breakout - L298N
×1
USB-A to B Cable
USB-A to B Cable
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Code snippet #1

Plain text
 // TECHATRONIC.COM  
 void setup()   
  {   
  Serial.begin(9600);   
   pinMode(3,OUTPUT); // Motor pin 1   
   pinMode(4,OUTPUT); // Motor pin 2   
   digitalWrite(4,LOW); // Normally LOW inthis pin   
   pinMode(A0,INPUT);  // 10k Potentiometer   
  }   
  void loop()   
  {   
  int s=analogRead(A0); // 10k Potentiometer   
  int z=map(s,0,1024,0,255);   
  Serial.println(z);   
  analogWrite(3,z);   
  }   

Code snippet #2

Plain text
 // TECHATRONIC.COM  
 void setup()   
  {   
  Serial.begin(9600);   
   pinMode(3,OUTPUT); // Motor pin 1   
   pinMode(4,OUTPUT); // Motor pin 2   
   digitalWrite(4,LOW); // Normally LOW inthis pin   
   pinMode(A0,INPUT);  // 10k Potentiometer   
  }   
  void loop()   
  {   
  int s=analogRead(A0); // 10k Potentiometer   
  int z=map(s,0,1024,0,255);   
  Serial.println(z);   
  analogWrite(3,z);   
  }   

Credits

Techatronic

Techatronic

72 projects • 127 followers
Electronic engineer

Comments