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 Remote Control ActivityBot with Blockly

IR Remote Control ActivityBot with Blockly

Add Obstacle Detection

Your Turn: Add Obstacle Detection Override

Right now, you can drive your ActivityBot right into an obstacle. But, if you already have the Ping))) Ultrasonic Distance Sensor or the whisker switches on board, you can program your ActivityBot for a little self-preservation!

The key is making the existing remote control loop conditional.  That will let the remote control code run as long as no obstacle is detected. Placing this conditional loop inside of a repeat forever loop, and adding code for what to do If an obstacle is detected, is all it takes for the ActivityBot to defend itself!

Adding Code for Whisker Switches & Piezospeaker

  • If your ActivityBot does not have a built and tested piezospeaker circuit, add it now.
  • If your ActivityBot does not have built and tested whisker switches, add them now.
  • Start with your original IR Remote Drive code, and save a copy as IR Remote Drive with Whiskers.
  • Change the repeat forever loop into a repeat while loop with the block’s dropdown menu.
  • As shown below, attach the following condition to repeat while: ((check PIN 7 + check PIN 8) = 2). Remember, the whisker switches are active-low. So, as long as their states add up to 2, neither one is being pressed and so the ActivityBot has not hit an obstacle.

  • Place the repeat while loop into a repeat forever loop, as shown above.
  • At the bottom of the repeat forever loop, just after the repeat while loop, add the code shown below. It will make the ActivityBot stop, drive backward, play a beep for 600 ms, then stop again. This code will only be used if the repeat while condition does not equal 2 meaning one or both whiskers are pressed.

  • Save the project and load it into your ActivityBot’s EEPROM.
  • Take it for a test drive, and try to make the ActivityBot drive into a wall. It should automatically beep and back up, even if you hold the button down to make it drive forward.

 

Adding Code for PING))) Sensor & Piezospeaker

  • If your ActivityBot does not have a built and tested piezospeaker circuit, add it now.
  • If your ActivityBot does not have a built and tested PING))) Ultrasonic Distance Sensor circuit, add it now.
  • Start with your original IR Remote Drive code, and save a copy as IR Remote Drive with Ping.
  • Change the repeat forever loop into a repeat while loop with the block’s dropdown menu.
  • As shown below, attach the following condition to repeat while: (Ping))) distance in cm > 15). So, this loop will only execute if the ActivityBot is more than 15 cm away from a detectable object.

  • Place this repeat while loop into a repeat forever loop, as shown above.
  • At the bottom of the repeat forever loop, just after the repeat while loop, add the code shonw below. At will make the ActivityBot stop, drive backward, play a beep for 600 ms, then stop again. This code will only be used if the condition (Ping))) distance in cm > 15) is no longer true, meaning the ActivityBot has come within 15 cm of an object. (Yes, these are the same blocks that the Whisker Switches used above.)

  • Save the project and load it into your ActivityBot’s EEPROM.
  • Take it for a test drive, and try to make the ActivityBot drive into a wall. It should automatically beep and back up, even if you hold the button down to make it drive forward.

 


Printer-friendly version
Remote Driving Code
Prev

DISCUSSION FORUMS | PARALLAX INC. STORE

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

© 2026 Parallax Learn • Built with GeneratePress