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

Activity 1: Testing the Frequency Sweep

Here’s a graph from one specific brand of IR detector’s datasheet (Panasonic PNA4602M; a different brand may have been used in your kit). 

The graph shows that the IR detector is most sensitive at 38.5 kHz—its peak sensitivity —at the top of the curve.  Notice how quickly the curve drops on both sides of the peak.  This IR detector is much less sensitive to IR signals that flash on/off at frequencies other than 38 kHz.  It’s only half as sensitive to an IR LED flashing at 40 kHz as it would be to 38 kHz signals.  For an IR LED flashing at 42 kHz, the detector is only 20% as sensitive.  The further from 38 kHz an IR LED’s signal rate is, the closer the IR receiver has to be to an object to see that IR signal’s reflection.

The most sensitive frequency (38 kHz) will detect the objects that are the farthest away, while less-sensitive frequencies can only detect closer objects.  This makes rough distance detection rather simple:  pick some frequencies, then test them from most sensitive to least sensitive.  Try the most sensitive frequency first.  If an object is detected, check and see if the next-most sensitive frequency detects it.  Depending on which frequency makes the reflected infrared no longer visible to the IR detector, your sketch can infer a rough distance.

Frequency Sweep is the technique of testing a circuit’s output using a variety of input frequencies.

Programming Frequency Sweep for Distance Detection

The next diagram shows an example of how the BOE Shield-Bot can test for distance using frequency.  In this example, an object is in Zone 3.  That means that the object can be detected when 38000 and 39000 Hz is transmitted, but it cannot be detected with 40000, 41000, or 42000 Hz.  If you were to move the object into Zone 2, then the object would be detected when 38000, 39000, and 40000 Hz are transmitted, but not with 41000 or 42000 Hz.

The irDistance function from the next sketch performs distance measurement using the technique shown above.  Code in the main loop calls irDistance and passes it values for a pair of IR LED and receiver pins.  For example, the loop function uses int irLeft = irDistance(9, 10) to check distance to an object in the left side of the BOE Shield-Bot’s detection zone “field of vision.”

// IR distance measurement function

int irDistance(int irLedPin, int irReceivePin)
{  
  int distance = 0;
  for(long f = 38000; f <= 42000; f += 1000) {
    distance += irDetect(irLedPin, irReceivePin, f);
  }
  return distance;
}

The irDetect function returns a 1 if it doesn’t see an object, or a zero if it does.  The expression distance += irDetect(irLedPin, irReceivePin, f) counts the number of times the object is not detected.  After the for loop is done, that distance variable stores the number of times the IR detector did not see an object.  The more times it doesn’t see an object, the further away it must be.  So, the distance value the function returns represents the zone number in the drawing above.

 


Printer-friendly version
Chapter 8. Robot Control with Distance Detection
Prev
Displaying Both Distances
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

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

© 2025 Parallax Learn • Built with GeneratePress