Introduction: FunShield for Arduino

I’ve been using the SparkFun Inventor's Kit to help teach electronics and programming to Teen Makers at our local public library in Corvallis Oregon. We’ve had lots of success, but being able to get a bread-boarded circuit working is sometimes a discouraging hurdle to younger makers, especially if time is limited, so I designed this shield to so that we could skip the wiring and get right to programming. I’m calling it the FunShield because what I really want kids to learn is how fun programming is.

The shield gives you access to input devices like a potentiometer, photocell, push buttons, and a temperature IC. The shield also contains outputs in the form of eight standard LEDs, an RGB LED, and a piezo speaker. There is no way to hook them up wrong or have conflicting pin assignments.

This Instructable will show you how to build and use the FunShield. I hope you find it as useful and fun as I have!

A kit is available on Tindie.com. Purchasing the kit will save you the time and expense of ordering from several different vendors and avoid the minimum PCB order premium. You will also be helping us develop and share other projects!

Step 1: Gather the Parts

To start, check to see you have everything:

From the SparkFun Inventor's Kit (or your favorite supplier):

  • (1) Photocell, SparkFun SEN-09088, $1.50
  • (1) SN74HC595N SHIFT REGISTER 16-DIP, SparkFun COM-00733, $1.50
  • (1) IC SENSOR TEMP, SparkFun SEN-10988, $1.50
  • (1) Piezo speaker, SparkFun COM-07950, $1.95
  • (1) TRIMMER 10K OHM 0.2W PC PIN, SparkFun COM-09806, $0.95
  • (1) Mini Push Button, SparkFun COM-00097, $0.35
  • (2) Momentary Push Button Switch - 12mm Square, SparkFun COM-09190, $1.00
  • (1) Common cathod RGB LED 5 or 10mm, SparkFun COM-11120, $0.95
  • (8) Assorted color 5mm LEDs, COM-12062, $2.95
  • (12) 330 Ohm 1/6W resistor, SparkFun COM-11507, $0.95/ea
  • (4) 10K 1/6W resistor, SparkFun COM-08374, $1.00
  • (1) Diode SparkFun COM-08588, $0.15
  • (1) NPN Transistor, COM-12852, $0.50

Other Items:

  • (1) PCB Board, http://oshpark.com/shared_projects/lPWpxju2, $22.10 for three copies
  • (1) 40-pin Break away header, SparkFun PRT-00116, $1.50
  • (2) CONN HEADER FEMALE 2POS .1" TIN, Digikey S7000-ND, $0.68
  • (1) CONN FEMALE 4POS .100" R/A GOLD, Digikey S5479-ND, $0.74
  • (1) CONN HEADER 4POS .100 R/A 30AU, Digikey 609-3312-ND, $0.39

Remember, I've done all the hard work if you just want to buy the kit at Tindie.com.

Step 2: Gentlement, Start Your Iron

We are going to assume you have some kit-building experience. If you need some help soldering, head over to www.sparkfun.com/tutorials/213 to brush up.

The order of assembly is largely a matter of preference. If you don't have a helper or a vice, I generally go from lowest height to tallest so when the board is reversed on the table, the parts stay in place.

Resistors:

Let's start with resistors since they are the most plentiful, lowest seating, and easiest to solder. They are more heat resistant and will give you a chance to brush up on your technique. They also have no polarity, so you can put them in either way.

You will, however, have to get the right values if you want the LED to be the correct brightness. In general, I use 330 ohm for red and yellow and 180 ohm for green and blue. When in doubt, check your data sheets for the forward voltages, and then calculate the correct resistor for 5 volts at http://led.linear1.org/1led.wiz. Resistor value for other components like 10K ohm for the I2C bus are marked on the PCB.

Diode and Photocell:

