Arduino development from concept to working robot

A practical path through Arduino for robotics: the board, the programming model, reading sensors, driving actuators and structuring a project.

Arduino is the easiest way into robotics and small mechatronic systems. It is cheap, open-source and supported by a huge community, so almost any problem you run into has already been solved and shared by someone. This post takes you from the board itself to a small working robot.

Why start with Arduino?

  • Open-source: the hardware designs and software are free to use and modify.
  • Beginner-friendly: plug it into USB, write a few lines, press upload.
  • Huge community: tutorials, libraries and forum answers for nearly every sensor and motor.
  • Grows with you: the same skills carry over to ESP32, STM32 and other microcontrollers.

The board

The Arduino Uno is the classic starting board:

Feature Arduino Uno
Microcontroller ATmega328P, 16 MHz
Digital pins 14 (6 of them can output PWM)
Analog inputs 6 (10-bit, values 0 to 1023)
Memory 32 KB flash for your program, 2 KB RAM
Logic voltage 5 V

The Nano is the same chip on a smaller board; the Mega has many more pins for bigger robots.

The programming model

Every Arduino program (a sketch) has two functions: setup() runs once at power-on, and loop() runs again and again for as long as the board has power.

C++
void setup() {
  pinMode(LED_BUILTIN, OUTPUT);   // runs once
}

void loop() {                     // runs forever
  digitalWrite(LED_BUILTIN, HIGH);
  delay(500);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
}

That loop is the same sense, think, act cycle every robot runs.

Reading sensors

An analog pin turns a voltage between 0 and 5 V into a number between 0 and 1023:

$$ \text{reading} = \frac{V_\text{in}}{5\ \text{V}} \times 1023 \qquad\Longleftrightarrow\qquad V_\text{in} = \frac{\text{reading}}{1023} \times 5\ \text{V} $$

So a reading of 512 means about 2.5 V. Digital sensors (buttons, ultrasonic sensors) use digitalRead() or timing functions such as pulseIn(), and smarter sensors (IMUs, temperature sensors) talk over I²C or SPI with a ready-made library.

Driving actuators

Arduino pins can only supply a few milliamps, so motors always need a driver in between:

Actuator Driver Arduino side
LED Series resistor digitalWrite()
Servo motor None (signal only), separate power for the servo Servo library
DC motor H-bridge (L298N, TB6612) PWM for speed, two pins for direction
Stepper motor Stepper driver (A4988, DRV8825) Step and direction pins

PWM (pulse-width modulation) switches a pin on and off very fast. The duty cycle, the fraction of time it is on, sets the average voltage the motor sees: analogWrite(pin, 128) gives about 50 %.

Choosing an LED resistor with Ohm's law, for a red LED (about 2 V) at 20 mA on a 5 V pin:

$$ R = \frac{V_\text{supply} - V_\text{LED}}{I} = \frac{5 - 2}{0.020} = 150\ \Omega $$

Pick the next larger standard value, such as 220 Ω, to be safe.

Putting it together: an obstacle-avoiding robot

$$ \underbrace{\text{Ultrasonic sensor}}_{\text{measures distance}} \;\rightarrow\; \underbrace{\text{Arduino}}_{\text{decides}} \;\rightarrow\; \underbrace{\text{Motor driver}}_{\text{supplies power}} \;\rightarrow\; \underbrace{\text{Two DC motors}}_{\text{turn the wheels}} $$

C++
const int TRIG = 9, ECHO = 10;

long distanceCm() {
  digitalWrite(TRIG, LOW);  delayMicroseconds(2);
  digitalWrite(TRIG, HIGH); delayMicroseconds(10);
  digitalWrite(TRIG, LOW);
  return pulseIn(ECHO, HIGH) / 58;   // echo time in µs → distance in cm
}

void setup() {
  pinMode(TRIG, OUTPUT);
  pinMode(ECHO, INPUT);
  // set up the motor driver pins here
}

void loop() {
  if (distanceCm() < 20) {
    // obstacle: stop, turn, then continue
  } else {
    // path is clear: drive forward
  }
}

Structuring a bigger project

  • One function per job: readSensors(), decide(), driveMotors(). loop() just calls them in order.
  • Avoid long delay() calls: use millis() to check the time, so the robot keeps reading its sensors while it waits.
  • Separate power: motors on their own supply, with a common ground to the Arduino.
  • Design the mechanics alongside: draw brackets and mounts in CAD (SolidWorks, Fusion 360), 3D-print them, and test early.
  • Plan the next step: when you need cameras or heavier computing, add a Raspberry Pi running ROS 2 and keep the Arduino for real-time motor and sensor control.

What's in a starter kit?

An Arduino board, a breadboard, jumper wires, LEDs and resistors, a servo, a DC motor with a driver, a few sensors (ultrasonic, temperature, light) and a USB cable. That is enough for dozens of projects.

Watch the video

For a quick visual introduction, see Arduino basics on YouTube.

Basheer Al-Tawil is a PhD researcher in Robotics and AI at Otto von Guericke University. Found a mistake or have a question? Write to me.

Browse by topic