Arduino Projects with Robotics Using the Sparkfun RedBoard

Updated 16 May 2018

Welcome to the final Project Set of the Sparkfun Inventors Kit! This Project Set focuses on Robotics with the final Circuit being an Autonomously Driving Vehicle! New components introduced in this tutorial are: 

  • DC Motor/Gearbox
  • Motor Driver
  • Switch

Important programming and debugging concepts are also introduced in this tutorial; mainly serial communication and string parsing. Understanding these two concepts will expand your Arduino programming repertoire for further exploration into electrical and electronic projects at the completion of the Sparkfun Guide. Before we get into this Project Set, let's learn how to control the DC motor/gearbox included in the kit with a motor driver.


DC Motors and Motor Drivers

The small motors provided in the Sparkfun Kit are an amalgamation of a DC motor and a gearbox. The gearbox changes the speed and torque appearing at the output of the motor such that the new output (at the white plastic axels) is powerful enough to turn the wheels that are included in the Sparkfun Kit. The current required to drive these motors is much larger than that which can be delivered by the RedBoard, hence the need for a motor driver. A motor driver works by using FETs (Field Effect Transistors) in an H-bridge configuration to control a large load (such as a motor or collection of motors)from a small power source (such as an Arduino). The motor driver we will be using is the TB6612FNG Motor Driver, which has a total of 16 pins capable of supplying 2 outputs. The first circuit will introduce motor and motor driver basics such as electrical setup and how to control a motors speed and direction. The following two circuits use both driver outputs, with wheels connected to the axels of the DC motors, to create a vehicle which can be driven by serial communication and autonomously.


Project 5 - Circuit 5A

This Circuit will demonstrate the connections required between the RedBoard, DC motor and motor driver sufficient for a motor to operate. The Pinout of the motor driver can be found below.

motor-driver-pinout

Starting at top left-hand corner and working down, the Pin Configuration is as follows:

  • VM, VCC, and GND pins should be connected to the VIN, +5V and GND pins from the power bus respectively. VIN takes a value dependent on the RedBoard's power supply and it is this voltage that is used to drive the Motor(s). VCC and GND are used for logic reference points.
  • A01, A02, B02, B01 are the two-pin outputs from the driver for each of the motors (A & B). The motor's direction is based on their polarity (switching the wires reverses the direction of rotation) and their potential difference (voltage) determines the motor speed. If the voltage across a specific motor's output pins is not high enough (analogWrite(PWMA, < 128)) then the motor will not have the capacity to turn.  
  • PWMA and PWMB are the Pulse Width Modulated inputs for motor A and motor B respectively which control the associated motors' speed.  
  • AIN1, AIN2, BIN1, and BIN2 are the input pins that reference the Motor direction using the Driver's FET configuration described earlier.
  • STBY is the pin which allows for correct operation of the H-Bridge (the internal structure of the driver). It must be connected to a HIGH pin or +5V as it has a pull-down resistor configuration.

The motor cables don't possess polarisation, however, reversing them reverses the direction of rotational motion due to the properties of DC motor design. For the purposes of this and future Circuits, the AO1 and BO1 pins should be connected to the positive motor leads (red) and the AO2 and BO2 pins should be connected to the negative Motor leads (black). I suggest holding down the Motor in this first Circuit with blu-tack to limit its movement. 

Important notes:

  • Disconnect the RedBoard from the computer before connecting anything to the Power Bus
  • Ensure +5V isn’t connected straight to GND through the power rail or otherwise
  • Make certain that the Motor Driver is connected correctly by following the Pinout Diagram above

Project 5 - Circuit 5B

