Skip to content

samshoni/ros2-arduino-bridge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ROS2-Arduino-Bridge

A simple yet powerful bridge between ROS 2 and Arduino.
This project demonstrates how to control an Arduino-connected LED from a ROS 2 node over serial communication.
It serves as a foundation for integrating embedded hardware (sensors, actuators) with ROS 2 robotics middleware.


πŸš€ Features

  • ROS 2 node written in Python (led_logic.py)
  • Serial communication with Arduino (/dev/ttyUSB0)
  • Control a physical LED using ROS 2 messages
  • Modular design (easily extendable for sensors, motors, etc.)

πŸ›  Hardware Setup

  • Arduino Mega 2560
  • LED + 220Ξ© resistor
  • Breadboard + jumper wires
  • USB cable (Arduino ↔ PC)

Wiring

  • LED anode β†’ Arduino Pin 13
  • LED cathode β†’ GND

πŸ’» Software Setup

1. Arduino

Upload the Arduino sketch (led.ino) from the arduino_code/ folder:

void setup() {
  pinMode(13, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  if (Serial.available()) {
    char c = Serial.read();
    if (c == '1') digitalWrite(13, HIGH);
    if (c == '0') digitalWrite(13, LOW);
  }
}

2. ROS 2 Workspace

cd ~/ros2_ws
colcon build
source install/setup.bash

3. Run the ROS 2 Node

ros2 run my_arduino_pkg led_logic

πŸ“‚ Repository Structure

ros2-arduino-bridge/
β”œβ”€β”€ my_arduino_pkg/        # ROS 2 package
β”‚   β”œβ”€β”€ package.xml
β”‚   β”œβ”€β”€ setup.py
β”‚   └── my_arduino_pkg/led_logic.py
β”œβ”€β”€ arduino_code/          # Arduino sketches
β”‚   └── led.ino
└── README.md

πŸ”Ž Example Output

[INFO] [led_logic]: Sending 1 (LED ON)
[INFO] [led_logic]: Sending 0 (LED OFF)

And the LED blinks physically on the Arduino board ✨
🌟 Future Extensions

    Add a buzzer controlled by ROS 2 topics

    Publish ultrasonic sensor distance readings to ROS 2

    Expand into motor driver control for a mobile robot

πŸ‘€ Author

Sam Shoni

    GitHub: samshoni

LinkedIn: Sam Shoni

About

Integrating Arduino with ROS 2: serial communication, message handling, and real robot control

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages