sparkfun Arduino Power Switch User Manual

June 9, 2024
sparkfun

sparkfun Arduino Power Switch User Manual
sparkfun Arduino Power Switch

Description

This is a simple ON/OFF switch for the LilyPad. When the switch is in the ON position it is closed and when it is in the OFF position it is open. Use it to trigger behavior in your programmed project, or to turn LEDs, buzzers, and motors on and off in simple circuits.

Dimensions

  • Size: 7.75×18.1mm
  • Thin 0.8mm PCB

How to Connect:

Connecting

Schematic

Schematic

Sensing (Switches):

Make a simple switch out of alligator clips
The LilyPad ProtoSnap Development Board already has a switch wired to the board, so if you’re using this board you can skip to the next step A switch is basically 2 pieces of conductive material that are sometimes pressed together and sometimes kept apart. The switch is CLOSED (pressed or triggered) when the conductors are pressed together and OPEN when the conductors are separated. We’ll make a really simple switch using 2 alligator clips. Attach a black alligator clip to the (-) tab on your LilyPad Arduino and an alligator clip of a different color (preferably not red) to tab 5. Now, when we touch the two alligator clips together we are closing or “pressing” the switch. Note that when we touch the clips together, the switchPin (flower petal 5) will be attached to ground or (-) via the alligator clips. We refer to ground or (-) in Arduino code as “LOW” and power or (+) or “+5V” as “HIGH”. More about this in a second.

Sensing

Attach the LilyPad to your computer and start the Arduino software

Copy this sample code into an Arduino window
Click here for switch sample code. Copy and paste this code into an empty Arduino window.

Format the Code
Under the Tools menu, select Auto Format. After you do this, align all of your comments (the statements in grey-brown following “//” on each line) so that they are in readable columns on the right hand side of the screen. This will help you read through the code. Here’s what my Arduino window looked like after I formatted everything:

Format the Code

Read through the code to get a sense of what it is doing. The comments at the end of each line should help you understand what’s happening. Note that in the code we are listening for a LOW signal on the switchPin. We turn on the LED when the switchPin is attached to ground. As was mentioned earlier, when we put the two alligator clips together this is exactly what is happening: the switchPin is attached to ground via the clips. So, let’s test it out in the real world…

Load the code onto the LilyPad
Compile the code and load it onto the LilyPad. Do this by hitting the upload button in the Arduino window (that’s the right pointing arrow at the top of the Arduino window).

See what happens when you close the switch!
The LED should come on. If it doesn’t, check to make sure your alligator clip connections are good. Here’s what my switch triggered board looks like. Look closely to see the light:

close the switch

If you’re using the LilyPad Proto Snap Development Board, turn on the pre- wired switch. The green light (next to pin 11) should turn on. Trying changing the code so you can use the button on pin A5 to turn on the green light

Overview

Play with modifying the code to get different behavior

  • Can you get the LED to turn on when the switch is open and off when the switch is closed? (Basically swapping the behavior of the sample code.)
  • Can you get the LED to blink quickly while the switch is closed and turn off when the switch is open?
  • Something a little more challenging… can you get the LED to toggle on and off with each press of the switch? That is, the first time you press the switch, the LED turns on, the second time you press the switch it turns off, and so on?

Build your own switch
As you can see from the alligator clip example, it’s easy to build a switch. Play with different materials to make your own switches. Some materials that you can use to make switches are conductive velcro, conductive fabric, conductive thread, aluminum foil, metal springs and metal beads. Use your imagination and whatever is lying around the house!

Read User Manual Online (PDF format)

Read User Manual Online (PDF format)  >>

Download This Manual (PDF format)

Download this manual  >>

Related Manuals