Your First Arduino Statement

Lets skip the next line, and go to the next two:

  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);

First line here is a...comment! Yes - We are already starting to recognize when a line of code is comment or not, nice work!

The second line is...not a comment. This is the first line of actual instruction code. It is also extremely unlike English (or any other human language).

This line of text, pinMode(13, OUTPUT); is what is called a statement, which is basically like a computerized sentence. Much like human sentances end with a . (period), all Arduino sketch statements end with a ; (semicolon)

But what does this statement/sentence mean? Well, coding is very concise, compared to human language. If the Arduino was a person, and you wanted it to unlock the front door,  you would probably call out and say something like:

Hey, Arduino, could you please unlock the front door for me? Thanks!

But that's very wordy. Arduino wants to get the job done fast, so instead of all the niceties you can skip straight to:

Set front door to unlocked

You're telling it the action you want it to do (set), and the things to do it on (front door) and the result you want (unlocked).

Now, the Arduino does not have a front door but it does have pins:

And what we want to do is basically to change the mode of one of these pins, and set it to an output pin (more on that later!)

So...

Arduino, please change the mode on pin number #13 to be an output. Thank you.

Shortens to...

Set pin 13 mode to output.

Shortens to...

pinMode ( 13 , OUTPUT ) ;

And, turns out that those spaces are not so important either so we can squish it down to pinMode(13, OUTPUT);

Remember that at the beginning of the example, we were calling out to the Arduino to ask it to do something? That's how we describe this statment: it is a function call to the Arduino. The function of the call is to have it change the mode of the pin just like the function of calling to your roommate to unlock the door.

Here is the structure of a function call:

Function name

(

Inputs & Details
Separated by commas

)

;

pinMode

(

13, OUTPUT

)

;

You might be wondering "OK, wait, so if the Arduino will do anything I ask - why don't I just tell it something like writeMyHomework(CHEMISTRY); and take off the rest of the day? Ahh, don't we all wish! It isn't like there's a magic wizard inside the Arduino - someone, somewhere had to describe what to do when it gets the pinMode request. If you wanted to ask the Arduino to do your Chemistry homework you'd still have to go through and explain to it every detail of how to do the homework. (It would be faster if you just did it yourself)

But enough chitterchatter - let's continue on and look for more comments and statements!

This guide was first published on Sep 02, 2016. It was last updated on Sep 02, 2016.
This page (Your First Arduino Statement) was last updated on Aug 08, 2020.