What is an Arduino Shield?
If you are learning about Arduino, you have no doubt come across the term Arduino Shield. This tutorial will explain what Arduino Shields are, why they are awesome, and several things to consider when buying shields. cool electronics ideas that you have. Now the Arduino in and of itself is pretty amazing - you can do a lot of stuff with an Arduino alone. But when you want to start adding all types of cool technologies like bluetooth, wifi, RF, motor-drivers, etc. it can be pretty tricky; especially if you are new to electronics and programming. Arduino shields take all the complexity of the hardware and reduce it to a simple interface. This allows you to get your idea up and running fast. Now it's not just the hardware that shields take care of, in many cases, Arduino shields also have programming libraries associated with them. These libraries allow you to easily implement the hardware features available on the shield. There are shields for all types of things - LCD shields, LED matrix shields, wifi and bluetooth shields, motor shields, power supply shields, geiger counter shields, there are even shields for cooking hot dogs. Chances are if you need to do something, a shield exists to get you up and running quick. Shields plug right into the top of an Arduino. The black plastic rows of holes along the sides of an Arduino are called headers, and on the bottom of a shield, you have these long spiky pieces of metal, these are called pins. The pins on a shield line up with the header rows on an Arduino and fit snuggly (more on this later). Buying an Arduino Shield? Think about this stuff: Does it have good documentation? Documentation is the fancy way of saying - “will they show me how to use this thing?” Basically, is there some type of tutorial or user manual or forum that talks about how to use the shield. This is one of the biggest factors for me when it comes to buying an Arduino shield. For all the ease of use that a shield provides, if I don't know how to use it, it's about as a good as a rock. Lucky for us, people who use Arduino tend to be awesome and do a great job writing about how to use stuff, so even if the manufacturer doesn't have good instructions, if people actually use the shield, then you will find a wealth of information online. But if you do a web search and it doesn't turn up much of anything useful, you might consider looking for another option. Two US companies that provide superb documentation of the shields they make and sell are Adafruit Industries and Sparkfun. Soldering may be required Many shields are sold as kits, that means they are not fully assembled - and will require you to do some soldering. If you are buying from a reputable source, you should know this ahead of time, but it is worth double checking. Sometimes manufacturers will offer the shield as a kit or fully assembled - I often go for the fully assembled option just to save time. If you have not soldered before, shields are usually a cinch to solder, so don't be intimidated - go get a cheap soldering iron and some solder and go for it! Probably the most important thing when soldering a shield is making sure that the pins on the bottom of the shield are straight up and down, if they aren't they won't line up to the Arduino headers and be a major pain to connect. Stackable or Not Stackable Arduino Shields If you plan on stacking an Arduino shield with other shields, you will want to make sure it is stackable. If it doesn't have pin headers on the top of the shield, or they don't look aligned correctly (usually too narrowly spaced), than it is likely another shield cannot be stacked on top of it. You might also run into a problem if components on the shield stick up too high to allow shields above from getting a snug fit. Manufactures of shields are getting more savvy to this issue, but you should always check. Not all Arduino shields have the same pinout Some older Arduino shields may not have all the pins to fill the header rows of an Arduino. This is because older versions of Arduino didn't have as many pin header slots. This usually isn't too much trouble, unless you needed to use those pins that are not connected on the shield. If you have an older version of Arduino, then a shield you buy might have more pins than your Arduino has headers for - usually they are still physically compatible - this should not be anything to sweat about. Matching Hardware and Software Versions On a final note, if you are having trouble with a shield working, it worth checking to see if you are using the most current library version for your version of shield. A great example is the near ubiquitous Adafruit motor shield. There is a hardware version 1 and a hardware version 2. There are two separate code libraries for these. If you are trying to run your new version of the hardware on the old version of the library - then you will likely run into troubles. It worth checking to see you have the correct library for the job. I hope you found this tutorial helpful, please be sure to check out our free Arduino Crash Course (signup below) if you want to accelerate your learning.
How to Use and Understand the Arduino Reference
So you just opened up your fancy new gadget - maybe an awesome DSLR camera, or the newest gaming system, or maybe a new Blu-ray player. As you gladly tear away the packaging - you notice a small book that feels like it was printed on 4th generation recycled newspaper - it’s the instruction manual. As you skim the pages you realize it was first written in Japanese, translated to Chinese by an Australian ventriloquist and then an intern in California used Google Translate to finish the job for your native tongue. So you toss the instruction manual and just plug the gadget in. Good for you - especially since it appears as everything is working just fine. Until.. ...something isn’t working just fine. Maybe you can’t navigate the menu options to find a setting that was advertised on the box, or maybe the functionality you thought your gadget has does not appear to be working no matter how correctly it seems you are pressing the buttons. This tutorial is going to focus on the Arduino instruction manual, known more commonly as the “Arduino Reference” or the “Arduino Documentation”. It is an important and useful aspect of learning to use Arduino - it will be your best friend in times of bewilderment, brain lapses and fits of rage. I know that instruction manuals get a bad wrap - but don't fret - the Arduino Reference is awesome! To be honest what really keeps us away from the documentation is our fears. That’s right - the reference pages can be a bit intimidating when you are just starting out. They use a lot of technical jargon, are loaded with funky acronyms and filled with rabbit holes. Nobody uses the stuff anyway...right? ( Not right - that was a joke! ) This Tutorial Will Cover: What is the Arduino Reference? The Anatomy of an Arduino Reference Page. Why You Should Be Using the Arduino Reference More. How to use brain waves to trick your cat into eating less. Have you ever read a book and come upon a word you didn’t understand? Sometimes you can infer the meaning from it’s context, but what about when no such context exists? Likely, you used a search engine to find the definition. The definition told you what the word meant, whether is was a verb or adjective (or both), it gave some examples of how to use the word, and maybe even the etymology. The Arduino Reference is the same thing. It is the “dictionary” for all the structures, variables and functions that you can use when programming a sketch. It tells you the description, the parameters it uses, the syntax (how it is written), and even gives a bunch of examples on how to use it. So let’s jump into an Arduino Reference page and dig into what we can learn. The Anatomy of an Arduino Reference Page So let’s navigate to a reference page to start our journey. You can find the index of all the Arduino Reference pages on the Arduino Website: http://arduino.cc/en/Reference/HomePage Or - if you are offline - don’t worry, your Arduino IDE comes with an html copy of all the pages. You can get to it through the Arduino IDE: Help > Reference You will note at the top of the Reference Index page, there are three columns; Structure, Variables, Functions. This is the first level of organization in the reference. So if you are looking for a variable, you know which column to start looking in. Each of the hyperlinked items on this index page will take you to the individual entries reference page. What’s great about the individual reference pages is that they are organized in a similiar manner from one to the next, so you should know what to expect. They are also terse, so don’t think you are going to have to scour through someones dissertation. Each page has some major headings. We will walk through each of the main ones, and then talk about some less common ones. Description: All entries will have a description. Pretty straightforward - this is going to be a simple explanation of what the item does. It usually uses language that is basic. Syntax: Most all entries have a “syntax” heading, but they are more prevalent for functions. The syntax shows how the function (or other code) should be written when you use it in your sketch. Basically - it is what the function needs to know to do it’s job. Let's take an example from the digitalWrite() reference page. The words in the parentheses are telling you what type of value should be passed to the function. If we want to use this function than it will need to know 2 things - the pin number and the value to write to the pin. You don’t type in the word “pin” when you use the function, you would replace that with the actual pin number, or a variable that represents that pin number. Same is true for the word “value”, you would replace this with one of the acceptable parameters (see below). So when you actually wrote the function, it might look like this: digitalWrite( 13 , HIGH ) Where 13 is the “pin” and HIGH is the “value”. Parameters: Only structures and functions will have the “Parameters” heading. These describe exactly what can go in the parentheses in the syntax above. This is good to know, because you might be trying to pass a floating point number when the function calls for an integer. Returns: This tells you what value to expect a function to give you back. For example, when you use the square root function, you expect to get back the square root. But what data type will the square root be - an integer, a float or a double? The “Return” heading will tell you. Sometimes, a function will return nothing. Take the pinMode() function for example, you give it the pin number and the mode that you want the pin to be and it simply sets the mode - there is no data it needs to give you back. Example: This is your best bet at understanding how the structure, function or variable is intended to be implemented in code. It is usually a very short code snippet, though sometimes they can be lengthy. The example below is taken from the map() reference page. A nice feature of the example description is the “get code” option on the right of the reference page next to the example code. When you click this, it will take your browser to a plain text web page where you can copy and then paste the code into your Arduino IDE. See Also: This is a bulleted list of similar or related entries to the reference page you are looking at. They will link to other reference pages inside the reference directory. If I end on a reference page that isn’t quite what I was looking for, I will usually check out the options they provide here. Sometimes, they will also link to tutorials on the Arduino website (and who doesn’t like tutorials?) Keep in mind if you are using the reference in the offline mode through the Arduino IDE and you do not have an internet connection that any links outside the reference directory will not work. That includes the most common headings, what follow are some less common, but none-the-less useful headings you will run into. Programming Tips / Coding Tip / Tip: These are going to little bits of knowledge provided by people who know their stuff. I always like to read these, because they add to the depth of my understanding. Warning: These point out common errors that occur when people like me and you try to use the code. Caveat: If there is an exception to the rule, they will be described here. Note: In many cases, the notes are the “miscellaneous” heading, capturing information that doesn’t particularly fall under other headings. Why You Should Be Using the Arduino Reference More Here is a scenario I have played out myself about 7,000 times. I am writing a program and some function does not seem to be working right. I spend 30 minutes making changes to the program, but keep getting errors. Every time I think I have it fixed, I find I am wrong. Then I decide to check out the reference at which point I quickly realize I simply didn’t understand how a function was supposed to work. So the habit I have developed when I don’t completely understand a function it to check out the associated Arduino Reference page. It saves me times, teaches me something I didn’t know or re-teaches me something I forgot - and it will do the same for you. Let’s sum all this up. The Arduino Reference page is: The Bee’s Knee’s. The Lions Mouth. My favorite page on the Arduino website. Your favorite page on the Arduino website? Challenge(s): Go the Arduino Reference Index Page and start perusing some functions. See if you can find entries with the following headings: Caveat / Warning / Tip Further Reading: Warning - this gets deep! - AVR Libc (This is the reference for what the Arduino language is based on) - User Manual for the AVR Libc P.S. Ok - as much as I love the Arduino Reference page, sometimes it has errors. So if you find any, mention it on the Arduino Forum.
Using Red-Green-Blue (RGB) LEDs with Arduino (Common Cathode Type)
In this tutorial we describe using RGB LEDs of the Common Cathode Type. We will describe setting up the circuit, talk about the LED and discuss the code used to adjust the hue.
Using Random Numbers with Arduino
This video tutorial talks about using the random() and randomSeed() functions with Arduino. It is pretty straight forward, but there are some intricacies worth noting. Creating truly random numbers in Arduino is harder than you might think. The closest we can get in Arduino, and just about anywhere else, is using pseudo random numbers. That is, numbers that mimic randomness, but in fact do have a pattern if Want to fast-track your Arduino skills? Click here to join our 12-part HD Video Course. Why are Random Numbers with Arduino All the Same? The most important thing to understand when using the random() function with Arduino is that it will generate the exact same list of pseudo random numbers every time. So if you build a slot machine, and the first crank of the handle is a winner, then you can be sure that if you reset the Arduino board and pull the handle again - it will still be a winner the first time. The easy way to overcome this is using the randomSeed() function. This function takes a value (an integer for example), and uses the number to alter the random list generated by the random() function. The number you pass to the randomSeed() function is called a 'seed'. You might put randomSeed() in the setup, and then use the random() function in the loop. Something like this: //this variable will hold a random number generated by the random() function long randomNumber; //Set up - this is where you get things "set-up". It will only run once void setup() { //setup serial communications through the USB Serial.begin(9600); //Let's make it more random randomSeed(42); }//close setup void loop() { //generate a random number randomNumber = random(2,5); //display the random number on the serial monitor Serial.print("The Random Number is = "); Serial.println(randomNumber); } But there is still an issue - even though the sequence of random numbers is different when using the randomSeed() function - it will still be the same every time the sketch is run. It is just a different list of pseudo random numbers! One Solution to the Random Problem So, what to do? Lucky for us the Arduino reference has a great solution. Use the analogRead() function to read a value from an unused analog pin. Since an unused pin that has no reference voltage attached to it is basically 'floating', it will return a "noise" value. This noise value can seed the randomSeed() function to produce differing sequences of random numbers every time the sketch is run. Below is the sketch from the video using analogRead() and randomSeed() in unison: /*How to use the random() and randomSeed() function YOU WILL NEED: (3) LEDs (3) 220OHM resistors (1) Jumper Wire (4) Hot cakes CIRCUIT: Connect a resitor to pin 2 and then to a breadboard. Connect the long leg of an LED to the resitor and the short leg to one of the ground rails on the breadboard Repeat this for the other components at pin 3 and 4 Coonect the ground on the breadboard to one of the Arduino GND pins. Created JUL 2014 by Michael James https://programmingelectronics.com/thearduinocourse */ //Declare and initialize LED pin variables int LED_1 = 2; int LED_2 = 3; int LED_3 = 4; //this variable will hold a random number generated by the random() function long randomNumber; //Set up - this is where you get things "set-up". It will only run once void setup() { //setup serial communications through the USB Serial.begin(9600); //Let's print a start messgae to the serial monitor when a new sequence of random numbers starts Serial.println("Starting new Random Number Sequence"); //set the LED pins as outputs pinMode(LED_1, OUTPUT); pinMode(LED_2, OUTPUT); pinMode(LED_3, OUTPUT); //Let's make it more random randomSeed(analogRead(A0)); }//close setup //The loop() runs over and over again void loop() { //generate a random number randomNumber = random(2,5); //display the random number on the serial monitor Serial.print("The Random Number is = "); Serial.println(randomNumber); Well, hopefully that was random enough for you! If you enjoy this tutorial, I highly recommend checking out our free Arduino Crash Course (You can sign up below).
Kit-on-a-Shield for Arduino
Ever ever spent too much time searching for a 220 ohm resistor or just one more jumper wire? Are you sure you had that extra LED, LDR, [Fill in the blank], but have no idea where it went? Do you just want to throw up a quick circuit and get to coding? Travel a lot and want an easy way to learn Arduino on the road?