PlayStation 2 Controller Arduino Library v1.0

Posted in Arduino Libraries by Bill
5 Jun 2010
PlayStation 2 Controller Arduino Library v1.0

Want to interface a PlayStation 2 Controller with an Arduino Microcontroller? You have come to the right place. Below you will find a link to download an easy to use library that takes care of all the interfacing for you, so you can start using the controller right away for your project. Don’t forget to link your cool projects in the comments, I’d love to see what you do with the library.

First, a brief history:

A while ago, I spent countless days trying to interface an Arduino and a Play Station 2 controller. I wanted to build a controller for my SAGAR robot, and figured PS2 + Arduino would be perfect. However, no matter what I did, no existing library would work for me. I shelfed the project for a while, but recently found this forum post with some code by a member named Shutter. I tried out the code, and to my surprise, IT WORKED!!! Well, mostly anyway. It didn’t really have analog stick support, nor was it formatted into an easy to use library. Well, through need I spent some time adding analog stick support, and formatted it into a library. It works fine on my Arduino Pro mini.

The first fully working version (v1.0) is now available. The big change is you can now define what pins of the Arduino are used, no longer are you tied to pins 10-13. Also, vibration (Rumble) and analog button pressure readings (how hard is a button being pressed) are now working. The library has changed names. PSX -> PS2X to avoid confusion with other sets of code. Sorry for those that need to change a bunch of their programs.

I had to rewrite a lot of code that powers the library, there is not much left of the original code written by Shutter of Arduino forums. There were many bug fixes, now the controller should automatically be in analog mode, and the mode button should be locked. There’s also a catch to make sure not to much time has past since the last controller reading. If there was, it will configure the controller again, in case it timed out.

Source Code available on GitHub project page.


Download PS2X


Old Versions:


PS2X lib v1.41

Arduino PS2 Controller Library V1.5

Wiring the Controller

The seemingly most notorious part prone to errors is wiring the controller to the Arduino. Lynxmotion sells a nice breakout connector available HERE.


The Lynxmotion adapter may not follow the color wiring diagram below. Instead, it might follow this diagram. (Lynxmotion only). Be careful and use a volt meter to confirm pin positions.

Or, to wire the controller not using the Lynxmotion adapter, follow the pinout in the following picture from the amazing CuriousInventor PS2 Interface Guide:

Image Source: CuriousInventor

A note from CuriousInventor: “Red – Power: Many sites label this as 5V, and while this may be true for Play Station 1 controllers, we found several wireless brands that would only work at 3.3V. Every controller tested worked at 3.3V, and the actual voltage measured on a live Playstation talking to a controller was 3.4V. McCubbin says that any official Sony controller should work from 3-5V.”

Here’s a video demonstrating the library.

Guitar Hero Controller Example

The following is a video and source for example of how to use the library with a Guitar Hero Controller.

Source: (tested with v1.5, should work with v1.6 as well)

Guitar Hero Example Arduino Code

Guitar Hero Example Processing Code (thanks Patrick)

Another Demo

Author unknown

Project Showcase

Hey guys, feel free to drop a link off in the comments to your project that uses my library. I’ll post it here.

  1. Guitar Hero Axe Controlled Flamethrowers by Chris Marion
  2. Scanalogic Review by CuriousInventor
  3. SAGAR by Me
  4. Remote Controlled Robot (Video) by ‘teachengineering
  5. ‘America Dream’  Electric Hammock by Stephen Shaffer
  6. Life size R2D2 robot by Dan
  7. Simon Says via DDR mat by Dalpix


Follow my troubleshooting guide first and then visit the Support Forum if you still can’t get it working. Don’t ask for help in the comments below.
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.


Trackbacks / Pingbacks

  1. HDSPs and Playstation 2 controllers on Arduinos - Hack a Day
  1. 587 Comments.

    • NickNo Gravatar says:

      Thank you for putting this into a library. I noticed that you said you used an Arduino Pro Mini. Are you using the 3.3v model or are you using the 5v version with some sort of level translator like the TXB0108 ( ) ? As I understand, the PS2 controller is 3.3v. May I see your electronics schematic? Thanks for helping us out!

      • BillNo Gravatar says:

        I am using the 5v version, and I’m not using a level shifter. I am powering the controller with 5v as well and it continues to work. It will even work with no power, lol.

        There’s nothing really to the wiring, beside just connecting the correct wire to the correct pin. But when I get back to my computer I’ll take a picture of the connections, and maybe a video of it controlling my robot.

    • […] those who would like a nice familiar input device for their Arduino, how about a Playstation2 controller? [Bill Porter] has written up the code and shown how to wire it up. This even includes the ability […]

    • ScottNo Gravatar says:

      Can you add a link in the post to (the source of the picture you’re using) ?

    • BillNo Gravatar says:

      ^^ added. I had thought the link embedded in the picture would suffice for credit given, and apologize for any ill will.

    • NateNo Gravatar says:

      Hey, Nice work. Check out this stuff I decoded with a logic analyzer ( This should be enough for anyone to understand the data that comes out of the controller. It’s SPI to the box. Ask me if you have any questions.

    • BillNo Gravatar says:

      Added video demonstrating library

    • Dale WheatNo Gravatar says:

      Good job! Thanks for writing this up!

      Any luck getting the “analog buttons” to work?


      Dale Wheat

    • BillNo Gravatar says:

      ^ Should be relatively easy. I assume you are referring to the pressure readings on all the push buttons?

      I can write a function to return those values, I didn’t think they were useful to anyone.

    • BillNo Gravatar says:

      I also want to try adding rumble support, would anyone use it?

    • DaveNo Gravatar says:

      How difficult would it be to convert all the various outputs from the PS2 controller to MIDI using the Arduino?

    • ankan mishraNo Gravatar says:

      dear sir,

      i am very much intrested in doing that…

      pls provide my the details of materials and how to connct all those…

      awaiting your reply

      thanks with regards.


    • BillNo Gravatar says:

      Dave, the only part I would not know about is how easy is it to create a MIDI Arduino interface? This library takes care of the controller, you have full access to the data. If there’s a MIDI library somewhere, it just a matter of combining the two.

      Ankan, all details are in this blog post.

    • NickNo Gravatar says:

      Rumble support sounds good. Also, the pressure readings would be great as well. Perhaps they could be used like a gas or brake pedal? I am concerned with the 5v Arduino to the 3.3v Playstation controller. When I attempt to put 5v on the 3.3v line of my wireless PS2 controller, it’s lights turn off but not if I apply 3.3v. Also, I’m not using an Xbee as I would be just connecting to the Arduino directly.

      May I see your electronics schematic? Thanks for helping us out!

    • NickNo Gravatar says:

      Ok… I’ll try to make this one my last comment. I just tried your code and library and it WORKS! I put a 10k resistor on the 3.3v line of my PS2 controller. It is a Gigaware brand wireless controller (if that helps anybody.) I am very happy for your efforts, Bill, and of course all that have contributed to this library.

      Do you have plans on working on pressure sensitivity? Thanks so much again!

    • BillNo Gravatar says:

      Glad to here it Nick!!!

      Question, is your Arduino running at 3.3V or 5? For those running with 5v Arduinos and are worried about the voltage to the controller, remember your logic levels are also at 5V so maybe consider a logic level shifter. My Sony brand wired PS2 controller seems to tolerate 5V supply and logic just fine, but Nick’s wireless Gigaware seems not to like 5V.

      I was going to look through the PS2 communications protocol tonight to see if I can get the pressure values and Rumble working. Stay tuned.

Leave a Reply