Table of Contents

Speed control of DC motor

Example Description
Learn how to control speed of the motor using Arduino and motor driver.
interfacing motor driver with Arduino

Arduino is a controlling device not a power source on the other hand, motors work on the principle of electromagnetism and hence draw a lot of load current which can’t be maintained by Arduino. To overcome this, we need a motor driver which maintains this load current along with the speed and direction control of the motor.

Circuit

connections

connection. 

Arduino uno            Motor driver

D5                             IN1

D4                             IN2

D6                             EN1

GND                          GND

Code

  • Create a variable as speed and set it 0

  • From actuators drag connect motor () direction 1() direction 2() and PWM()

  • from controls palette add a forever block

  • again from controls palette add if-then-else block in the forever block

  • We will be changing the speed using th up and down arrow. For this goto sensing and check for the key pressed.

  •  from Acturatos add run motor() direction () with speed()

  • Inset the value of the speed variable as motor speed

  • Repeat the above steps for the down arrow to reduce the speed. 

  • Add a wait block for a time of 0.25 seconds in forever block outside the if-then-else block.

  • now from the event palette add when flag clicked event at the start of the script.

Script

Output