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
  • Visible Light Navigation for the cyber:bot

Visible Light Navigation for the cyber:bot

Park in the Dark

The script halt_under_shadow  will make the cyber:bot go forward until the phototransistor detects a shadow that’s dark enough to make the voltage applied to D/A2 drop below 0.1 V, or a different threshold you choose.

  • Use the micro:bit Python Editor to open a script that already has the cyber:bot module, like phototransistor_voltage or cyberbot-template-with-blink.
  • Set the project’s name to halt_under_shadow, and enter the script below over the existing script.
  • Using the measurements you just took with the script phototransistor_voltage, update the threshold value 0.1 in if volts < 0.1 with a value consistent with “shade” in your ambient lighting.
  • Click Save, and then click Send to micrso:bit.   
#halt_under_shadow

from cyberbot import *

bot(18).servo_speed(75)
bot(19).servo_speed(-75)

while True:
    ad2 = pin2.read_analog()
    volts = ad2 * (3.3/1024)
    
    if volts < 0.1:               # Update voltage threshold value here           
        bot(18).servo_speed(None)
        bot(19).servo_speed(None)
  • Place your cyber:bot on the floor in ambient light, pointing straight towards the cardboard box “garage” or other dark spot.
  • Set the cyber:bot board’s PWR switch to 2 so the cyber:bot will drive forward.  How close did it get to stopping directly in the box-garage?
  • If needed, try making adjustments to the threshold you set in the if volts <… statement to get the cyber:bot to stop directly the box-garage.

 


Printer-friendly version
Measuring Phototransistor Voltage
Prev
How the volts Function 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