Now that we understand the basics of motor / motor-driver circuits, we can continue on our way to building an Autonomous Driving Vehicle! The next step is to include the second motor and attach both motors to the wheels and baseplate. Attaching the wheels to the motor is easy, simply fit the white axels from the Gearbox into the center-slots of the wheels. Grab the adhesive tape and cut off two strips that are the length of the flat face of the DC motor/gearbox; these strips will fix the motors to the baseplate. Set the final piece of tape aside as it will be used to mount the battery pack to the baseplate in the next Circuit. It's important to note that the motors should be mirror-images of each other as shown below. This is to ensure that the motor driver spins the wheels in the correct direction. Peel the back off the adhesive strips that were cut for the motor-baseplate connection, placing them on the baseplate underneath the breadboard and on the flat part of the properly orientated Gearboxes as shown below.

dual-lock-unassembled-rev-one    dual-lock-assembled-rev-one

The code for this circuit has two motor functions which independently control speed and direction of rotation for a given Motor (wheel). With the ability to control each motor independently, we are able to turn the Vehicle to the left or right by counteracting both motors rotation. Similarly, we can drive forward or backward by rotating the motors together. Another new addition to the code is that, instead of entering a motor speed, we enter in a distance (in inches) for linear motion and an angle in degrees for rotational motion. The serial port reads in a string which follows the form: a direction-identifying-character (l,r,f,b) and distance/angle number, separated by a space. The code then splits the string up to obtain the entered direction and distance/angle; this is quite cool! A binder clip should be attached to the baseplate on the RedBoard side so that the baseplate isn't dragged across the surface of the terrain and damaged.

Important notes:

  • Disconnect the RedBoard from the computer before connecting anything to the Power Bus
  • Ensure +5V isn’t connected straight to GND through the power rail or otherwise
  • Make certain that the Motor Driver is connected correctly by following the Pinout Diagram above

Project 5 - Circuit 5C

Well, this is it, the Final Circuit of the Final Project Set... An Autonomous Vehicle! This circuit will use a similar electrical set-up to the previous circuit; we'll just add the HCSR04 Ultrasonic Sensor that was introduced in Project Set 3. When connecting the sensor, make sure it is facing the 'front' of the vehicle with no chords (or the end of the breadboard) obstructing its view. The code in this circuit which makes the vehicle autonomous is set up so when an object is detected in front of the vehicle (within 10 inches from the sensor) it will back up, turn to the right and then begin driving forwards again. This program is a great example of if-else statements and sensors at work; there are only three functions (excluding the necessary setup() and loop() functions) used to make this autonomous vehicle possible! 

To make this Circuit portable, we will be attaching and using the battery pack from the Sparkfun Kit. The final strip of dual-lock adhesive should have one side attached to the baseplate underneath the baseplate section as shown in the second Circuit 5B photo. Make sure to not place the strip too close to the edge of the baseplate; we don't want the battery pack to drag on the floor when driving, make room for the binder clip. The other side of the adhesive strip should be stuck to the center of the battery pack base. After successfully uploading the Circuit 5C code to the RedBoard, disconnect the USB cable and lock the battery pack to the underside of the baseplate via the adhesive strips as shown in the photo below. The binder clip should also be attached as shown to protect the baseplate and battery pack from dragging on the floor. Upon connection of the battery pack's barrel jack to the RedBoard, the program should run and the vehicle should begin to move (provided the switch is positioned to be on).

battery-pack-connection


Congratulations! You've now completed the Sparkfun Inventors Kit Guide and are ready for the next stage in your electronics pathway! If you would like to visit any of the previous Sparkfun Inventors Kit tutorials before moving on, they can be found here:

If you're all studied up on the content of this Tutorial Set, there are many different avenues that you can now travel down to extend your Arduino and/or Electronics knowledge. Our website has new tutorials being released all the time. Some interesting content by us can be found here:

In addition to our great resources, there are library examples, forums and project ideas that can be found on the Arduino Website under the resources tab. If you run into any problems on your electronics adventure, don't forget to consult our Forum as we're Makers ourselves and happy to help. Good luck!

Have a question? Ask the Author of this guide today!

Please enter minimum 20 characters

Your comment will be posted (automatically) on our Support Forum which is publicly accessible. Don't enter private information, such as your phone number.

Expect a quick reply during business hours, many of us check-in over the weekend as well.

Comments


Loading...
Feedback

Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.