Skip to content
Parallax Learn

Parallax Learn

  • Welcome
  • Tutorials
        • Tutorial Series head tag

          Tutorial Series
        • Tutorial Series

          The special, classroom-ready series pages are organized collections of tutorials for our most popular hardware and/or languages. The tutorials for each topic are conveniently accessible from a single page, shown in the order it is recommended that they be completed.
        • Robotics Series Head tag

          Robotics Series
        • Robotics Series

          • Artificial Intelligence
          • Cybersecurity: Radio Data tutorialCybersecurity
          • cyber:bot + Python
          • cyber:bot + MakeCode
          • Boe-Bot Tutorial SeriesBoe-Bot
          • Arduino Shield-Bot
          • ActivityBot with C TutorialsActivityBot + C
          • ActivityBot with BlocklyProp Tutorial SeriesActivityBot + BlocklyProp
          • Scribbler 3 Tutorial SeriesScribbler 3
        • Electronics & Programming Series Head tag

          Electronics & Programming Series
          • BS2 Board of Education Tutorial SeriesBS2 Board of Education
          • Propeller C-Language BasicsPropeller C Basics
          • FLiP Try-It Kit C Tutorial SeriesFLiP Try-It Kit + C
          • FLiP Try-It Kit BlocklyProp TutorialsFLiP Try-It Kit + BlocklyProp
          • Badge WX Tutorial SeriesBadge WX
          • Propeller BlocklyProp Basics and ProjectsPropeller BlocklyProp Basics
          • View All Tutorial Series »
        • Browse Tutorials
        • Browse Tutorials

          Individual tutorials sorted by robot or kit, and language.
        • By Robot or Kit
          • ActivityBot
          • SumoBot WX
          • Boe-Bot
          • Shield-Bot
          • cyber:bot
          • Badge WX
          • ELEV-8
          • ARLO
        • By Language
        • By Language

          • Propeller C
          • Arduino
          • BlocklyProp
          • PBASIC
          • Python
          • MakeCode
          • View All Tutorials »
  • Educators
  • Reference
  • Downloads
  • Home
  • All Courses
  • Robotics with the Board of Education Shield for Arduino

Robotics with the Board of Education Shield for Arduino

Chapter 2 Solutions

Question Solutions

  1. Plug the two leads into the same 5-socket row on the breadboard.
  2. The pinMode function. 
  3. The digitalWrite function does both, depending on its value parameter:
digitalWrite(13, HIGH) // 5 V
digitalWrite(13, LOW)  // 0 V
  1. Assuming a pin has just been set high, the delay call can keep it high for a certain amount of time.  Then, a digitalWrite call can set it low.
  2. (a)1.3 ms pulses for full speed clockwise, (b)1.7 ms pulses for full speed clockwise, and (c)1.5 ms pulses for stay still.
  3. (b) servoLeft.writeMicroseconds(1420).  Full speed clockwise is servoLeft.writeMicroseconds(1300), and stop is servoLeft.WriteMicroseconds(1500).  Since 1420 is further from stop and closer to full speed, it’s the correct value for faster clockwise rotation even though it is smaller.
  4. Servo.writeMicroseconds(value) followed by delay(ms) followed by Servo.writeMicroseconds(newValue) or Servo.detach(pin) will keep the servo turning for ms milliseconds.

Exercise Solutions

  1. The total on + off time has to be 200 ms, which is 1/5th of a second.  So, on for 50 ms, off for 150 ms:
void loop()                    // Main loop auto-repeats
{                              // 200 ms -> 5 blinks/second
  digitalWrite(13, HIGH);      // Pin 13 = 5 V, LED emits light
  delay(50);                   // ..for 0.05 seconds
  digitalWrite(13, LOW);       // Pin 13 = 0 V, LED no light
  delay(150);                  // ..for 0.15 seconds
}
  1. Set pin 13 servo to full speed clockwise and the pin 12 servo to stop.  Then, delay for 1200.  Since servoRight is already stopped, all the code has to do is stop servoLeft.
void setup()                   // Built in initialization block
{
  servoLeft.attach(13);        // Attach left signal to pin 13
  servoRight.attach(12);       // Attach right signal to pin 12

  servoLeft.writeMicroseconds(1300);  // 1.3 ms -> clockwise
  servoRight.writeMicroseconds(1500); // 1.5 ms -> stop
  delay(1200);                        // ..for 1.2 seconds
  servoLeft.writeMicroseconds(1500);  // 1.5 ms -> stop
}
  1. In this example, the pin 13 servo starts counterclockwise and the pin 12 servo starts out clockwise.  This goes on for 1.5 seconds.  Then, the pin 12 servo is changed to counterclockwise, and this goes on for another 1.5 seconds.  After that, both servos are stopped.
void setup()                   // Built in initialization block
{
  servoLeft.attach(13);        // Attach left signal to pin 13
  servoRight.attach(12);       // Attach right signal to pin 12

  servoLeft.writeMicroseconds(1700);  // 1.7 ms -> cc-wise
  servoRight.writeMicroseconds(1300); // 1.3 ms -> clockwise
  delay(1500);                        // ..for 1.5 seconds
  servoRight.writeMicroseconds(1700); // 1.7 ms -> cc-wise
  delay(1500);
  servoLeft.writeMicroseconds(1500);  // 1.5 ms -> stop
  servoRight.writeMicroseconds(1500); // 1.5 ms -> stop
}

Project Solutions

  1. The detach function detaches the instance of Servo from its pin.  This sketch verifies that it stops the servo after 3 seconds of run time.  The chapter examples sent pulses telling the servo to stay still.  In contrast, detach stops sending signals to the servo—the pin doesn’t tell the servo to do anything, so it goes dormant instead of holding the “stop speed.”  The end result is the same, the servo motor stops.  The advantage to detach is that it prevents the servos from turning slowly if the servo is not precisely calibrated.
/*
 Robotics with the BOE Shield – Chapter 2, Project 1
 Generate a servo full speed counterclockwise signal with pin 13 and
 full speed clockwise signal with pin 12.
 */

#include <Servo.h>                    // Include servo library
 
Servo servoLeft;                      // Declare left servo signal
Servo servoRight;                     // Declare right servo signal

void setup()                          // Built in initialization block
{
  servoLeft.attach(13);               // Attach left signal to pin 13
  servoRight.attach(12);              // Attach right signal to pin 12

  servoLeft.writeMicroseconds(1700);  // Pin 13 counterclockwise
  servoRight.writeMicroseconds(1300); // Pin 12 clockwise
  delay(3000);                        // ..for 3 seconds
  servoLeft.detach();                 // Stop servo signal to pin 13
  servoRight.detach();                // Stop servo signal to pin 12
}  
 
void loop()                           // Main loop auto-repeats
{                                     // Empty, nothing needs repeating
}
  1. Solution is the sketch ForwardLeftRightBackward, from a later chapter.

Printer-friendly version
Chapter 2 Challenges
Prev
Chapter 3. Assemble and Test your BOE Shield-Bot
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

About | Terms of Use | Feedback: learn@parallax.com | Copyright©Parallax Inc. 2024

© 2025 Parallax Learn • Built with GeneratePress