2

Hila Research Centre

Computer Engineering

Light Detector

      Using some inexpensive components it is possible to use your computer to detect light. Why, you ask, would you want to detect light with your computer? Combining some clever programming with light detection you can create a burglar detector, a race timer or an event counter.

       We will use the joystick port and Qbasic to create our basic light beam detector. If you are not familiar with the joystick port or Qbasic, go to http://fox.nstn.ca/~hila and click on projects.

Detecting light.

        In our first part of this program we learned that the joystick port works by detecting changes in resistance. To learn more about resistance check out the Electronics 1 page in the projects menu. A photocell is a device that changes resistance with the amount of light falling on it. We will use a cadmium sulfide photocell (Radio Shack #276-116).

Connect the photocell to your joystick port with one lead to pin 1 the other lead to pin 3. Conncting from pin 1 to pin 3 allows us to read a resistance value using the Qbasic command STICK(0).

See diagram in Computer Engineering 1 for pin numbers on joystick port.

Enter this Qbasic program then run it. Note the last line, this allows the user to break out of a DO-LOOP by pressing any key. Use "help" in Qbasic to learn more about "WHILE" and "INKEY$".

        The value of the numbers you see scrolling up the screen are being controlled by the resistance of the photocell. Block the light falling on the photocell and watch the numbers change.

        Let some light fall on the photocell and note the number that is now appearing on the screen - suppose it is 80 (your number will be different, use it where I use 80 in this program).

Enter this code in Qbasic:

  • CLS
  • SCREEN 9
  • DO
  •            a = STICK (0)
  •            PRINT a
  •            IF a > 80 THEN COLOR 2,4
  •            IF a < 80 THEN COLOR 4,2
  •            
  • LOOP WHILE INKEY$ = ""
  •          Block the light falling on the photocell. This program changes the colour of the computer screen depending on the amount of light falling on the photocell. Be sure to use the proper number - 80 was just an estimate.

    Return to projects menu