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°

Build the Light Sensor Circuits

Now, it’s time to build and test two phototransistor circuits to give your ActivityBot phototransistor “eyes.” Leave the piezo speaker circuit in place.

Parts

  • (2) Phototransistor (#350-00029)
  • (2) 0.01 µF capacitor (labeled 103)
  • (2) 220 ohm resistor (red-red-brown)

 

Build the Light Sensor Circuits

As you build the circuit shown below:

  • Make sure the phototransistor’s shorter leads and flat spots are connected to ground, as shown in the wiring diagram below.
  • Use the 0.01 µF capacitors, labeled “103.” The capacitors in your ActivityBot kit are not polar; it does not matter which way you plug them in.
  • Point the phototransistors upwards and outwards, about 90° from each other, and about 45° from vertical.

 

Test the Light Sensor Circuits

This test will display raw light sensor readings in the SimpleIDE Terminal. You will need a flashlight or lamp that is brighter than the overall light level in the room.

The phototransistor circuits are designed to work well indoors, with fluorescent or incandescent lighting.  Make sure to avoid direct sunlight and direct halogen lights; they would flood the phototransistors with too much infrared light. 

  • In your robotics area, close window blinds to block direct sunlight, and point any halogen lamps upward so that the light is reflected off the ceiling.
  • Click SimpleIDE’s Open Project button.
  • Open Test Light Sensors.side from …DocumentsSimpleIDELearnExamplesRobotsActivityBot360.
  • Put the power switch in Position 1.
  • Click the Run with Terminal button.
  • Hold your hand over one phototransistor, and then the other, while watching the values change.

The values shown above were taken in a room with overhead fluorescent lighting. Notice how the lightRight measurement is larger – this was caused by cupping a hand over the right phototransistor.

Mismatched Measurements 
It is unlikely that your two phototransistor measurements will match exactly. Each individual sensor will vary slightly as a natural part of the manufacturing process, and the brightness levels are rarely precisely even in any environment However, if one gives a measurement about 100 times larger than the other when exposed to the same level of light, that phototransistor is probably in backwards. Check your circuit and try again.

 

How it Works

This simple program starts by declaring two int variables, lightLeft and lightRight,  to hold values returned by the left and right phototransistor circuits.

The action happens inside a while(1) loop, which takes two light sensor measurements and displays the results over and over again. 

Recall from the Sense Light tutorial that phototransistor measurement is a two-step process. First, high(9) connects the phototransistor circuit to 3.3 V, allowing the capacitor in the circuit to charge up like a tiny battery. It only takes a moment to do that; pause(1) allows enough time. Immediately after charging the circuit, the next line of code calls the rc_time function to take a measurement at I/O pin 9 and store the result in lightLeft.  The same steps are taken to store a sensor measurement in lightRight.

After that, the print statement prints the name of each variable followed by its value in decimal.  The control character HOME returns the cursor to the upper left corner of the SimpleIDE terminal each time, and CLREOL clears out any characters left over from the previous measurement.

/*
  Test Light Sensors.c
*/

#include "simpletools.h"

int lightLeft, lightRight;

int main()                    
{
  while(1)
  {
    high(9);
    pause(1);
    lightLeft = rc_time(9, 1);
    
    high(5);
    pause(1);
    lightRight = rc_time(5, 1);

    print("%clightLeft = %d, lightRight = %d%c",
           HOME, lightLeft, lightRight, CLREOL);
    pause(250);
  }
}

 


Did you Know?

Light travels in waves so small that the distance between adjacent peaks is measured in nanometers (nm), which are billionths of meters.  The figure below shows the wavelengths for colors of light we are familiar with, along with some the human eye cannot detect, such as ultraviolet and infrared.  The phototransistor in your ActivityBot kit detects visible light, but is most sensitive to 850 nm wavelengths, which is in the infrared range.


Your Turn

Just for fun, let’s see if the phototransistor can detect different colors.

  • Zoom in on the color wavelenghth graph above.
  • Re-run Test Light Sensors.side.
  • Hold your robot up to the screen, placing one phototransistor very close to the color bar.
  • What color gives the highest reading? What colors give the lowest? 

From your observation, do you think a clear phototransistor alone, like this one, could be used as a color sensor? Why or why not?


Printer-friendly version
Meet the Photoransistor
Prev
Using the Measurements
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

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

© 2025 Parallax Learn • Built with GeneratePress