Prototype an Electronic Coin-toss Step 1: Connect the IC to Power
Electronics Projects: How to Build a Motor Driver
Electronics Projects: How to Use NAND Gates to Create Other Gates

Electronics Projects: How to Flash an LED with a BASIC Stamp

A BASIC Stamp is serious overkill for an electronic circuit that simply flashes an LED on and off: You can do that for a few bucks with a 555 timer integrated circuit (IC), a capacitor, and a couple of resistors.

But learning how to flash an LED on and off with a BASIC Stamp is an important step toward completing more complex projects. To flash an LED on and off, you first have to connect an LED to an output pin in on the homework board. Once that is done, all that remains is learning how to write a PBASIC program that will flash the LED.

To write such a program, you need to know the following five PBASIC instructions:

  • HIGH — Sets one of the Stamp’s I/O pins to HIGH. You use this instruction to turn the LED on.

  • LOW — Sets one of the Stamp’s I/O pins to LOW. You use this instruction to turn the LED off.

  • PAUSE — Causes the Stamp to sit idle for a specified period of time. You use this instruction to delay the program a bit between HIGH and LOW commands so that the LED stays on for a while before you turn it off, and then stays off for a while before you turn it back on.

  • GOTO — Causes the program to loop back to a previously designated location. You use this to cause the program to repeatedly flash the LED on and off instead of flashing the LED on and off only once.

  • Label — Marks the location that you want the GOTO statement to loop to.

Here's the complete program that flashes the LED:

' {$STAMP BS2}
' {$PBASIC 2.5}
Main:
 HIGH 15
 PAUSE 1000
 LOW 15
 PAUSE 1000
 GOTO Main

Take a look at how this program works, one line at a time:

Program Line What It Does
' {$STAMP BS2} Indicates that the program will run on a BASIC Stamp 2.
' {$PBASIC 2.5} Indicates that the program uses version 2.5 of PBASIC.
Main: Creates a label named Main that marks the location that the GOTO command will loop back to.
HIGH 15 Makes I/O pin 15 HIGH, which turns the LED on.
PAUSE 1000 Pauses the program for 1,000 ms, which is the same as one second. This allows the LED to stay on for one full second.
LOW 15 Makes I/O pin 15 LOW, which turns the LED off.
PAUSE 1000 Pauses the program for 1,000 ms. This allows the LED to stay off for one full second.
GOTO Main Causes the program to skip back to the Main label, which causes the program to loop through the HIGH, PAUSE, LOW, and PAUSE instructions over and over again.

The net effect of this program is that the LED on pin 15 flashes on and off at one-second intervals.

This project shows how to build a simple circuit that connects an LED to pin 15 and then download and run the LED Flasher program so that the LED flashes on and off.

image0.jpg
  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus
Electronics Projects: How to Build Series and Parallel Switched Circuits
Electronics Projects: How to Write a PBASIC Program
Electronics Projects: How to Make an LED Flasher Using a Timer Chip
Electronics Projects: How to Build a T Flip-Flop Circuit
Electronic Project Plan Step 2: Design the Circuit
Advertisement

Inside Dummies.com