Building a Raspberry Pi ROS robot from scratch teaches robotics fundamentals — motor control, sensor fusion, mapping, and autonomous navigation — using the same software framework that runs research robots, warehouse bots, and self-driving cars. ROS 2 (Robot Operating System) provides a standardised way to connect sensors, motors, and algorithms into a working robotic system.
Table of Contents
- What Is ROS and Why Use It
- Robot Hardware Bill of Materials
- Chassis Assembly
- Installing ROS 2 on Raspberry Pi
- Motor Control with ROS
- Adding Sensors: LiDAR and IMU
- SLAM: Simultaneous Mapping and Navigation
- Frequently Asked Questions
- Conclusion
What Is ROS and Why Use It
ROS 2 is not an operating system — it is a middleware framework for robotics. It provides libraries and tools for inter-process communication, hardware abstraction, package management, and a vast ecosystem of pre-built algorithms for navigation, perception, and control.
Why ROS matters for learning robotics:
- Industry standard: Used by Amazon Robotics, Boston Dynamics, Universal Robots, and most robotics companies. ROS experience is directly employable.
- Pre-built packages: Navigation stacks, SLAM algorithms, motion planners, and sensor drivers are available as packages — you do not need to implement core algorithms from scratch.
- Simulation: Test your robot in Gazebo simulation before deploying on hardware. This saves time and prevents crashes.
- Community: Thousands of ROS packages, tutorials, and Q&A threads available online.
Robot Hardware Bill of Materials
| Component | Purpose | Approx. Cost (₹) |
|---|---|---|
| Raspberry Pi 5 (8GB) | Main computer | 8,500-9,500 |
| 2WD/4WD robot chassis kit | Frame, wheels, motors | 800-2,500 |
| L298N motor driver | Drive DC motors | 150-300 |
| RPLiDAR A1 (or similar) | 2D LiDAR for mapping | 5,000-8,000 |
| MPU6050 IMU | Orientation sensing | 150-300 |
| Motor encoders | Odometry (distance tracking) | 300-600 |
| 18650 batteries + holder | Power supply | 500-1,000 |
| 5V buck converter | Regulated Pi power | 100-200 |
| Pi Camera Module 3 | Visual recognition (optional) | 3,000-3,500 |
Total estimated cost: ₹18,000-26,000 (with LiDAR), ₹10,000-14,000 (without LiDAR).
Chassis Assembly
Start with a pre-made robot chassis kit — these include an acrylic or aluminium platform, DC motors with gearboxes, wheels, a caster wheel, and mounting hardware. Available from Indian electronics retailers for ₹800-2,500.
Assembly steps:
- Mount the motors to the chassis using the provided brackets and screws
- Attach the wheels to the motor shafts
- Install the caster wheel at the front (for a differential-drive robot)
- Mount the battery holder on the lower deck
- Mount the Pi 5 on the upper deck with standoffs
- Place the L298N motor driver between the battery and motors
- Mount the LiDAR on top for an unobstructed 360° view
Wiring:
- Battery → buck converter → Pi 5 (via USB-C)
- Battery → L298N VCC/GND (motor power)
- L298N IN1/IN2/IN3/IN4 → Pi GPIO pins (motor direction)
- L298N ENA/ENB → Pi PWM pins (motor speed)
- RPLiDAR → Pi USB port
- MPU6050 → Pi I2C (SDA/SCL)
Installing ROS 2 on Raspberry Pi
ROS 2 Humble Hawksbill (or later) supports Ubuntu 22.04, which runs on the Raspberry Pi 5.
# Install Ubuntu 22.04 Server for Raspberry Pi
# Flash using Raspberry Pi Imager
# Add ROS 2 repository
sudo apt install software-properties-common
sudo add-apt-repository universe
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
# Install ROS 2
sudo apt update
sudo apt install ros-humble-ros-base ros-humble-slam-toolbox ros-humble-navigation2
This installs ROS 2 base packages plus SLAM and navigation stacks. Add source /opt/ros/humble/setup.bash to your .bashrc to load ROS in every terminal session.
Motor Control with ROS
In ROS 2, the robot’s movement is controlled by publishing geometry_msgs/Twist messages to the /cmd_vel topic. A motor driver node subscribes to this topic and translates velocity commands into motor PWM signals.
Write a ROS 2 node in Python that:
- Subscribes to
/cmd_velfor velocity commands - Converts linear and angular velocity to left/right wheel speeds (differential drive kinematics)
- Outputs PWM signals to the L298N motor driver via GPIO
- Reads motor encoders and publishes odometry data to
/odom
With this node running, you can control the robot using keyboard teleop:
ros2 run teleop_twist_keyboard teleop_twist_keyboard
Use WASD keys to drive the robot around. This validates motor control before adding autonomous navigation.
Adding Sensors: LiDAR and IMU
RPLiDAR: The RPLiDAR A1 scans 360° and produces a 2D point cloud of distances to obstacles. ROS 2 has a ready-made driver:
sudo apt install ros-humble-rplidar-ros
ros2 launch rplidar_ros rplidar_a1_launch.py
This publishes sensor_msgs/LaserScan data that SLAM and navigation algorithms consume. Visualise the scan in RViz to verify the LiDAR is working correctly.
IMU (MPU6050): The IMU provides accelerometer and gyroscope data, which helps the robot estimate its orientation. This is crucial for accurate odometry on slippery or uneven surfaces where wheel encoders alone are insufficient.
SLAM: Simultaneous Mapping and Navigation
SLAM allows the robot to build a map of its environment while simultaneously determining its position within that map. The slam_toolbox package provides state-of-the-art SLAM on ROS 2.
# Launch SLAM
ros2 launch slam_toolbox online_async_launch.py
Drive the robot around your room or office using keyboard teleop. SLAM builds a 2D occupancy grid map in real time — visible in RViz as walls, furniture, and doorways appear on the map.
Once the map is complete, save it and switch to localisation mode. Now launch the Navigation 2 stack:
ros2 launch nav2_bringup navigation_launch.py use_sim_time:=False
Click a goal point on the map in RViz. The robot plans a path around obstacles and drives to the goal autonomously — avoiding furniture, walls, and people using real-time LiDAR data.
Frequently Asked Questions
Can a Raspberry Pi 5 run ROS 2 smoothly?
Yes. The Pi 5 8GB runs ROS 2 Humble with SLAM and Navigation 2 at acceptable performance. Map building with RPLiDAR works in real time. For very large maps or computationally intensive perception algorithms, consider offloading heavy processing to a laptop via ROS 2’s distributed architecture.
Do I need a LiDAR, or can I use ultrasonic sensors?
LiDAR is strongly recommended for SLAM — it provides 360° distance data at high resolution. Ultrasonic sensors (like HC-SR04) give single-point distance measurements and cannot build maps. For a budget robot without SLAM, ultrasonic sensors work for basic obstacle avoidance.
What programming language is ROS 2 written in?
ROS 2 nodes can be written in Python or C++. Python is easier for beginners and adequate for most robotics learning. C++ offers better performance for real-time control and computationally intensive algorithms.
How long does the battery last?
With a 4x 18650 battery pack (3.7V, 2600mAh each, series-parallel configuration for 7.4V), expect 1-2 hours of active driving with LiDAR. The Pi 5 is the largest power consumer. For longer runtime, use larger capacity batteries or a LiPo pack.
Can I simulate the robot before building it?
Yes. Gazebo (ROS 2’s simulation environment) lets you create a virtual robot with the same sensors and actuators. Test SLAM, navigation, and custom algorithms entirely in simulation, then deploy the same code to your physical robot.
Conclusion
Building a ROS 2 robot with a Raspberry Pi 5 is the most practical way to learn robotics — you work with the same framework used in industry, build real hardware, and develop skills in motor control, sensor fusion, and autonomous navigation. The total cost of ₹15,000-25,000 is a fraction of educational robotics kits, and the skills transfer directly to professional robotics careers.
Start with a basic chassis and motor control, add LiDAR for mapping, and work toward autonomous navigation. Each stage teaches new concepts while producing a tangible, working robot.
Find Raspberry Pi boards and robotics components at Zbotic — fast shipping across India.
Add comment