info@artec.bg +359 889 557 337
Artec Robotics
News item

Educational Robotics: Arduino and Raspberry Pi

Home / News / Educational Robotics: Arduino and Raspberry Pi

09.04.2025

A practical guide to building a simple robot with microcontrollers

Arduino and Raspberry Pi are two of the most popular tools in the world of educational robotics. While Arduino is ideal for controlling hardware (motors, sensors), Raspberry Pi adds the ability to do complex data processing and connect to the internet. In this guide we'll show you how to use both to build a simple robot.

Components you'll need

Before you start, gather these basic items:

For Arduino

  1. An Arduino Uno/Nano board.
  2. Motors with wheels (e.g. a geared DC motor).
  3. A motor driver (e.g. L298N).
  4. A distance sensor (e.g. the HC-SR04 ultrasonic sensor).
  5. A battery (9V or LiPo).
  6. Jumper wires and a breadboard.

For Raspberry Pi

  1. A Raspberry Pi (e.g. Model 4B).
  2. A motor shield (e.g. L293D) or GPIO driver.
  3. A camera (e.g. the Raspberry Pi Camera Module).
  4. Sensors (e.g. an infrared sensor).
  5. An SD card with an OS installed (Raspberry Pi OS).

Step 1: Choosing between Arduino and Raspberry Pi

  • Arduino is better suited for:
    • Simple real-time projects (e.g. obstacle avoidance).
    • Controlling motors and sensors without complex code.
  • Raspberry Pi is better for:
    • Robots with computer vision or artificial intelligence.
    • Projects that need an internet connection or multitasking.

Step 2: Building a robot with Arduino

  1. Connecting the motors
  • Connect the DC motors to the L298N driver.
  • Connect the driver to the Arduino:
    • IN1 and IN2 to digital pins (e.g. 5 and 6).
    • ENABLE to a PWM pin (for speed).
  1. Adding an obstacle sensor
  • Connect the HC-SR04 sensor:
    • VCC to 5V, GND to ground.
    • TRIG to pin 9, ECHO to pin 10.

3. Programming the Arduino

Upload this code, which makes the robot avoid obstacles:

#include <Ultrasonic.h>
Ultrasonic ultrasonic(9, 10);

void setup() {
  pinMode(5, OUTPUT); // IN1
  pinMode(6, OUTPUT); // IN2
}

void loop() {
  int distance = ultrasonic.read();
  
  if (distance > 20) {
    // Move forward
    digitalWrite(5, HIGH);
    digitalWrite(6, LOW);
  } else {
    // Turn right
    digitalWrite(5, LOW);
    digitalWrite(6, HIGH);
    delay(500);
  }
}

Step 3: Building a robot with Raspberry Pi

  1. Installing the OS and setup
  • Install Raspberry Pi OS using Raspberry Pi Imager.
  • Enable GPIO and the camera via raspi-config.
  1. Connecting the motors
  • Use a motor shield such as the L293D:
    • Connect GPIO pins 17 and 18 to the shield's inputs.
    • Connect the motors to the outputs.
  1. Writing a Python script

Create a file robot.py with this code:

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT) # IN1
GPIO.setup(18, GPIO.OUT) # IN2

try:
    while True:
        # Move forward
        GPIO.output(17, True)
        GPIO.output(18, False)
        time.sleep(2)
        
        # Stop
        GPIO.output(17, False)
        GPIO.output(18, False)
        time.sleep(1)
except KeyboardInterrupt:
    GPIO.cleanup()

Step 4: Combining Arduino and Raspberry Pi

For more complex projects you can use them together:

  1. The Raspberry Pi processes data (e.g. images) and sends commands to the Arduino.
  2. The Arduino controls the motors and sensors.
  • Connect them via USB or GPIO/UART for communication.

Step 5: Common problems and solutions

  • The motors don't move: Check the connections and power supply.
  • The sensor doesn't work: Make sure it's connected to the right pins.
  • The Raspberry Pi overheats: Use heatsinks or a fan.

Upgrade ideas

  1. Add a camera for object recognition with OpenCV.
  2. Integrate a Bluetooth/WiFi module for remote control.
  3. Make the robot autonomous with algorithms such as SLAM (Simultaneous Localization and Mapping).

Arduino and Raspberry Pi are ideal for getting into the world of robotics. Start with a simple project and gradually add more complex features.

Useful resources:

On the Artec Robotics “News” page you will find a variety of articles and guides on robotics and automation. Here you'll find useful information about the latest technologies, software solutions and programs. They will help you dive deeper into the world of industrial robots and automated systems.

Follow the news from Artec Robotics!

MAKE AN INQUIRY

Arduino and Raspberry Pi
Contact us

Make an inquiry