Arduino built-in functions are the core commands and routines used to control a board, read inputs, produce outputs, manage time, and communicate with other devices. The most familiar are pinMode(), digitalWrite(), digitalRead(), analogRead(), analogWrite(), delay(), and millis(); which features they support and how they behave can depend on the board and its Arduino core.
What Arduino means by built-in functions
Arduino sketches are written in C++, with Arduino’s board-specific core providing a familiar set of functions and constants. These functions are available when you select a compatible board in the Arduino IDE, without installing a separate library for each basic operation. They are often called Arduino functions or the Arduino language, although Arduino is not a completely separate programming language from C++.
Some names that beginners call functions are technically constants, keywords, or object methods. For example, HIGH and LOW are constants used to represent logic levels, while Serial.begin() and Serial.println() are methods belonging to the Serial object. The distinction matters when learning C++, but the practical idea is straightforward: Arduino’s core and standard libraries provide common tools for communicating with board hardware.
There is no single short list that applies identically to every Arduino-compatible board. A classic AVR-based Uno, a newer Uno R4, and boards using other microcontrollers may have different pins, input ranges, timer behavior, and core-specific additions. The selected board’s documentation is the authority when a function’s exact capabilities matter.
How setup() and loop() organize a sketch
Most Arduino sketches use two special functions. The core calls setup() once after the board starts or resets, then repeatedly calls loop() while the board is running. They are not ordinary commands that a sketch must call itself; they are the entry points the Arduino runtime expects.
setup()is where a sketch commonly configures pins, starts serial communication, and initializes sensors or displays.loop()contains work that should be checked or performed repeatedly, such as reading a button and updating an output.
A minimal structure is void setup() { } followed by void loop() { }. The void indicates that each function returns no value. You can define additional functions of your own and call them from either place; the Arduino core does not require every useful routine to have a special built-in name.
Digital pins: pinMode(), digitalWrite(), and digitalRead()
Digital pins work with two logic states, commonly represented in sketches as HIGH and LOW. To use a pin, configure it with pinMode(pin, mode). Common modes include OUTPUT, INPUT, and, on many Arduino boards, INPUT_PULLUP, which enables an internal pull-up resistor.
For example, pinMode(LED_BUILTIN, OUTPUT) configures the board’s built-in LED pin as an output. Then digitalWrite(LED_BUILTIN, HIGH) requests a high output level, and digitalWrite(LED_BUILTIN, LOW) requests a low one. LED_BUILTIN is a board-provided constant, so it is often more portable than hard-coding a pin number, though a board might not have an onboard LED.
To read a switch, configure its pin as an input and use digitalRead(pin). With INPUT_PULLUP, the internal resistor pulls the unpressed input high; a button wired between the input and ground typically makes the reading LOW when pressed. This reversed logic surprises many first-time users. An input left electrically unconnected can fluctuate, so use an appropriate pull-up or pull-down circuit rather than assuming it will read reliably.
Analog input and PWM output
analogRead(pin) samples a voltage on a pin that supports analog input and returns an integer measurement. It does not usually return volts directly. The range depends on the board’s ADC resolution and configuration: a classic Uno commonly returns values from 0 to 1023, while other boards can use different ranges. Reference voltage and input limits also matter, so consult the board specifications before connecting a sensor.
analogWrite(pin, value) is a common source of confusion. On many Arduino boards it produces pulse-width modulation (PWM), a rapidly switched digital signal whose duty cycle changes with the value. It is not necessarily a true, steady analog voltage from a digital pin. A PWM-capable pin can use this technique to control, for example, LED brightness or a suitable motor driver. The available pins, resolution, and valid value range can differ by board.
- Check the pinout for analog input pins before calling
analogRead(). - Check which pins support PWM before relying on
analogWrite(). - Do not connect a motor directly to a GPIO pin; use a suitable driver and observe voltage and current limits.
For an actual adjustable analog voltage, a board needs a DAC output or an external circuit such as a filter. Whether a board has DAC pins is model-specific. Thus, the names of these two functions do not guarantee identical hardware behavior across the Arduino range.
Timing functions and non-blocking code
delay(milliseconds) pauses the sketch for the requested duration. It is convenient for a simple blink, but during the pause the sketch does not proceed through its normal loop() work. This can make it slow to respond to a button, sensor, or communication task. Some hardware features may continue independently, but delay() is still a blocking wait from the sketch’s perspective.
millis() returns the number of milliseconds since the board began running the current program. A common alternative is to check elapsed time and perform an action when an interval has passed, allowing the loop to keep doing other work. The safe comparison pattern uses unsigned subtraction: if (millis() - previousTime >= interval). Save the current time in previousTime when the action occurs. This pattern continues to work when the counter wraps around, provided the interval is within the supported range.
micros() provides elapsed time in microseconds, with precision and rollover timing depending on the board and core. It is useful for shorter intervals, but should not be mistaken for unlimited precision or a universally exact stopwatch. Use the timing function that matches the task, and avoid assuming that timing resolution is identical across boards.
Communication, pulses, and other useful functions
The Serial API is widely used for debugging and for communication over a board’s serial interface. A sketch typically calls Serial.begin(9600) in setup() to select a baud rate, then uses methods such as Serial.print() and Serial.println() to send readable data. The number in begin() must match the other end’s settings. USB connection behavior varies by board; some boards expose a native USB interface, while others use a separate USB-to-serial component.
Other core functions address specific jobs:
tone(pin, frequency)andnoTone(pin)generate and stop a tone on supported hardware. Timer use and pin behavior can vary.pulseIn(pin, value)measures the duration of a pulse. It waits for the pulse and can time out, so use its timeout option when an indefinite wait would be a problem.shiftOut()sends bits serially to compatible external hardware, whileshiftIn()reads bits from a device using the corresponding signaling approach.random()generates pseudo-random values, andrandomSeed()can initialize its sequence. It is not a cryptographic random-number source.constrain(),map(),min(), andmax()help work with numeric values. In particular,map()rescales a value but does not automatically limit it to the destination range.
Functions such as attachInterrupt() and detachInterrupt() let supported pins respond to events outside the normal loop sequence. Interrupt service routines should be short. On some boards, data shared between an interrupt routine and the main sketch needs careful handling; check the core documentation and examples for the board in use.
Board differences and choosing the right function
Before copying an example, identify the selected board and check its pinout and core documentation. A function name may be shared while its usable pins, resolution, timing, or electrical limits differ. Board variants can also offer additional APIs that are not portable to every Arduino model. The IDE’s board selection affects how the sketch is compiled and which core definitions are available.
Choose a function based on the hardware operation, not just its name. For a digital switch, use a digital input and an appropriate pull resistor. For a varying sensor voltage, use an analog input and interpret its result using the board’s ADC range. For dimming, verify that the output pin supports PWM, and for a true analog voltage, verify that a DAC is available or plan an external circuit. For timing, use millis() when other loop tasks need to remain responsive.
When a function is missing or behaves differently than an online example, check whether the example assumes a different board, a different Arduino core, or an added library. The built-in core API is not the same as every function found in a tutorial: libraries add their own functions and methods, and their names may only be available after the library is installed and included.
Common mistakes and practical checks
Many problems attributed to a broken function are actually caused by wiring, configuration, or assumptions about the board. A few checks can quickly narrow down the cause:
- Confirm the board and port selected in the IDE, then check the pin number against that board’s pinout.
- Call
pinMode()for pins that need a specific input or output mode; do not expect an unconfigured pin to behave as an output. - Remember that
digitalRead()on a pull-up input usually returnsLOWwhen a switch connects the pin to ground. - Do not treat a PWM value as a voltage measurement, or assume every digital pin supports PWM.
- Use the correct analog range and reference when interpreting
analogRead()results; a raw count is not automatically a value in volts. - Use elapsed-time checks instead of long delays when a sketch must remain responsive.
- Check power and electrical limits. Arduino pins are for signal-level connections, not for directly powering high-current loads.
Also remember that Arduino function names are case-sensitive: digitalWrite() is not the same identifier as Digitalwrite(). Compiler messages can point to a misspelled name, missing library, or unsupported API. Reading the first error and checking the board-specific reference is usually more useful than changing unrelated code.
Frequently Asked Questions
What are the most commonly used Arduino built-in functions?
The basic set includes pinMode(), digitalWrite(), digitalRead(), analogRead(), analogWrite(), delay(), and millis(). Serial methods such as Serial.println() are also common, though they are methods of an object rather than standalone functions.
Are Arduino functions the same on every board?
No. Many core functions have familiar names across boards, but supported pins, ranges, timing, and hardware behavior can differ. Check the documentation and pinout for the exact board and core selected for the sketch.
Is analogWrite() a real analog output?
Usually not. On many boards it produces PWM, which rapidly switches a digital output to create a controllable duty cycle. A true analog voltage requires a DAC-capable output or an external circuit.
What is the difference between delay() and millis()?delay() blocks the sketch for a period, while millis() lets the loop check elapsed time and continue handling other work. Use the latter for responsive sketches with multiple tasks.
Do I need to install a library to use Arduino built-in functions?
Basic functions supplied by the selected Arduino core are available without installing a separate library. Functions for a particular sensor, display, or other device may require a library, which must be installed and included as its documentation describes.
Related
- How to Add Transitions in PowerPoint: Steps and Tips
- T Balance in Accounting: Meaning, Examples, and Uses
- Is Split Fiction Cross-Platform? Crossplay Explained
Try it: the Formula Explainer: paste any formula and see each function and reference in plain English.
More in Formulas & functions
- AVERAGE vs AVERAGEIF in Excel: Which Should You Use?Use AVERAGE to find the mean of numeric values in a range; use AVERAGEIF to average only values…
- How to Find a Z Value in Excel: Formulas and ExamplesTo calculate a z-score for a value in Excel, subtract the dataset mean from the value and divide…
- COUNTIF in Excel: How It Works and How to Use ItExcel’s COUNTIF function counts cells in a range that meet one condition. Give it a range to inspect…
- Excel Shortcut to Paste a Formula: Keys and Tips in ExcelIn Excel for Microsoft 365 on Windows, copy the formula cell, select the destination, then press Ctrl+Alt+V, press…
- Excel MATCH With Multiple Criteria: Formulas That WorkYes. In Microsoft Excel for Microsoft 365, combine the criteria into a TRUE/FALSE test, use MATCH to find…
- Excel Wildcard SUMIF Formula Examples That Match TextTo total values for text that contains a word, use SUMIF with asterisks around the word: with product…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.