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

Programming the Start-Reset Indicator

The next example sketch tests the piezospeaker using calls to the Arduino’s tone function.  True to its name, this function send signals to speakers to make them play tones. 

There are two options for calling the tone function.  One allows you to specify the  pin  and frequency (pitch) of the tone.  The other allows you to  specify pin, frequency, and duration (in milliseconds).  We’ll be using the second option since we don’t need the tone to go on indefinitely. 

tone( pin , frequency)
tone(pin, frequency, duration)

This piezospeaker is designed to play 4.5 kHz tones for smoke alarms, but it can also play a variety of audible tones and usually sounds best in the 1 kHz to 3.5 kHz range.  The start-alert tone we’ll use is:

tone(4, 3000, 1000);
delay(1000);

That will make pin 4 send a series of high/low signals repeating at 3 kHz (3000 times per second).  The tone will last for 1000 ms, which is 1 second.  The tone function continues in the background while the sketch moves on to the next command.  We don’t want the servos to start moving until the tone is done playing, so the tone command is followed by delay(1000) to let the tone finish before the sketch can move on to servo control.

Frequency can be measured in hertz (Hz)  which is the number of times a signal repeats itself in one second.  The human ear is able to detect frequencies in a range from very low pitch (20 Hz) to very high pitch (20 kHz or 20,000 Hz).  One kilohertz is one-thousand-times-per-second, abbreviated 1 kHz. 


Printer-friendly version
Build the Piezospeaker Circuit
Prev
Example Sketch: StartResetIndicator
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

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

© 2025 Parallax Learn • Built with GeneratePress