Arduino Motorshield - How to controll a DC Motor

There is also a video on YouTube for this article: Arduino DC Motor Controller - Motorshield

The Arduino Motor Shield can be used to control servo, stepper and DC motors. Because multiple pins are used to control the driver, a library is recommended. Adafruit offers a good library, which is also compatible with non-original shields. For most shields, the first version is needed because the second version works only with i2c.  The software can control the Moter as with PWM signals from 0-255. The shield requires an external voltage supply for the motors, which must also be suitable for the motors. The Arduino gets the power from the shield.

How the motor is controlled

The shield can be used to control up to four DC motors. Each motor connection has two pins, depending on the direction of rotation (forward, backward) one of the pins has energy.  The ground-pin is always used by two motors. To allow a simple DC motor to rotate in both directions, the motor must be reversed. Beginners can reverse the motor with a relay-card.

Arduino DC Motor Controller - Motorshield

#include <AFMotor.h>

AF_DCMotor motor(1); //Set Motor (1 = M1, 2 = M2, 3 = M3, 4 = M4)

void setup() {

void loop() {
  int i;; //FORWARD = PIN A / BACKWARD = PIN B
  motor.setSpeed(50); //Set motor speed
Info: This article has been partially translated automatically and may contain errors.

You Might Also Like


Social Media