Home Chapter 7 BS2 with a switch to LED outputs

Site Search

GTranslate

Chinese (Simplified) French German Italian Portuguese Russian Spanish
BS2 with a switch to LED outputs


So far you have learned to program the flashing of two LEDs in the process of programming and downloading your code into the Basic Stamp 2. In order to turn either LED off and on, you must program your voltage to change at the output pins of your BASIC Stamp. To turn the LED on, you momentarily turned pin 0 and pin 1 to 5 volts by using the command HIGH 0 and HIGH 1.

To turn the LEDs off, you switched the output of pin 0 and pin 1 to logic low, or 0 volts DC, by using the command LOW 0 and LOW 1. In both cases, the HIGH and LOW command is smart enough to also know that you want these pins to function as outputs. Output means you are sending voltage and current out of the pin as opposed to looking to accept a voltage into the Stamp to make something change.

One of the amazing elements of the BS2 is that you can also program a pin, which was formerly an input, to function as an output. This is exciting, as it means you will be able to configure any of the 16 input/output pins to drive devices by providing voltages from the BS2 and to accept voltages from other devices. By accepting voltages into the pins you will be able to use switches and sensors, which allow you to have the BS2 make decisions based on these inputs and your programming.

In this activity you will learn to install and program a small micro switch to turn on two LEDs and in this process, you will have learned to program and relate an input to a programmed output, thus completing the notion of feedback.

By pressing the micro switch provided, you will make a series of LED's flash, which gives you visual feedback and lets you know that your pressing action was what triggered the LED's. These switches are devices that allow human hands to make and break electrical connections.

This next exercise will be practiced in many variations in this book, where various kinds of devices and switches will be used to cause some change within the BS2 to allow some change outside of the BS2, as with the LEDs, for instance.

In this exercise, you will learn to use a command called IN and another command called IF…THEN, which is a conditional logic statement, used to make decisions about what the BS2 will be doing.

You will begin by using your multimeter to test a small micro switch and determine the normally open position and the normally closed position of the switch.

 

Normally open or “NO” means the switch contacts are not complete until you press and activate the switch.

 

Normally closed or “NC” means the connection is always complete unless you press the switch, breaking the contact.


Parts Required


1 Mini switch
1 10k ohm resistor
1 220 ohm resistor
 Connecting wires

Introducing switches

Switches are devices that come in all shapes and forms and allow you to make and break electrical connections. There are literally thousands of varieties of switches, which can be activated in numerous ways, but all perform the same basic function.

 

Mini switch enlarged, Normally open push button switch. This is the one in your kit and is good for human fingers.

FA limit switch (actual size) is a very useful switch as it is used in making and breaking electrical connections in mechanical operations with cams for instance. This is not in the kit but provided as an example and is one that is good for machine “fingers” so-to-speak.

 

The key parameters for switches are:

  1. Their maximum current rating or the highest current the switch can
    handle. The micro switch below is fine for small currents, but certainly would not work for the 25 amps that you are familiar with using to switch your house lights on and off. The micro switch wires are just not fat enough to handle the number of electrons.
  2. How much voltage the switch can handle. The switch below is fine for 5 volts DC, but is not capable of handling 120 volts AC, for instance, as again, it is just not beefy enough.
  3. How much resistance is there across the two connecting points of the switch.
  4. How fast the switch can make and break its connection.
  5. How many times you can use the switch. All mechanical parts have a limited life span and some will go for a few hundred-switch activations while others can function for millions of activations.
  6. The type of switch and other characteristics such as the amount of force needed to activate the switch. Some common switch types are rotary, pushbutton, illuminated, or snap action, and different forces are required to activate them. Limit switches, for example, require different amounts of force to activate them.

    Try doing a GOOGLE image search on these key phrases: rotary switch, push button switch, illuminated switch, snap action switch and see what you discover.
  7. Some switches do not require human hands for activation, but can be triggered by infrared light or by sound. These can be explored further in the section on sensors in chapter 17-

    The micro pushbutton switch that is part of this project is especially good for prototyping electronics on your breadboard and for testing software. This same software will function with much larger switches.

    In order to use this switch, you must first determine its normally open position often designated NO in ordering catalogs.

  8. Place the switch in the breadboard on the Board of Education, as shown below.
  9.  

     Switch on Board of EDU

     

  10. Set the multimeter to 200 Ohm’s or to the continuity tester if you have one with a beeping capability.


  11. Now, touch the tip of the meter probes to the leads of the switch, as shown in Figure 7-19
  12. Use one hand to hold both probes or get help from a friend and press the small pushbutton.

     


  13. Using continuity tester to check switch

     

  14. Keeping your multimeter on the same settings, move the probes over to the other two electrical leads underneath the switch. With one hand holding the two multimeter probes, as above test the switch.
  15. Now, press the button with your finger and see what the reading is. If the switch is closed, the meter will read between .2 and .7, which is the same as finding continuity between two electrical points, as in Chapter 3 where you used your multimeter to test an electrical connection between the two wire ends.
  16.  

    Testing a switch

     

    In the second example, the numbers changed, which means that those two points are the normally open part of the switch. Because the numbers didn’t change in the first example, it means that the points are connected together. Now that you have determined the position of the switch for its normally open configuration, you are ready to hook up the circuit.