Home Chapter 7 BS2 Turning an LED off and On
BS2 Turning an LED off and On


Now it’s your turn.

Enter the program below.

      ' {$STAMP BS2} ‘A directive to the Stamp that you are Using the Basic Stamp 2
      ' {$PBASIC 2.5}

      Top: 'This is a label that allows you TO refer TO this label later ON in the ‘program.
      HIGH 0 'Set PIN one TO logic HIGH 5 volts
      PAUSE 1500 'PAUSE the program FOR 1 & 1/2 seconds
      LOW 0 'Set the PIN 0 TO LOW OR logic LOW 0 volts.
      PAUSE 1500 'PAUSE program FOR 1 & 1/2 seconds
      GOTO Top 'RETURN TO the label “Top:”



  1. Hit RUN in the program editor, and watch your LED flash. Notice that you can also use the quick key Ctrl+R.



  3. If the LED is flashing, skip to the section called “Modifying Your Code”.
    1. Check that your Stamp power is on.
    2. Check that your Stamp board is plugged both to the Board of Education and to the wall.
    3. Check that the output pin you are connected to is pin 0.
    4. Check that you have not accidentally used the letter “o” instead of 0 in your code thought the Stamp editor may have already caught this.
    5. Check the LED to make sure that the cathode and anode are in the correct orientation.
    6. Push down on all wires to make sure your connections into the breadboard are solid.
    7. If the circuit still does not work, try another LED, as perhaps the one you are using is damaged.
    8. Vary the pause cycle after HIGH 0 and LOW 0 in a few different ways and watch what happens.
    9. How does this change the program? _________________________
    10. Can you make the LED seem to glow less bright by decreasing the length of the pause? _____________________________


    If your LED is not flashing you must debug. Debugging is the process of trying to find what is wrong with the circuit, and this process is going to be another necessary skill for you to learn and master in order to enjoy working with electromechanical systems. Debugging is a method of being methodical in trying to discover why something does not work, as you would expect it to.

    This process is very much like the scientific process in that you have a hypothesis as to why something does not work and then you test your hypothesis and work methodically, eliminating the reasons it may not work, before moving onto the next hypothesis.

    These are some of the usual culprits:


    Modifying Your Code

    What is happening here? In order to turn the LED off and on, you are programming your voltage to change at the output pins of your BASIC Stamp.

    To turn the LED on, you momentarily turned pin 0 to 5 volts, logic high, by using the command HIGH 0. To turn the LED off you switched the output of pin 0 to logic low, or 0 volts DC, by using the command LOW 0.