How to control Arduino Servos from Raspberry Pi with Serial Communication

arduino Raspberry spi - steinacoz

In this post/tutorial, We will be controlling two Servo motors attached to an Arduino board from Raspberry Pi (RPi) using Serial Communication. I earlier made a post on Arduino – Rpi Communication using Serial communication, but it was just to send data from the Arduino to Rpi.

See also:

I was working on a project that requires attaching Servo motors and Stepper motor to RPi but I decided to incorporate an Arduino board to make it more easier. So, the components will be needing ans you can check them out in our store:

  • Arduino board
  • Raspberry Pi
  • Servo Motor x2
  • External Power Supply (I am using 12.5v battery pack)
  •  12v/24v to 5v DC converter (my module can comfortably power Arduino, RPi and the motors)
  • Cables



  • Connect Servo Motor 1 data to Arduino D9
  • Connect Servo Motor 2 data to Arduino D10
  • Connect Servo motors VCC to the 5v out of the converter and GND  to converter GND
  • Attach Arduino USB to Raspberry USB

Open a terminal and run this command in your RPi to find your Arduino USB device:

ls /dev/tty*


I first setup some integers to be sent to the Arduino:

  • 1 –> up
  • 2 –> down
  • 3 –> right
  • 4 –> left
  • 5 –> Full rotation

So the python code in RPi generates random integers from 1 to 5 and sends to the Arduino:


You can get the Arduino full sketch and Python code from my  github


components - steinacoz
components – steinacoz

Leave a Reply

Your email address will not be published. Required fields are marked *