Javatpoint Logo
Javatpoint Logo

What are constants?

The constants in Arduino are defined as the predefined expressions. It makes the code easy to read.

The constants in Arduino are defined as:

Logical level Constants

The logical level constants are true or false.

The value of true and false are defined as 1 and 0. Any non-zero integer is determined as true in terms of Boolean language. The true and false constants are type in lowercase rather than uppercase (such as HIGH, LOW, etc.).

Pin level Constants

The digital pins can take two value HIGH or LOW.

In Arduino, the pin is configured as INPUT or OUTPUT using the pinMode() function. The pin is further made HIGH or LOW using the digitalWrite() function.


The board includes two types of voltage pins to provide HIGH value, which are listed below:

  • 5V
  • 3V

Some boards include only 5V pins, while some include 3.3V.

Some boards consist of both 5V and 3.3V pins. For example, Arduino UNO R3.

The pin configured as HIGH is set at either 5V or 3.3V.

The pins are configured at the 5V or 3.3V depending on:

  • for voltage > 3.0V (presented at 5V pin)
  • for voltage > 2.0V (presented at 3.3V pin)


The pin configured as LOW is set at 0 Volts.

The pins are configured at the 5V or 3.3V depending on:

  • for voltage < 1.5V (presented at 5V pin)
  • for voltage < 1V (presented at 3.3V pin)


The Arduino boards have built-in LED connected in series with the resistor. The particular pin number is defined with the constant name called LED_BUILTIN.

Most Arduino boards have the LED_BUILTIN connected to Pin number 13.

Constant Keyword

The name const represents the constant keyword. It modifies the behavior of the variables in our program. It further makes the variable as 'read-only'.

The variable will remain the same as other variables, but its value cannot be changed.

It means we cannot modify the constant. For example,

The const keyword is considered superior compared to the #define keyword because it obeys the rules of the variable scope.

For example,

Consider the below code:

Output: 11.36

Note: We can either use const or #define in the case of strings and numeric constants. But we can only use const for arrays.


The #define in Arduino is used to give a name to the constant value. It does not take any memory space on the chip.

At the compile time, the compiler will replace the predefined value in the program to the constants with the defined value.

The syntax is:


nameOFconstant: It is the name of the macro or constant to define

value: It includes the value assigned to the constant or macro.

For example,

Note: The #define does not require any semicolon. Hence, we do not need to specify any semicolon after the #define. Otherwise, the compiler will show errors.

The incorrect declarations of #define can be:

Next TopicArduino Operators

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA