Reader small image

You're reading from  Arduino Robotic Projects

Product typeBook
Published inAug 2014
Reading LevelIntermediate
Publisher
ISBN-139781783989829
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Richard Grimmett
Richard Grimmett
author image
Richard Grimmett

Richard Grimmett has more fun that should be allowed working on robotics projects while teaching Computer Science and Electrical Engineering at Brigham Young University Idaho. He has a Bachelors and Masters degree in Electrical Engineering and a PhD in Leadership Studies. He also has 26 years of experience in the Radar and Telecommunications industries, and even has one of the original brick phones. He has written books on the basics of using the BeagleBone Black for robotics projects, and another for the Raspberry PI and yet another for the Arduino.
Read more about Richard Grimmett

Right arrow

The Arduino code for the DC motor shield


Now that the HW is in place, bring up the Arduino IDE; make sure that the proper port and device are selected and enter the following code:

The code is straightforward. It consists of the following three blocks:

  • The declaration of the six variables that connect to the proper Arduino pins are as follows:

    int pwmA = 3;
    int pwmB = 11;
    int brakeA = 9;
    int brakeB = 8;
    int directionA = 12;
    int directionB = 13;
  • The setup() function, which sets the directionA, directionB, brakeA, and brakeB digital output pins:

    pinMode(directionA, OUTPUT);
    pinMode(brakeA, OUTPUT);
    pinMode(directionB, OUTPUT);
    pinMode(brakeB, OUTPUT);
  • The loop() function. This is an example of how to make the wheeled robot go forward and then turn to the right. At each of these steps, you'll need to use the brake to stop the robot. The code is as follows:

    // Move forward
    digitalWrite(directionA, HIGH);
    digitalWrite(brakeA, LOW);
    analogWrite(pwmA, 255);
    digitalWrite(directionB, HIGH);
    digitalWrite...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Arduino Robotic Projects
Published in: Aug 2014Publisher: ISBN-13: 9781783989829

Author (1)

author image
Richard Grimmett

Richard Grimmett has more fun that should be allowed working on robotics projects while teaching Computer Science and Electrical Engineering at Brigham Young University Idaho. He has a Bachelors and Masters degree in Electrical Engineering and a PhD in Leadership Studies. He also has 26 years of experience in the Radar and Telecommunications industries, and even has one of the original brick phones. He has written books on the basics of using the BeagleBone Black for robotics projects, and another for the Raspberry PI and yet another for the Arduino.
Read more about Richard Grimmett