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
  • IR SumoBot WX Opponent Detection and Tracking

IR SumoBot WX Opponent Detection and Tracking

How the Tests Work

If humans could see infrared as red, it might look like the image below.  The SumoBot on the left shines both of its IR lights.  The lower beam misses the opponent SumoBot, and just keeps going.  In this case, the IR receiver sends a high signal to the Propeller microcontroller’s P6 I/O pin because it does not detect any infrared.  The upper beam bounces off the corner of the opponent SumoBot, and some of the reflected infrared light reaches the IR receiver connected to P5.  That IR receiver sends P5 a low signal indicating it detected infrared light.
 

Let’s take a look at the SumoBot-Front-IR-Terminal code blocks.

The main loop just repeatedly calls two functions with run function blocks.  First, it calls “IR Front” to measure the distances, and then “IR Front Terminal” to display those distances.

The program contains all the functions you have created up until now as well as a few new ones.  For example, QTIs front Turn from Border is new, and if you look inside, you’ll see the switch…case statement you created to avoid the border in Navigate with QTIs -Avoid the Border.  The IR Front function is also new, and it does the IR measurement work.  

  • Right-click the function IR Front block, and select Expand block.

When you expand the IR front block, it should look like this.  

The IR front block uses frequency PIN 5 duration (ms) 1 frequency (Hz) 38000 to make the IR LED flicker on/off at 38,000 Hz (times per second).  This is what the IR receiver requires to detect the reflected infrared.  Other sources of infrared, like lamps and sunlight, do not tend to flicker at 38,000 Hz—they’re usually emitting infrared at some constant level instead of flickering.  This consistent, rapid on/off behavior makes it possible for the IR receivers in devices to detect the signal from an IR remote by only detecting infrared that flickers at 38,000 Hz.

Immediately after making the IR LED flicker for 1 ms, the program uses irLF = irLF + check PIN 1 to check the IR receiver’s output and keep a tally of how many times the object was not detected.  In the case of not detected, the IR receiver’s output stays high, and check PIN returns a binary 1.  If reflected IR is detected, the IR receiver’s output sends a low signal, and check PIN returns a binary 0.  

The process for both IR LEDs and receivers is repeated in a loop that counts from 0 to 140 in steps of 20.  The user defined code uses the da variable to set the voltage at all the IR LED’s cathodes.  By increasing this voltage, it makes the IR LED dimmer each time through the loop, which in turn makes the IR sensor more nearsighted.  By counting the number of times check PIN returns 1 (did not detect an object), it arrives at a number that indicates the relative distance.  

When the object is up close, every time through the loop, check PIN returns 0 because no matter how nearsighted it gets, the reflection is still detected.  When the object is out of range, check PIN returns 1 each time since it did not detect the flickering infrared reflected off any objects.  All those 1 values are added up with the irLF = irLF + check PIN… operation, for a result of 8.  

 


Printer-friendly version
Terminal IR Distance Measurements Tests
Prev
Detect and Charge at an Opponent
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

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

© 2025 Parallax Learn • Built with GeneratePress