World's Fastest PCB Manufacturing
My Message
Suggestions
Account

Get started now

Log In

or

Sign Up

My ALLPCB

My Orders Shipping Address Balance Account Settings My SNS Profile
0
  • Home
  • Instant Online Quote Alternate Text
    • PCB Instant Quote
    • PCB Assembly Quote
    • SMD-Stencil Quote
  • PCB Assembly
  • PCB Capabilities
  • Feedback
  • Resources
    • Sponsorship
    • PCB Softwares
    • Units Conversion
    • FAQ
  • About Us
    • About Us
    • Why Us
    • Contact Us
    • News
Log In Sign Up
  • Home
  • Instant Online Quote
    • PCB Instant Quote
    • PCB Assembly Quote
    • SMD-Stencil Quote
  • PCB Assembly
  • PCB Capabilities
  • Feedback
  • Resources
    • Sponsorship
    • PCB Softwares
    • Units Conversion
    • FAQ
  • About Us
    • About Us
    • Why Us
    • Contact Us
    • News
service@ALLPCB.com
Thank you very much for your valuable suggestion!
We will solve it as soon as possible!

A tutorial for the Arduino Motor Shield

2017/1/20 20:08:41

Overview
The Arduino Motor Shield is a shield that lets you control various loads that a typical Arduino pin cannot drive. The motor shield has quite a few features such as current measuring and the ability to drive a single stepper motor. At the heart of this shield is the L298P dual full bridge driver that can handle up to 3 amps for very short durations or 2 amps continuously per channel. Thorough example code is available for all the sections in the attached zipped folder.
Power Supply Requirements
The motors attached to the motor shield need an ample power supply. By using the USB connection, the current will often be limited to 500mA or 1 amp. Many motors will draw more current than the amount the USB source can supply. To reduce the risk of possible damange to a usb port an external power supply should be used.
Setup
In order to used this shield, you need to initialize several of the pins used by the shield. This setup code is typically placed in the setup function. To use all the functionality of the shield, pins 8,9,12, and 13 need to be initialized as output pins. This can be done with the following code:
pinMode(8,OUTPUT); //Channel A Brake Pin Initialize pinMode(9,OUTPUT); //Channel B Brake Pin Initialize pinMode(12,OUTPUT); //Channel A Direction Pin Initialize pinMode(13,OUTPUT); //Channel B Direction Pin Initialize
Direction Control
To control the motor’s direction, Pin 12 (Channel A) and Pin 13 (Channel B) are used. To drive the motor forward* this pins needs to be brought high. The pins can be driven low to put the motors into reverse.
Important note: Changing direction rapidly can cause unexpected effects. From a mechanical standpoint, going from forward to reverse rapidly could potentially damage a gear box. From an electrical standpoint, it can cause large current and voltage spikes. To resolve these issues, a motor needs to be taken from one direction to another with a small pause inbetween. An example of this can be found in Basic_Control.ino, attached.
*Since the “forward” direction of the motors depends on application, for this tutorial "forward" will refer to positive voltage on the + screw terminal on the shield.
Speed Control
To control the motors speed Pin 3 (Channel A) and Pin 11 (Channel B) can use PWM signals to vary the speed of the motors. To use the PWM feature on the arduino the analogWrite function needs to be called. In the function a pin needs to be defined and a speed between 0-255 needs to defined. An example of this can be found in Basic_Control.ino, attached.
Braking
The motor driver on the Arduino Motor Shield has the ability to apply an engine brake. The brake works by shorting both terminals of the motor together. The brake is controlled by Pin 8 (Channel A) and Pin 9 (Channel B).
Current Sensing
Another feature of the Arduino Motor Shield is the ability to determine the amount of current the motor (or any inductive load) is drawing. Current sensing can be useful for robotics applications, such as traction control and determining if the robot is pushing an object. The current sense pins are A0 (Channel A) and A1 (Channel B). The Motor Shield will output 3.3v on the current sense pins when the maximum channel current (2 amps) is reached.
After a small amount of math, it can be determined that each integer will represent 2.96mA. So for example, if the analogRead(A0) produces a value of 121 the motor (or load) is drawing 0.36 amps. An example of this can be found in Current_to_Serial.ino, attached.
Simple Project - Speed and Direction Control with a Potentiometer
By using the Arduino Motor Shield and a potentiometer, the speed and direction of a small motor can be controlled.
Parts Needed:
  • Arduino UNO (or Similar)
  • Arduino Motor Shield
  • Small DC Motor
  • Potentiometer (I used a 5K ohm single turn)
  • 4 Cell AA Holder (Or similar upto 12v) with batteries
Steps:
1. Plug In the motor shield into the Arduino.
2. Wire the potentiometer. The wiper of the potentiometer goes to pin A2 and the others go to Vin (assuming you're running off of USB power) and GND.
3. Attach the motor. For this project “Channel A” is used.
4. Attach the AA Battery Pack. Be sure to double check the polarity with a volt meter!
5. In the attached zip file there is a file for the Arduino IDE titled "pot_motor_control.ino". Using the Arduino IDE, upload the code to your Arduino board. To upload the code to the Arduino, press the right arrow in the circle.
6. You are all set! Move the potentiometer to adjust the speed and direction of the motor.
  • 2722
  • 1
  • 392
Post Comment

    Biagio Carlucci

    2017/1/22 20:08:41

    incredible work

    You might like

    madeo

    • Threads

      4

    • Following

      0

    • Followers

      0

    PCB Prototype

    PCB Instant Quote

    x mm

    Quantity

    Quote Now

    PCB Assembly

    SMT-Stencil

    Components Sourcing

    • 12
    Products & Service
    PCB Capabilities
    Aluminum PCB Service
    PCB Assembly Service
    SMT-Stencil
    Quotation & Feedback
    Online Auto-Quotation
    PCB Assembly Quote
    Quote by Salesperson
    Customer Reviews
    Customer Support
    FAQ
    Community
    Sponsorship
    Referral Program
    About Us
    About Us
    Why Us
    Contact Us
    News
    Resource Details
    PCB Software
    Units Conversion
    service@allpcb.com CEO@allpcb.com

    +86 18106594443

    Follow Us:
    Facebook Youtube Twitter Tumblr Youtube
    Certification: Certification
    Our Preferred Partners: Our Preferred Partners

    Please send Gerbers to service@ALLPCB.com for quotation © ALLPCB.com,All Rights Reserved Privacy PolicySitemap

    Secure Site by GoDaddy.com This site has earned the McAfee SECURE certification.