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
  • Propeller C Programming with the ActivityBot 360°

Propeller C Programming with the ActivityBot 360°

Inside the Whisker Circuit (Optional)

Let’s take a look at the right whisker and see what happens when it is not pressed, and then pressed. 

When it’s not pressed the whisker does not touch the 3-pin header on the breadboard, so there is no electrical contact between the two.  Because of that, the 10 kΩ resistor that’s connected to the 3.3 V socket above the breadboard applies 3.3 V to the breadboard row with the 3-pin header post.  The 220 Ω resistor that connects that row to P8 applies the 3.3 V to P8.

The whisker is like a normally open switch.  In the schematic, P8 detects 3.3 V through the 220 Ω and 10 kΩ resistors.  Whenever a circuit applies 3.3 V (or anything over 1.65 V) to P8, input(8) returns 1.  That’s why wR = input(8) copied the value of 1 to the wR variable (and you saw it displayed in the SimpleIDE Terminal).

Why 3.3 V at P8?  In case you’re wondering why the voltage at P8 is the same as the voltage above the 10 kΩ resistor, here’s what’s going on:

First of all, the schematic shows an open switch with the “Not pressed” label.  That open switch is the whisker, which is not in contact with the 3-pin header, and it keeps ground (GND = 0 V) out of the circuit.  So, all we have is 3.3 V on one end of a pair of resistors, and P8 on the other end.  Since P8 is set to input, it looks invisible to the circuit.  As far as the circuit’s concerned, the right side of that 220 Ω resistor might as well be disconnected from everything and sticking up in the air.  When only one voltage is applied to a resistor, or even a chain of resistors, that same voltage will appear at the other end as well.  So, P8 as an input is invisible to the circuit, but it can detect the voltage the circuit applies to it.  In this case, that voltage is 3.3 V, which causes the Propeller to store 1 in its P8 input register, and so input(8) returns the value 1.

When the right whisker is pressed because the robot has bumped into an obstacle, then the right whisker makes contact with the front post on the 3-pin header.  The whisker is electrically connected to that plated hole on the corner of the board, which eventually makes its way to the battery’s negative terminal.  That negative terminal is commonly called ground, and has a value of 0 V.  Since the whisker touches that 3-pin header post, it connects that row to ground, so P8 sees 0 V through the 220 Ω resistor.

Take a look at this schematic.  It shows how the whisker connects that node where the 10 kΩ and 220 Ω resistors meet to ground (0 V).  …and that’s what P8 detects.  As a result, a call to input(8) returns zero.  That zero value gets copied to wR with wR = input(8), and that’s what gets displayed by the Parallax Terminal Window when the whisker is pressed.

Why 0 V at P8?  Now that the whisker is pressed, the schematic above shows 0 V applied to P8.  That’s because pushing the whisker up against the post connects GND (0 V) to the node where the 10 kΩ and 220 Ω resistors meet.  Now, instead of 3.3 V, the circuit applies 0 V to P8.  Reason being, 0 V is being applied to the left side of the 220 Ω resistor, and the circuit still thinks the right side of that resistor is floating in the air.  So, the rule for a high impedance input still applies, and the voltage that’s on the right side of the 220 Ω resistor will be the same as the voltage applied to its left side.

Now that there’s 3.3 V on one end of the the 10 kΩ resistor and 0 V on the other end, it applies electrical pressure that causes current to flow through that resistor.  You can use the Ohm’s Law equation of V = I x R to figure it out.  This equation says the voltage (V) difference at two ends of a resistor is equal to the current (I) pasing through it multiplied by the resistor’s resistance (R).  With a little algebra, we have I = V ÷ R = 3.3 V ÷ 10,000 Ω ≈ 0.00033 A.  That’s 0.00033 A, or in terms of milliamps, 0.33 mA, a very small amount of current, especially compared about 140 mA, which is what the servos need to make the Propeller ActivityBot move.

The 10 kΩ resistor is called a pull-up resistor.  It pulls the voltage at P8 up to 3.3 V when the whisker is not pressed.  It’s important to have either a pull-up or pull-down resistors in switch circuits.  A pull-up or pull-down resistor applies a voltage that’s opposite of the voltage the I/O pin will detect when the switch/button contact is made.  Without it, the I/O pin will allow nearby electric fields to affect whether it reports 1 or 0 to the input function.  For example, without that pull-up/pull-down resistor, simply putting your hand near the 220 Ω resistor might change the value the input function reports.

 


Printer-friendly version
Test the Whiskers
Prev
Add Whisker Indicator Lights
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

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

© 2025 Parallax Learn • Built with GeneratePress