Arduino: Controlling Servo With PS2 Controller (Program With Visuino)




In this Instructable you will learn how to program Arduino to control Servo motor from a Play Station 2 controller with the help of Visuino - an easy to use graphical development environment for Arduino.

Please note that the annotation on some of the pictures in this Instructable will work correctly on some browsers only after you click on the image to expand it.

Please note that the annotation on some of the pictures in this Instructable will work correctly on some browsers only after you click on the image to expand it.
Please make sure you click on the image to see the annotation showing the correct spot on the image!

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Components

You will need:

  1. One Arduino Mega (You can easily modify for another Arduino compatible board)
  2. One Play Station 2 compatible controller
  3. One Cytron PS2 Shield You can buy it easily from here
  4. One small servo
  5. Up to 5 jumper wires

Step 2: Connecting the Shield and the PS2 Controller

The Cytron PS2 Shield used in the demo has configuration jumpers for the Arduino UNO serial, or to use software serial.

Using the main hardware serial is problematic as the same serial is used to program the Arduino and for debugging.

Arduino Mega has 4 serials, and it is recommended to use a hardware serial whenever one is available.

To connect the PS2 Shield to one of the additional serial ports of the Arduino Mega, you can use jumper wires.

1. Disconnect the jumpers from the PS2 Shield.

2. If you have Male to Female jumper wires connect directly the pins of the jumper marked on the second picture with the red circles to the Arduino Mega pins marked with red ellipses in the first picture.

The RX pin (right on the PS2 Shield picture) should be connected to the pin 19 (RX1) of the Arduino Mega (first picture)

The TX pin (left on the PS2 Shield picture) should be connected to the pin 18 (TX1) of the Arduino Mega (first picture)

If you have only male-male jumper wires as in my case, you can use the jumper cap to make the connection as shown in picture 3

Step 3: Start Visuino and Select Arduino Board

To start programming the Arduino, you will need to have the Arduino IDE installed from here:

Please be aware that there are some critical bugs in Arduino IDE 1.6.6.

Make sure that you install 1.6.5 or 1.6.7, otherwise this Instructable will not work!

The Visuino: also needs to be installed.

  1. Start Visuinoas shown in the first picture
  2. Click on the "Tools" button on the Arduino component in Visuino
  3. When the dialog appears, select Arduino Mega as shown on Picture 2

Step 4: Add PS2 Controller Component and Connect It

  1. From the toolbar expand the "Remote Controllers" Category, then the "Digital" Sub Category, and select the "PlayStation 2 Controller (Serial Shield)" as shown on the first picture, then drop the component in the design area
  2. Connect the "Out" pin of the PS2Controller1 component to the "In" pin of Serial[ 1 ] of the Arduino component (Picture 2)
  3. Connect the "RightStick" "Y" pin of the PS2Controller1 component to "In" pin of Serial[ 0 ] of the Arduino component (Picture 3)

Step 5: Monitoring the PS2 Controller With the Serial Terminal

  1. In Visuino Press F9 to generate the Arduino code
  2. When the Arduino IDE appears, click on the Upload button (Picture 1)
  3. Open the Arduino IDE Serial Terminal to monitor the position of the right stick (Picture 2), and move the right stick up and down
  4. The position of the stick will be printed on the serial, each time it has changed. The position will be in values between 0 and 1 where 0.5 is the center position of the stick

Step 6: Connecting the Servo

  1. Connect the "Signal" wire of the servo to pin Digital 2 of the Arduino (Picture 1)
  2. Connect the +5V and the Ground for the servo. It is recommended to use external power for the servo, but for testing with small servos, you can connect directly to the Arduino as shown on the schematic. (Picture 2)
    My servo has female connectors and I used male-male jumper cables to connect it to the Arduino Mega as you can see in Picture 3. If your servo has separated male connectors, you can connect it directly to the Arduino.

Step 7: Programming the Servo

  1. From the toolbar expand the "Motors" category, select "Servo" (Picture 1)
  2. Drop it in the design area, then connect the "RightStick" "Y" of the PS2Controller1 to the "In" pin of the Servo1, and the "Out" pin of the Servo1 to the "Digital" input pin of "Digital[ 2 ]" channel of the Arduino component as sown in Picture 2

Step 8: And Play!

  1. In VisuinoPress F9 to generate the Arduino IDE code as you did in Step 3 and when the IDE appears press the "Upload" button.
  2. Once the code is uploaded, you can start controlling the servo with the right stick by moving it up and down as shown in the video.

Congratulations! You created your own Arduino program to control Servo motor with a PS2 Shield in just few minutes!

Also attached is the Visuinoproject, that I created for this Instructable. You can download and open it in Visuino :

Robotics Contest

Participated in the
Robotics Contest

Tech Contest

Participated in the
Tech Contest

Be the First to Share


    • Made with Math Contest

      Made with Math Contest
    • Multi-Discipline Contest

      Multi-Discipline Contest
    • Robotics Contest

      Robotics Contest

    5 Discussions


    1 year ago

    Does the Visuino programming solve the problem of debouncing button presses from the PS2 controller? The Cytron shield has worked great for me, but the button input bounces are a problem. You press the button once and the arduino may think its been preset several times quickl. I was never able to get any debounce library to work with the Cytron shield inputs and cytron support didn't seem to have any idea what was even meant by debouncing button input.


    3 years ago


    Thank for Uploading this.

    Hope you upload ESP8266 RC Car with PWM someday..;)

    1 reply