Arduino
Arduino
Definition: An open-source hardware and software platform built around simple microcontroller boards, widely used for hobbyist electronics and rapid embedded prototyping.
How It Works
- Boards are built around a microcontroller, with easily accessible pins for connecting sensors and actuators
- Programmed in a simplified C/C++ dialect through the Arduino IDE, designed to be approachable for beginners, compiled down to native machine code that runs directly on the microcontroller
- A massive library ecosystem means most common sensors and modules already have ready-to-use code available, install a library, call three functions, and a sensor is reading data
- Every Arduino sketch (program) is structured around exactly two required functions:
setup(), which runs once at power-on, andloop(), which repeats forever afterward - Digital pins read or write simple HIGH/LOW (5V/0V or 3.3V/0V) signals; analog input pins read a continuous voltage via an onboard analog-to-digital converter (ADC), typically 10-bit (0-1023) resolution
- The Arduino IDE uses
avr-gcc(or the relevant toolchain for non-AVR boards) under the hood, and the “sketch” abstraction hides most of the compiler and linker flags a raw embedded C project would expose directly
Under the Hood
setup() never runs again after the board finishes it once, everything that needs to happen continuously lives in loop(), which the microcontroller executes millions of times over its lifetime.
Worked example 1: loop iteration rate
- Given: an Arduino Uno (16MHz ATmega328P) runs a
loop()that reads one analog sensor (analogRead(), ~100 microseconds) and writes one digital pin (digitalWrite(), a few microseconds), with no added delay - Step: total loop body time ≈ 100-110 microseconds per iteration
- Step: iterations per second ≈ 1,000,000 microseconds / 110 microseconds ≈ 9,000 loop iterations per second
- Answer: without an explicit
delay(), this loop runs thousands of times a second, far faster than most sensors or actuators actually need, which is why almost every real sketch adds adelay()or a non-blocking timing check to pace itself appropriately
Worked example 2: analog-to-digital resolution
- Given: an Arduino Uno’s ADC has 10-bit resolution and its analog reference voltage is 5V
- Step: 10-bit resolution means 2^10 = 1,024 discrete possible readings, from 0 to 1023
- Step: voltage per step = 5V / 1024 ≈ 0.00488V (about 4.88mV) per increment of
analogRead()’s returned value - Answer: an
analogRead()value of 512 corresponds to roughly 512 × 0.00488V ≈ 2.5V at the pin, and the smallest voltage change the board can actually distinguish is about 4.88mV, finer changes are simply invisible to this ADC
Worked example 3: powering an actuator safely
- Given: a small DC motor draws 250mA when running, and an Arduino Uno digital pin is rated for a maximum of about 40mA
- Step: wiring the motor directly to the pin would attempt to draw 250mA through a pin rated for 40mA, roughly 6x over the safe limit, likely damaging the microcontroller’s output driver
- Step: the correct approach uses the pin only to switch a transistor or MOSFET (drawing a few mA to turn it on), which then switches the motor’s own separate power supply carrying the full 250mA
- Answer: the pin never carries more than its rated current, the transistor/MOSFET does the heavy lifting, this pattern (small control signal switching a larger load through a driver component) is standard for any actuator beyond an LED
Power and I/O Limits
- Most 5V Arduino boards (Uno, Nano, Mega) can source or sink roughly 20mA per pin continuously, 40mA absolute maximum, and about 200mA total across all pins combined
- 3.3V boards (many ARM-based Arduino-compatible boards) have similar or lower per-pin limits and are not 5V-tolerant on their inputs, connecting a 5V sensor directly can damage a 3.3V board
- USB power alone (typically 500mA available) is enough for the board itself plus small sensors, but motors, multiple LEDs, or wireless modules under load usually need a separate, adequately rated power supply
- A flyback diode is required across any inductive load (a motor, a relay coil) to absorb the voltage spike generated when it’s switched off, without one that spike can damage the switching transistor or the board
- Battery-powered projects need to account for the board’s own idle current draw (a few mA to tens of mA depending on the board), not just the actuator’s, since that idle draw runs continuously between actuator activations
Why It Matters
- Dramatically lowered the barrier to entry for physical computing, turning “build a device that senses and reacts to the world” into a weekend project instead of requiring deep electrical engineering knowledge
- Its open-source hardware design spawned an entire ecosystem of compatible and derivative boards (ESP32-based boards, clones, shields), instead of locking users into one vendor’s proprietary hardware
- Shield boards (add-on hardware that stacks directly onto the pin headers) let a project gain new capabilities, motor control, GPS, wireless, without any custom PCB design work
- The
setup()/loop()structure is simple enough to teach programming fundamentals to complete beginners while still being a real, deployable embedded platform
Common Pitfalls
- Trying to run genuinely compute-heavy or networked applications on it, Arduino’s constrained hardware isn’t meant for that, a Raspberry Pi fits that need better
- Underestimating power and current limits when wiring up motors or other demanding components directly to its pins, most digital pins can only safely source/sink around 20-40mA, far below what a small motor draws
- Using
delay()for timing insideloop(), which blocks the entire program and makes it unable to respond to other events (a button press, an interrupt) during that pause - Forgetting that
analogRead()resolution and reference voltage vary by board (Uno: 10-bit/5V, many ARM-based boards: 12-bit or higher/3.3V), so code tuned for one board can silently misbehave on another - Not debouncing mechanical switches, a single physical press can register as several rapid digital transitions due to contact bounce, causing a
loop()to see multiple presses for one press - Connecting a 5V board’s output directly into a 3.3V-only board’s input, exceeding its input voltage tolerance and risking permanent damage
- Wiring an inductive load (a motor, a relay coil) without a flyback diode, letting the voltage spike on switch-off damage the driving transistor or the board itself
- Assuming library code that works on an Uno will behave identically on an ESP32 or other non-AVR board, pin numbering, ADC resolution, and available memory can all differ significantly between architectures
Comparison
| Board | Microcontroller | Clock speed | Typical use |
|---|---|---|---|
| Arduino Uno | ATmega328P (8-bit) | 16MHz | Learning, simple sensor/actuator projects |
| Arduino Nano | ATmega328P (8-bit) | 16MHz | Same as Uno, smaller form factor |
| Arduino Mega | ATmega2560 (8-bit) | 16MHz | Projects needing many I/O pins |
| ESP32 (Arduino-compatible) | Dual-core Xtensa (32-bit) | 240MHz | Wi-Fi/Bluetooth-connected IoT projects |
| Raspberry Pi Pico (Arduino-compatible) | RP2040 (32-bit dual-core) | 133MHz | Higher-performance microcontroller projects |
| Arduino Leonardo | ATmega32u4 (8-bit) | 16MHz | Projects needing native USB HID (acting as a keyboard/mouse) |
Example
A hobbyist builds a plant-watering system: an Arduino reads a soil moisture sensor’s analog voltage through analogRead(), compares it against a threshold in loop(), and actuates a small pump via a relay when the soil gets too dry. The Arduino Uno remains the most common starting board for this kind of project because of its simplicity, extensive tutorials, and huge base of compatible shields (add-on boards) and libraries.
void setup() {
pinMode(PUMP_PIN, OUTPUT);
}
void loop() {
int moisture = analogRead(SENSOR_PIN);
digitalWrite(PUMP_PIN, moisture < DRY_THRESHOLD ? HIGH : LOW);
delay(60000); // check once a minute
}
That delay(60000) is a simple, if blocking, way to pace a sketch that doesn’t need to respond to anything else while it waits.
Common Interview Questions
- What are
setup()andloop(), and why does every sketch need them? —setup()runs once for initialization (pin modes, serial communication, sensor configuration),loop()runs forever afterward and contains the program’s actual repeating behavior - Why does Arduino code avoid using
delay()in more advanced sketches? —delay()blocks the entire program, preventing it from reading input or responding to events during the pause; non-blocking timing usingmillis()comparisons lets the loop stay responsive - What’s the difference between a digital and an analog pin on an Arduino? — digital pins read/write simple HIGH/LOW signals, analog input pins read a continuous voltage through an onboard ADC and return a proportional numeric value
- Why is Arduino often paired with a Raspberry Pi rather than treated as a substitute for one? — Arduino excels at low-level, real-time, low-power sensor/actuator control, while a Raspberry Pi handles the compute-heavy or networked side (a dashboard, machine learning inference), each doing what it’s actually good at
- What happens if you draw more current from a pin than it’s rated for? — it can damage or destroy the microcontroller’s output driver for that pin, which is why current-hungry actuators are switched through a transistor, MOSFET, or relay instead of being wired directly to a pin
- Why does an inductive load need a flyback diode? — switching off current through a coil generates a brief high-voltage spike as the collapsing magnetic field induces a reverse voltage, the diode gives that spike a safe path to dissipate instead of arcing back through the switching transistor
- What’s the practical memory ceiling that limits Arduino Uno programs? — 2KB of SRAM holds all runtime variables and the call stack combined, large arrays, deep recursion, or heavy use of the String class can exhaust it quickly and cause unpredictable crashes
FAQ
- Does Arduino run an operating system? — no, standard Arduino boards run “bare metal,”
loop()is the entire program, there’s no OS scheduling multiple processes underneath it - Can Arduino connect to Wi-Fi or the internet? — the base Uno/Nano/Mega cannot on their own, but Arduino-compatible boards like the ESP32 or add-on Wi-Fi shields extend the same programming model to networked projects, often publishing sensor data over MQTT
- What language is Arduino actually written in? — C/C++, with a thin wrapper library (the “Arduino core”) providing simplified functions like
digitalWrite()andanalogRead()on top of the raw microcontroller registers - How much memory does a typical Arduino Uno have? — 32KB flash for the program, 2KB of SRAM for variables at runtime, and 1KB of EEPROM for data that should persist across power cycles, all tiny compared to any general-purpose computer
- Is Arduino only for hobbyists? — no, its simplicity makes it common in prototyping even at professional and educational levels, though shipped commercial products more often move to a custom board once the design is finalized
- Can multiple sensors and actuators run from one Arduino at once? — yes, within the limits of available pins, total current budget, and how much time each sensor’s read takes inside
loop(), dozens of simple devices can share one board
History
The Arduino project began in 2005 at the Interaction Design Institute Ivrea in Italy, created specifically to give design students without an electrical engineering background an approachable way to build interactive hardware prototypes. Its open-source hardware license meant anyone could legally manufacture compatible boards, which is why the ecosystem grew well beyond the original Arduino company’s own boards into countless clones, derivatives, and Arduino-compatible platforms like the ESP32 and Raspberry Pi Pico.
Related Terms
Referenced by