preloader

Search on AEQ-WEB

AEQ-WEB | Blog

Arduino Motorshield - How to controll a DC Motor

Arduino DC Motor Control

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;
  motor.run(FORWARD); //FORWARD = PIN A / BACKWARD = PIN B
  motor.setSpeed(50); //Set motor speed
  delay(2000);
  motor.setSpeed(100);
  delay(2000);
  motor.setSpeed(255);
  delay(2000);
  motor.setSpeed(50);
  delay(2000);
  motor.run(RELEASE);
  delay(1000);
}


Info: This page was automatically translated and may contain errors
Share:
thumbnail
07.06.2018
Arduino CC1101 Transceiver

On this page we will show you how to make a data transfer with the CC1101 and an Arduino. Wiring plan and libraries are available on AEQ-WEB

Alex @ AEQ-WEB
thumbnail
15.04.2019
Arduino MOSFET Control

In this article we show how to control large loads with a MOSFET transistor over an Arduino board and how you can control the speed of a motor with PWM

Alex @ AEQ-WEB