ENGR 2110 - Principles of Engineering

Profs. Millner, Faas, Minch, & Reifel

Fall 2018

Lab 3 - Due before class Fri., 10/12

Lab 3 - DC Motor Control


  1. Integrate sensing and control with a standard two-wheeled, mechanical robotic platform
  2. Write a closed-loop controller that runs on your Arduino and enables your robot to follow a track consisting of electrical tape laid out on the floor in a loop.
  3. Tune your controller to enable your robot to complete a lap around the course as quickly as possible.


In completing the first and second labs, you have developed an understanding of how to output digital signals, read analog inputs, and use the combination to act on and measure the physical world.

The purpose of this lab is to integrate your ability to sense the physical world through sensors connected to the microcontroller with your ability to act on the physical world through actuators (direct current, or DC, motors in this case).

Fig. 1 - A standard robot chassis that you must integrate with.

In this lab you will use a standard robot chassis platform to create a line-following robot with your Arduino, a motor shield (and accompanying Arduino Library with documentation), and two infrared reflectance sensors. You may not permanently physically modify any of the chassis in any way (this includes drilling, cutting, and gluing - as they will be reused).

You must design the physical integration of your electronics to accommodate the existing features of the chassis, and you must be able to remove your electronics reasonably quickly. You may find this Solidworks model of the acrylic plate portion of the chassis (there is also an alternative model for folks who might have one of the newer chassis) helpful for designing your mechanical attachment.

Fig. 2 - The Adafruit Motor Shield v2

You will use the IR sensors to detect the presence or absence of the tape line on the ground, and your controller logic will use that information to compute the signals that must be sent to the motors to enable the robot to follow that line. The IR sensor consists of an infrared light emitting diode and a phototransistor. The more IR light that is reflected back to the phototransistor, the closer Vout will be to zero. A sample schematic showing how to connect a sensor to your arduino is shown in Figure 4. You will use the reflectance reported by your sensors as signals around which to design a feedback loop that ensures your motors will keep your robot following the tape line.  

Fig. 3 - Your IR reflectance sensor


Figure 4: A circuit for connecting your IR reflectance sensors

A really helpful resource for understanding how to design and implement feedback control is the excellent article from Embedded Systems Programming magazine entitled PID Without a PhD. You may also find the “Implementation” section of the PID chapter in  Astrom and Murray’s excellent book, Feedback Systems: An Introduction for Scientists and Engineers useful. Though it may enhance the performance of your robot, you are not required to use PID feedback control. Any simple, closed-loop control scheme that accomplishes the task of completing the track is acceptable.

Lastly, you must be able to update the behavior of your control code via the serial connection without restarting the Arduino or recompiling/reloading code.


  1. Design and build a removable attachment method for integrating your electronics with the wheeled robotic platform. You may not modify the platform in any way that persists after you remove your electronics. Write a controller that uses the optical reflectivity sensors provided to guide your robotic platform along the “track.”

  1. Integrate the Adafruit motor shield with the wheeled platform to drive two DC motors independently. Using two IR reflectivity sensors, implement a controller that enables your robot to follow a black tape line around a loop as fast as possible.

  1. Create an interface to your Arduino code that allows you to change the behavior of your controller from your laptop (via the serial connection) without recompiling or reloading your Arduino code.

You will receive a wiring harness that attaches to a barrel jack to screw terminal adapter (Figure 5) on your Arduino and the screw terminals on your motor shield. At the other end will be a four pin, wire-to-wire Molex connector shown below. You may also find it helpful to watch this video to see how NINJAs made the cables you received.

Figure 5 - Barrel jack to screw terminal power adapter. 

Figure 6 - Molex Ditto genderless connector 

Suggested Steps if you need to replace the cable (with NINJA guidance)

  1. Create a wiring harness that goes from the screw terminals on your barrel jack adapter and the screw terminals on your motor shield to a 4 pin Molex connector. (There will be four wires in total). Consider watching this Molex connector crimping video.
  2. Make sure to remove the power jumper (if it’s not already removed) from your motor shield to prevent your shield from trying to take power from the Arduino’s USB connection.
  3. Design a circuit for integrating your two IR tape sensors. Refer to Figure 4 for assistance.
  4. Understand your reflectance IR sensors. Can you reliably detect the difference between tape and the floor? What about on different surfaces? Can you visualize the output of the sensor as it transitions over tape and back?
  5. Calibrate and test your IR sensor with the tape provided on different surfaces.
  6. Design and build some means of affixing your electronics and sensors to the robot chassis keeping in mind that you are forbidden to permanently modify the chassis in any way.
  7. Test movement of your motors in both directions using your motor shield. You can use Adafruit’s example motor control code.
  8. Develop a control loop that uses the input from the sensors to determine how to control the motors in order to keep the robot chassis centered over the tape while the robot drives forward.
  9. Using your serial interface, tune your control loop and motor speed settings to get your robot to traverse the tape course as quickly as possible.

Bill of Materials (BOM):

Please complete the Lab 3 Hardware Inventory spreadsheet so that we may track and recover the hardware used in the lab for future offerings of the class.

Lab Report

Your lab report should include the following elements:

  1. A description of the process you used to test and calibrate your IR sensor
  2. A CAD model, image, or sketch and description of your system for doing mechanical integration with the chassis.
  3. A description of how your controller works
  4. 1 plot superimposing sensor data from both your IR sensors and commanded motor speeds (generated by your controller) for a short trial run.
  5. A link to a video of your successful completion of the track
  6. All source code

Please submit your reports as pdf attachments to poe.submit@gmail.com and read the Lab Report Style Guide carefully before writing your lab report.