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

How the volts Function Works

The micro:bit module’s A/D0, A/D1, and A/D2 sockets are connected to its Nordic chip’s pins that are configured for analog to digital conversion.  Analog to digital conversion, called “A to D” and abbreviated A/D, is how microcontrollers measure voltage. The microcontroller splits a voltage range into many numbered, equal divisions, with each number representing a voltage level. More divisions provide a higher resolution, with more precise voltage measurements.

Each of the micro:bit module’s analog inputs has a 10-bit resolution, meaning that it uses 10 binary digits to describe its voltage measurement.  With 10 binary digits, you can count from 0 to 1023; that’s a total of 1024 voltage levels if you include zero.

By default, the cyber:bot’s read_analog function is configured to use the 0…1023 values to describe where a voltage measurement falls in a 3.3 V scale.  If you split 3.3 V into 1024 different levels, each level is 3.3/1024ths of a volt apart.  3.3/1024ths of a volt is approximately 0.00322266 V, or about 3.22 thousandths of a volt.  So, to convert a value returned by read_analog to a voltmeter-style value, all the volts function has to do is multiply by 3.3 and divide by 1024.

Example: The read_analog function returns 742; how many volts is that?
Answer:
V = 742 x 3.3 V / 1024
= 2.39121094 V
= 2.39 V

The previous scripts have been storing the read_analog function values as the variable ad2.  This variable is stored as an integer since it returns the values between 0 and 1023.  It is then multiplied by 3.3 and divided by 1024 to get the voltage value (just like we converted 742), and this is being stored as the float variable volts.

    ad2 = pin2.read_analog()
    volts = ad2 * (3.3/1024)

The script phototransistor_voltage displays the value returned by volts with the display.scroll function.

The script halt_under_shadow script uses that value to bring the cyber:bot to a stop when it detects a shadow (if volts < 0.1).

Binary vs. Analog and Digital

A binary sensor can transmit two different states, typically to indicate the presence or absence of something.  For example, a whisker sends a high signal if it is not pressed, or a low signal if it is pressed.

An analog sensor sends a continuous range of values that correspond to a continuous range of measurements.  The phototransistor circuits in this activity are examples of analog sensors. They provide continuous ranges of values that correspond to continuous ranges of light levels.

A digital value is a number expressed by digits.  Computers and microcontrollers store analog measurements as digital values.  The process of measuring an analog sensor and storing that measurement as a digital value is called analog to digital conversion.  The measurement is called a digitized measurement.  Analog to digital conversion documents will also call them quantized measurements.

 


Printer-friendly version
Park in the Dark
Prev
How the Phototransistor Circuit 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