top of page
  • Writer's picturePuriphico

constants: variables in arduino programming (part 1)

This article details the types of constants in Arduino programming

  • Overview

    • They are predefined expressions in the Arduino language, used to make the sketch easier to read.

  • HIGH | LOW

    • As you may have read in the Digital Functions articles, when reading or writing to a digital pin, there are only two possible values a pin can take: HIGH and LOW.

    • The meaning of HIGH and LOW depends on whether the pin is declared as an INPUT or an OUTPUT. Visit the articles on digital functions to learn more.

  • true | false

    • the two constants used to represent truth and falsity are: 'true,' and 'false.'

    • False

      • Defined as 0.

    • True

      • Often defined as 1, but technically has a wider definition, and can be expanded to include any non-0 number. Both the true and false constants should be typed in lowercase letters, in contrast to the HIGH and LOW constants, among others.


    • Most Arduino boards have a pin connected to an on-board LED in series with a resistor. The constant LED_BUILTIN is the number of the pin to which the on-board LED is connected. Most boards have this LED connected to digital pin 13; however, to avoid confusion, I usually affirm this by examining a schematic of the board.

  • Integer Constants:

    • Numbers that are used directly in a sketch, whose value is replaced with the assigned variable at compile time.

    • Example:

      • number = 5 // 5 is an integer constant, so at any later time in the program where I reference 'number,' the compiler will replace that value with '5'

    • Note: integer constants can be written in a variety of forms and different base numbers (ie binary and hexadecimal)

  • Floating-Point Constants:

    • Similar to integer constants with the exception that they refer to numbers containing decimal points.

    • Example:

      • number = .001; // .001 is a floating-point constant


bottom of page