The field of computer engineering is at the interface between hardware and software and seeks to balance the tension between application requirements and technology constraints. In an earlier lab session, students already became familiar with basic electrical circuits and explored the field of computer engineering from the hardware perspective by building a basic digital adder. In this lab session, students worked in groups of two to explore the field of computer engineering from a software perspective by incrementally building a mobile robot control application using the popular Arduino micro-controller. For detailed information about the lab see the following lab notes and handout. The lab notes review background information while the lab handout was used by students during the lab session.

Lab Overview

Students started by compiling and running a basic Arduino program that simply adds two numbers together. By examining the compiled assembly code, students were able to see first-hand how high-level programming language constructs (e.g., +) are turned into low-level machine instructions (e.g., add instruction). Students then experimented with the light-emitting diodes (LEDs), switches, and potentiometers included as part of the mobile robotic platform, before testing the grayscale analog sensor and drive motors. Once students had a good feel for the basic sensors and actuators on the robot, they incrementally developed the full mobile robot control application in three steps: (1) develop a move-and-stop behavior; (2) develop wander behavior; and (3) develop a wander-to-target behavior.

The following two photos show students working on the lab. The left photo shows two students beginning to program their robot using the Arduino development environment. The right photo shows several groups testing their robots on the playing fields.

Lab Hardware

To support the lab, we developed an Arduino-based mobile robotic platform using the DFRobot Turtle 2WD chasis, official Arduino motor controller shield, and the Maker Shed MakerShield Kit. We also added two mechanical bump switches and an infrared range finder for obstacle avoidance. Finally, we added an analog grayscale sensor to the bottom of the robot for detecting the target. We also built custom U-shaped playing fields measuring approximately 4'x3', with extra movable obstacles for advanced students.

Lab Software

We provided scholars with a simple template defining the appropriate pin numbers and setup code. Scholars were responsible for writing the loop function to implement their mobile robot control application. The following code illustrates a simple solution to the lab which causes the robot to wander the playing field, avoid obstacles, and spin when it finds the target.

void loop()
  // Read mechanical bump sensors

  int bumped_left  = digitalRead( pin_bump_left );
  int bumped_right = digitalRead( pin_bump_right );

  // If robot has bumped into an obstacle, then backup and rotate

  if ( bumped_left or bumped_right ) {

    // Make robot go backwards
    digitalWrite( pin_motor_left_dir,  HIGH  );
    digitalWrite( pin_motor_right_dir, HIGH  );

    // Make robot rotate
    digitalWrite( pin_motor_left_dir,  LOW  );
    digitalWrite( pin_motor_right_dir, HIGH );


  // Read analog grayscale sensor

  int light = analogRead( pin_grayscale_sensor );

  // If robot is over the target, then spin and stop

  if ( light > 300 ) {

    // Make robot spin
    digitalWrite( pin_motor_left_dir,  LOW  );
    digitalWrite( pin_motor_right_dir, HIGH );

    // Make robot stop forever
    analogWrite( pin_motor_left_speed,  0 );
    analogWrite( pin_motor_right_speed, 0 );
    while (1);


  // Make robot move forward

  digitalWrite( pin_motor_left_dir,  LOW  );
  digitalWrite( pin_motor_right_dir, LOW  );
  analogWrite( pin_motor_left_speed,  100 );
  analogWrite( pin_motor_right_speed, 100 );