How to Program on Arduino with Raspberry Pi

Both Arduino and Raspberry Pi are powerful tools for electronics and automation projects, but they serve different purposes. Arduino excels at direct hardware control, while Raspberry Pi is perfect for running a full operating system and handling more complex logic.

By combining the two, you can get the best of both worlds — using your Raspberry Pi to write, upload, and control Arduino sketches directly. In this guide, we’ll show you how to set up and program your Arduino board using your Raspberry Pi.

What You’ll Need

Before starting, make sure you have the following:

  • A Raspberry Pi (any model with USB ports, such as Pi 3 or Pi 4)
  • An Arduino board (e.g., Arduino Uno, Nano, or Mega)
  • A USB cable compatible with your Arduino
  • A microSD card with Raspberry Pi OS installed
  • A stable internet connection for installing dependencies

Optional but recommended: a keyboard, mouse, and monitor connected to your Raspberry Pi.

Step 1: Update Your Raspberry Pi

First, make sure your Raspberry Pi is up to date. Open the terminal and run:

sudo apt update
sudo apt upgrade -y

This ensures you have the latest packages and security updates installed.

Step 2: Install the Arduino IDE

The Arduino IDE can be installed directly from the Raspberry Pi repository. In your terminal, type:

sudo apt install arduino -y

Once the installation finishes, you can launch the IDE either from the Programming menu on the desktop or by typing:

arduino

If you prefer, you can also install the newer Arduino IDE 2.0 version using the official AppImage from Arduino’s website.

Step 3: Connect Arduino to Raspberry Pi

Next, plug your Arduino board into one of the Raspberry Pi’s USB ports using the USB cable.
To verify the connection, run the following command:

ls /dev/tty*

You should see a device listed as /dev/ttyUSB0 or /dev/ttyACM0.
That’s your Arduino’s serial port.

Step 4: Grant Serial Port Access

To allow the Arduino IDE to communicate with your Arduino board, you need to add your user to the dialout group:

sudo usermod -aG dialout $USER

After running this command, reboot your Raspberry Pi:

sudo reboot

This step ensures your user account has permission to upload code to the Arduino.

Step 5: Open the Arduino IDE and Select Your Board

After rebooting, open the Arduino IDE on your Raspberry Pi. Then:

  1. Go to Tools > Board and select your Arduino model (e.g., Arduino Uno).
  2. Under Tools > Port, choose the serial port you found earlier (e.g., /dev/ttyACM0).

Once configured, you’re ready to upload your first sketch.

Step 6: Write and Upload Your Code

Let’s test the setup with the classic Blink example.

  1. Go to File > Examples > 01.Basics > Blink.
  2. Click the Upload button (the right arrow icon).

The IDE will compile and upload the sketch to your Arduino.
If everything is working, the onboard LED on your Arduino will start blinking at one-second intervals.

Step 7: Program Arduino from the Command Line (Optional)

If you prefer using the terminal instead of the graphical IDE, you can install arduino-cli — the official command-line tool for Arduino.

Run the following commands:

curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh
sudo mv bin/arduino-cli /usr/local/bin/

Initialize it with:

arduino-cli config init
arduino-cli core update-index
arduino-cli core install arduino:avr

Now you can compile and upload sketches directly from the terminal:

arduino-cli compile --fqbn arduino:avr:uno Blink
arduino-cli upload -p /dev/ttyACM0 --fqbn arduino:avr:uno Blink

This is ideal for headless Raspberry Pi setups or automated IoT environments.

Wrapping Up

Programming an Arduino with a Raspberry Pi gives you a powerful hybrid setup for embedded development. The Raspberry Pi handles higher-level logic and networking, while the Arduino provides precise control over sensors, motors, and other hardware components.

Once your environment is configured, you can write, upload, and automate Arduino code seamlessly — all from your Raspberry Pi. It’s a compact, efficient, and flexible development workflow perfect for IoT projects, robotics, and learning electronics.

Posted by Arpita

With a background in Computer Science, she is passionate about sharing practical programming tips and tech know-how. From writing clean code to solving everyday tech problems, she breaks down complex topics into approachable guides that help others learn and grow.

X