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

Example Sketch: Test Servo Speed

With this sketch, you can check servo RPM speed (and direction) for pulse values from 1375 µs to 1625 µs in steps of 25 μs.  These speed measurements will help make it clear how servo control pulse durations in the 1400 to 1600 µs range control servo speed.  This sketch starts by displaying the pulse duration that it’s ready to send as a servo control signal.  Then, it waits for you to send the Arduino a character with the Serial Monitor before it runs the servo.  It runs the servo for six seconds, and during that time you can count the number of full turns the wheel makes.  After that, the for loop repeats itself, and increases the pulse duration by 25 for the next test.

  • Place a mark (like a piece of masking tape) on the wheel so that you can see how revolutions it turns during the wheel speed tests. 
  • Set the BOE Shield-Bot on its nose so that the wheels can spin freely.
  • Enter, save and upload TestServoSpeed to the Arduino.
  • Open the Serial Monitor, and set the drop-down menus to “No line ending” and “9600 baud.”
  • Click the transmit pane at the top, type any character, and click the Send button.
  • Count the number of turns the wheel makes, and multiply by 10 for RPMs.  (Don’t forget to make a note of direction; it will change after the 5th test.)
  • If you were to add your data points to the graph, would they fit the overall shape?

/*
 Robotics with the BOE Shield – TestServoSpeed
 Send a character from the Serial Monitor to the Arduino to make it run the
 left servo for 6 seconds.  Starts with 1375 us pulses and increases by
 25 us with each repetition, up to 1625 us.  This sketch is useful for
 graphing speed vs. pulse width.
 */

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

void setup()                                 // Built in initialization block
{
  tone(4, 3000, 1000);                       // Play tone for 1 second
  delay(1000);                               // Delay to finish tone
 
  Serial.begin(9600);                        // Set data rate to 9600 bps
  servoLeft.attach(13);                      // Attach left signal to P13
}  
 
void loop()                                  // Main loop auto-repeats
{

  // Loop counts with pulseWidth from 1375 to 1625 in increments of 25.

  for(int pulseWidth = 1375; pulseWidth <= 1625; pulseWidth += 25)
  {
    Serial.print("pulseWidth = ");           // Display pulseWidth value
    Serial.println(pulseWidth);
    Serial.println("Press a key and click"); // User prompt
    Serial.println("Send to start servo...");

    while(Serial.available() == 0);          // Wait for character
    Serial.read();                           // Clear character

    Serial.println("Running...");
    servoLeft.writeMicroseconds(pulseWidth); // Pin 13 servo speed = pulse
    delay(6000);                             // ..for 6 seconds
    servoLeft.writeMicroseconds(1500);       // Pin 13 servo speed = stop
  }
}

Printer-friendly version
Activity 4: Test Speed Control
Prev
How TestServoSpeed Works
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

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

© 2025 Parallax Learn • Built with GeneratePress