How to Connect and Interface a Raspberry Pi with an Arduino

Sometimes you may need to connect an Arduino to a Raspberry Pi. For example, if you have sensors, motors, and actuators, you can connect these to the Arduino and make the Arduino send values to and from the Raspberry Pi. This way, we can separate the computing intensive tasks (Done by the Raspberry Pi) and controlling tasks (Done by the Arduino).

In this tutorial, we will connect an Arduino to a Raspberry Pi and have the Arduino send “Hello from Arduino” to the Raspberry Pi and the Raspberry Pi will blink an LED upon receiving the command from the Arduino.



For communication, we will use simple serial communication over USB cable.

So, let’s get started.

Connect the LED to pin number 11 as shown in the picture below.



Turn on the Raspberry Pi and open Python 3 in a new window

Write the following code in the new window and save it. (Saving to your desktop is a good place so you don’t lose it)



import serial
import RPi.GPIO as GPIO
import time
ser=serial.Serial("/dev/ttyACM0",9600)  #change ACM number as found from ls /dev/tty/ACM*
def blink(pin):
GPIO.setup(11, GPIO.OUT)
while True:
    if(read_ser=="Hello From Arduino!"):


Now open Arduino IDE and upload the following code to your Arduino.



String data="Hello From Arduino!";
void setup() {
  // put your setup code here, to run once:
void loop() {
  // put your main code here, to run repeatedly:
  Serial.println(data);//data that is being Sent


Make sure the code is uploaded to Arduino.

In your Raspberry Pi interface, be sure to enable Serial and I2C in PiConfig.




Next, you’ll need to restart your Raspberry Pi. Open the Terminal and execute these commands:


sudo apt-get install python-serial

sudo pip install pyserial


Connect your Arduino to your Raspberry Pi


ls /dev/tty*


Then find a line with /dev/ttyACM0 or something like /dev/ttyACM1 etc., check for an ACM with any number 0,1,2 etc.



Open Python again and change ser=serial.Serial(“dev/ttyACM1”,9600) to the ACM number you found. So if in your case, in your case you got ACM0 then the line should look like ser=serial.Serial(“dev/ttyACM0”,9600)

Now run the program you just created in Python3. You will see “Hello From Arduino!” in the Python terminal and your LED should be blinking as well!

Recommended Posts
  • dinie

    Hi. Thank you for this excellent post. but i do have problems with the output. My output b’Hello from Arduino\r\n’, how to remove that? because my led wont blink since it compare with no a similar read_ser. i do try change a bit. i want to use the same method but transferring numbers like int and float but the output still the same. I try the method .decode but it only can change during print and it print the output but with a square shape at the end.

Leave a Comment

34 − 28 =

Start typing and press Enter to search