LESSON 31: Understanding Arduino Arrays

So fare we have used variable declarations like float, int, char and string. We have a variable declaration for any type of data we want to work with, but each of these allows storing a single piece of information.  Often times we want to store more than just one variable, we want to store lists. We can store lists of variables in an array. We can make arrays of all the variable types we already know how to use. For example, if we wanted to store a single grade, we could use the following variable declaration:

float grade;

But, if we wanted to store a list of grades, we could define grades to be an array with the following command:

float grades[15];

This command creates an array called grades, which has 15 slots, so up to 15 grades can be stored. To specify which slot you are working with in your program, you simply reference the slot you are working with inside the brackets. For example:

grades[3]=97;

would set slot 3 in the grades array to the value 97.

Realize when you create an array in arduino, the first slot is slot zero, hence if you wanted to put a grade in the first slot you would use the command:

grades[0]=96;

You can create arrays for all the arduino variable types you are familiar with. You can create int, float, char and string arrays. The video above gives simple to understand examples of how to use arduino arrays.