Now you are warmed up, time to try something with polarity. Add the diode above the 330 ohm resistor in the upper center of the board, observing the white line on the PCB and the black band on the diode. This is the "kick-back" diode for the motor transistor, so your motor will not work if it is in backwards (it will just bypass the motor and probably overheat.

The photocell goes in the lower right corner, and has no polarity.

Step 3: I2C Headers and Shift Register

The I2C headers on the right side are optional, and will allow you to connect two boards together, or connect to another I2C device like a Wii Nunchuk or Adafruit I2C LCD. They are logically next because they sit so low, but they can be added later if desired.

The shift register allows us to control the eight LEDs using just three of the Arduino's I/O pins. Itis a 16-pin IC that must go in with the correct orientation to work. Note the notch in one end. This show which side of the chip has pin one. Match the notch with the outline on the PCB. I usually solder on pin on each diagonal corner and then check the seating. Double check the orientation, because after you solder more than two pins, it will be very difficult to switch. Trust me, I've had to do it more than one.

Step 4: Temperature Sensor and Transistor

The Temperature Sensor and the Transistor look identical except for the markings. Identify them by the markings on the face using a good light and a magnifying glass. You are looking from something like "TMP36" for the temperature IC, and "2Nxxxx" for the transistor.

The Temperature Sensor goes in the upper left corner with the flat face toward the center of the board. This is an analog device that produces a voltage proportional to temperature.

The NPN Transistor goes on the upper right side of the board, and may or may not have the flat face pointing toward the center of the board, depending on your manufacture. Check your data sheet and the schematic above to see where the base, collector, and emitter pins are. The transistor is an electronic switch that lets us use the small current the Arduino digital pins can supply to control a motor needing 200 milliamps. An LED, on the other hand, only needs 10 milliamps, so can be powered directly from the digital pins.

Step 5: Buttons and Speaker

Next up are the buttons. There are two input buttons, which can use either the 12mm button or a smaller tactile button, and the reset set button. These do need to be installed in a certain direction, the PCB holes are aligned to take care of that (don't bend the pins to fit them in).

The speaker is next. There are two sets of holes. The speaker sold by SparkFun has leads closer together, and has polarity. The set of holes 90 degrees off are farther apart, and fit the PS1202 style speaker sold by Adafruit which doesn't have polarity.

Step 6: Let There Be Light! or LEDs.

Time for LEDs. You should have already decided on colors and resistor values, so now you just need to get the correct LEDs in the right spots. LEDs have polarity, with the longer leg being positive. Solder one leg of each LED and then check the seating on the other side (it is easier to reseat if you only have one solder joint to heat up!)

The RGB led goes in the upper left corner. There are two types of RGBs, common cathode, where the longer pin has the supply voltage, and each color runs to ground, and common anode, where the long pin is the ground. In both cases, the longer lead goes through the hole with the square pad. The board comes ready for common cathode, which comes in SparkFun kits, but can be easily modified for the other if that is what you got from Adafruit. On the underside of the board, cut the CC pad, and solder-bridge the CA pad. Check both for continuity with a multimeter. Note: I've left enough room to use a 10mm RGB LED instead of the standard 5mm.

Step 7: Measure Your Potential - Trim Pot

The potentiometer, or "trim pot" goes in the lower left corner. There are several types of pin arrangements for potentiometer, and the SparkFun kit comes with one that is breadboard friendly with three 0.1" spaced leads in a line. I've also added the offset hole to mount the more common and inexpensive trim pots if that is what you've got on hand.

Step 8: Heading Out, or in - I/O Headers

There wasn't room for all the SparkFun kits components, so I added some headers to help us connect with the outside world. The 2-pin female header on the left connects the motor to the transistor controlled digital output. The 2-pin female header on the right connects to an analog pin and ground for components like the flex sensor. Use a piece of male header to hold them in place and aligned while soldering.

For connecting to the servo, add the 3-pin male header next to the motor header.

Step 9: Final Hot Work - Arduino Headers

The final bit of soldering you need is to connect the two 8-pin and two 6-pin male headers for connecting the shield to the Arduino. The easiest way I've found to do this is to put the headers in place in the Arduino first, and then place the shield over the pins before soldering them in place. This will give you rock-solid alignment.

Step 10: Start Sparkin

You should have noticed by now that all the pin assignments are marked on the bottom of the board, and can be used in normal Arduino fashion. In a lot of cases, they actually match the ones used in the SparkFun Inventors Kit's demonstration sketches. At most, you will just have to change the pin numbers to use them.

SparkFun Inventors Kit Guide: http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Kit...

SparkFun Inventors Kit Example Sketches: http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Kit...

  • Place the "SIK Guide Code" folder in the Arduino IDE "examples" directory:
  • Start the Arduino IDE; the examples should be visible in File/Examples/SIK Guide Code

Here are the FunShield Pin Assignments:

  • A0 TRIM
  • A1 LIGHT
  • A2 TEMP
  • A3 ANALOG
  • A4 I2C-SDA
  • A5 I2C-SCL
  • D2 Shift register Data
  • D4 Shift register Latch
  • D12 Shift register Clock
  • D6 RGB-BLUE
  • D9 RGB-RED
  • D10 RGB-GREEN
  • D3 MOTOR
  • D5 SERVO
  • D7 RIGHT BUTTON
  • D8 LEFT BUTTON
  • D11 Speaker

Step 11: FunShield Library

I have written a library for the FunShield to help take care of the dirty work of setup and pin assignment. The library includes demo sketches to get you going.

Steps:

  1. Download zip file from: https://github.com/MakersBox/FunShield/archive/mas...
  2. Unzip the folder.
  3. Move the "FunShield-master\FunShield\libraries\FunShield" folder to your sketchbook "library" folder.
  4. Restart the Arduino IDE.
  5. Example sketches should now show up under:
    • [File] -> [Examples] -> [FunShield]

Step 12: ArduBlock

ArduBlock is a graphical programming environment that integrates with the Arduino IDE. It is an open source project written in Java.

  1. If you haven't downloaded the zip file from: https://github.com/MakersBox/FunShield/archive/master.zip in the previous step, do so now and unzip it.
  2. Move the toolsfolder to your sketchbook folder.
  3. Move the ArduBlockExamples folder to your sketchbook folder.
  4. Restart the Arduino IDE.
  5. Start ArduBlock from [Tools] -> [ArduBlock].
    • If the "ArduBlock" option is not visible, go back and check you got it in the right location.
    • The actual directory structure should end up looking like: ../sketchbook/tools/ArduBlockTool/tool/ardublock-FunShield.jar

    • If you are still having trouble, check out the more detailed instructions at http://blog.ardublock.com/engetting-started-ardublockzhardublock/

  6. Open an example project (you will have to navigate to the ../sketchbook/ArduBlockExamples folder.

Step 13: Example of Component Integration

You are done! I guess that all that is left is to give you a gentle push in the right direction. Let's take a look at the example sketch called "FS_01_LED.ino":

First, we need to indicate we want to use the FunShield library, and instanciate a FunShield object called "fs":

// sets up and initialize FunShield
#include <FunShield.h> #include <Wire.h> // Require for I2C communication FunShield fs; // Instanciate FunShield instance

A couple of simple variables to help us:

// variable declarations
int led = 0; // Can be any led from 0 to 7 int delayTime = 1000; // Delay time in milliseconds

Since the FunShield library handles all the setup, the setup() function can be empty. I usually ad some code to see what is going on via the console:

void setup() {
Serial.begin(9600); // Setup serial communications for troubleshooting Serial.println("FS_01_LED.ino"); }

And now for the main loop:

void loop(){
LED(led, HIGH); // turn LED on delay(delayTime); LED(led, LOW); // turn LED off delay(delayTime); }

You should recognize this as the basic Arduino "blink" sketch, just using the FunShield LED() function instead of digitalWrite().

Lets bring in a for loop so we can turn all the LEDs on and off.

void loop(){
for(led=0; led<8; led++){ LED(led, HIGH); // turn LED on delay(delayTime); LED(led, LOW); // turn LED off } }

You may want to lower your delayTime value so it doesn't take a full 8 seconds to traverse the LEDs.

Now, how could we get the LED to reverse direction when it reaches the end? Another for loop maybe?

void loop(){
for(led=0; led<8; led++){ LED(led, HIGH); // turn LED on delay(delayTime); LED(led, LOW); // turn LED off } for(led=6; led>0; led--){ LED(led, HIGH); // turn LED on delay(delayTime); LED(led, LOW); // turn LED off } }

Notice I start back on led #6 because led #7 was already lit by the first for loop. I also stop the second loop at led#1 because the other for loop handles it as well.

What if we want to add an audible clue as the light changes direction? Here is where the beauty of the library comes in handy. No need to look up pin numbers. Just call the speaker() function

void loop(){
for(led=0; led<8; led++){ LED(led, HIGH); // turn LED on delay(delayTime); LED(led, LOW); // turn LED off } speaker(440, 10); // short beep for(led=6; led>0; led--){ LED(led, HIGH); // turn LED on delay(delayTime); LED(led, LOW); // turn LED off } speaker(880, 10); // short beep }

One final trick to throw in. How about we vary the speed of the LED based on the trim potentiometer value? Piece of cake! Just change the delayTime variable to the trim() function:

void loop(){
for(led=0; led<8; led++){ LED(led, HIGH); // turn LED on delay(trim()); // read potentiometer to determine delay time. LED(led, LOW); // turn LED off } speaker(440, 10); // short beep for(led=6; led>0; led--){ LED(led, HIGH); // turn LED on delay(trim()); LED(led, LOW); // turn LED off } speaker(880, 10); // short beep }

Wow, that was easy! You have the basis for a cool 2-dimension Pong game. Now go forth and have FUN!

Sensors Contest

Participated in the
Sensors Contest

Arduino Contest

Participated in the
Arduino Contest