Reference   Language (extended) | Libraries | Comparison

constants

Constants are predefined variables in the Arduino language. They are used to make the programs easier to read. We classify constants in groups.

Defining Logical Levels, TRUE and FALSE (Boolean Constants)

There are two boolean constants defined in the C language, upon which Arduino is based: TRUE and FALSE.

FALSE is the easier of the two to define. FALSE is defined as 0 (zero).

TRUE is often said to be defined as 1, which is true, but TRUE has a wider definition. Any integer which is non-zero is TRUE, in a Boolean sense. So -1, 2 and -200 are all defined as TRUE, too, in a Boolean sense.

Defining Pin Levels, HIGH and LOW

When reading or writing to a digital pin there are only two possible values a pin can take/be-set-to: HIGH and LOW.

HIGH represents the programming equivalent to 5 volts. When reading the value at a digital pin if there is 3 volts or more at the input pin, the microprocessor will understand it as HIGH. This constant is also represented by the integer number 1, and also the truth level TRUE.

LOW is representing the programming equivalent to 0 volts. When reading the value at a digital pin, if we get 2 volts or less, the microprocessor will understand it as LOW. This constant if also represented by the integer number 0, and also the truth level FALSE.

Defining Digital Pins, INPUT and OUTPUT

Digital pins can be used either as INPUT or OUTPUT. Changing a pin from INPUT TO OUTPUT with pinMode() drastically changes the electrical behavior of the pin.

Pins Configured as Inputs

Arduino (Atmega) pins configured as INPUT are said to be in a high-impedance state. One way of explaining this is that pins configured as INPUT make extremely small demands on the circuit that they are sampling, say equivalent to a series resistor of 100 Megohms in front of the pin. This makes them useful for reading a sensor, but not powering an LED.

Pins Configured as Outputs

Pins configured as OUTPUT are said to be in a low-impedance state. This means that they can provide a substantial amount of current to other circuits. Atmega pins can sorce (provide positive current) or sink (provide negative current) up to 40 mA (milliamps) of current to other devices/circuits. This makes them useful for powering LED's but useless for connecting to sensors. Pins configured as outputs can also be damaged or destroyed if short circuited to either ground or 5 volt power rails.

See also

Reference Home

Corrections, suggestions, and new documentation should be posted to the Forum.

The text of the Arduino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.