Friday, January 15, 2016

SPEED CONTROL OF DC MOTOR WITH ARDUINO AND L298 MOTOR DRIVER

PWM  CONCEPT

PWM speed control is a technique of transferring desired average power to the motor driver from arduino microcontroller by increasing or decreasing the pulse width of transferred square wave signal. This is also called a changing of duty cycle of signal of enable pin. This can be done by the pwm function of arduino using analogWrite() function and with the use of potentiometer.
analogWrite(variable,0); means 0% duty cycle
analogWrite(variable,255); means 100% duty cycle
analogWrite(variable, 128); means 50 % duty cycle and so on

look and understand the figure below .





CIRCUIT DIAGRAM

Connect the circuit as shown in the diagram carefully.




CODE OF THE PROJECT

  • copy the following code and upload it to your arduino board. 

int control=3;
int pot=A0;
int min1=4;
int min2=5;
void setup() {
  pinMode(control,OUTPUT);
  pinMode(pot,INPUT);
  pinMode(min1,OUTPUT);
  pinMode(min2,OUTPUT);
}

void loop() {
  int value=analogRead(pot);
  value=map(value,0,1023,0,255);
  digitalWrite(min1,HIGH);
  digitalWrite(min2,LOW);
  analogWrite(control,value);
}


  1. potentiometer out pin is connected to pin A0 of arduino
  2. control pin must be pwm pin (3,5,6, 9,10 ,11) of arduino uno and nano. 
  3. int value=analogRead(pot); reads the analog value from 0 to 5v in the form of 0 to 1023. 
  4. value=map(value,0,1023,0,255) maps the variable named value from 0-1023 to 0-255 since input resolution is 1024(0-1023) but output resolution is only 256(0-255). 
  5. to make motor move, one pin should be high and another must be low
  6. analogWrite(control,value); sets the value of control to the mapped value gained from potentiometer. 0 means no motion and 255 means full speed. 
  7. 2.2 kohms resistor is used between pin 3 and enable of motor driver otherwise your circuit wont work. 

  • start to turn around the potentiometer and see the effect on your motor. 
  • your motor speed should be increasing or decreasing based on your turning direction.

DEMO VIDEO OF THE PROJECT




If you get success to make this project then congratulation and if you are feeling trouble then please leave a comment. Thanks for the 

No comments:

Post a Comment