Arduino Reference

These are the basics about the Arduino language, which implemented in C. If you're used to Processing or Java, please check out the Arduino/Processing language comparison.

Arduino programs can be divided in three main parts: program structure, values (variables and constants), and functions.

Program Structure

Getting Started

An Arduino program run in two parts:

setup() is preparation, and loop() is execution. In the setup section, always at the top of your program, you woiuld set pinMode, initialize serial communication, etc. The loop section is the code to be executed -- reading inputs, triggering outputs, etc.

Control Structures

Further Syntax

  • ; (semicolon)
  • {}? (curly braces)
  • // (single line comment)
  • /* */ (multi-line comment)
  • #define

Variables

Variables are expressions that you can use in programs to store values, like e.g. sensor reading from an analog pin. They can have various types, which are described below. Warning: floating point variables and operations are not currently supported.

Constants

Constants are labels for certain values which are preset in the Arduino compiler. You do not need to define or initialize constants. Arduino includes the following pre-defined constants.

Functions

Digital I/O

Analog I/O

Serial Communication

Used for communication between the Arduino board and the computer, via the USB or serial connection (both appear as serial ports to software on the computer). Or used for serial communication on digital pins 0 (RX) and 1 (TX).

Serial Library as of version 0004

Handling Time