PTZ camera control with Playstation 2 controller and RS485

I need a check on using the MAX485 and some advice on using the Pelco-D ‘4F’ command - zoom to position. I may need to query the camera to get the current zoom position.

Trying to do a slow zoom so the camera control is more human-like for production work…

=  GG_PTZ_PS2x   =
 An easy to use controller for PTZ cameras to give them a "human touch" for live production work.
 Written to support PTZ cameras over a RS485 bus using the Pelco-d protocol and fine motor controls like .05 deg/sec

 Thanks to Bill Porter and RickPBush for the coding examples that served as the starting point for this project.
 Bill Porter - ps2x a PlayStation2 controller library
 RickPBush - a Pelco-D PTZ controller project

 draft 1 - combined the ps2x and Pelco-D programs and removed the use of the Hall Effect sensor as an input device.
 draft 2 - implemented SoftwareSerial SSerial3 to emualte the Serial3 port seen on a mega (running this on a Uno)
 added in commands for preset positions 1-4 and call preset positions 1-4. added halt command
 draft 3 - added pin diagram, more commands, speed control on focus, tally light ideas
 draft 4 - add Pelco commands for the stick inputs and button selections. Tuned stick ranges, no drifting now.
 draft 5 - trimmed down the RS-485 command build process. collect all PTZ and send one command word, added tally lights
 draft 6 - working on variable speed zoom. requires that the camera support '4f' command, but mine dont support it.
 draft 7 - works ! I am running 3 cameras with this system each week. 
 draft 7d - Had to fix some RS485 timing issues with some delay here - working on zoom speed, cameras with variable zoom step sizes are preferred
Hardware build requires the following items:
  a PS2 Dual Shock controller, 
  a PS2 controller extension cable, (jumper cable)
  a MAX485 serial interface module, 
  a RJ45 jack, a copper ethernet cable, LEDs and resistors for tally lights 
  lots of jumper wires,
  a project box and suitable power supply (5v-9v DC)

Here are the pin assignments for the PS2 jumper cable to an Arduino Uno. 
The diagram is showing the jumper cable connector that you would plug the PS2 controllr into.
The appropriate wire on the jumper cable should be plugged into the pin on the Arduino as shown below: 

                   ||   ---------------------------   ||
                   ||   | o o o || o o o || o o o |   ||
                    \\  ---------------------------  //
 PS2 Extension cable:     9 8 7    6 5 4    3 2 1
       PS2 control line                          Arduino pin number
           9    data        ---------*--------         12  * 
           8    cmd         ------------------         11
           7    vibrate     ------------------         vin
           6    gnd         ------------------         gnd
           5    3.3v        ------------------         3.3v
           4    attn        ------------------         10
           3    clk         ------------------         13            
           2  unknown       ------------------         N/C
           1    ack         ------------------         N/C
Uno pin listing
         GND    MAX485_gnd and PS2 gnd
    -->  +5v    MAX485_vcc and PS2 VCC
    \    Vin    ps2_rumble   (works at 5v, but specs say use ~7-9v)  
    \    13    ps2_clock
    * -- 12    ps2_data    
         11    ps2_command
         10    ps2_attention
          9    MAX485 DE pin
          8    tx >> MAX485 pin

          7    rx >> MAX485 pin  (unused if we do not request a response form the cameras)
          5    tally_LED4 (unit power on)
          4    tally_LED3
          3    tally_LED2
          2    tally_LED1 
          1    reserved serial
          0    reserved serial
* Dont forget the 10k pullup resistor to VCC on the ps2 data line

If you have suggestions or corrections, please send to gegcorp2012 at
(please note... I am not a corporation though)

Here is my code:

Photos added…

Update : I was able to try the controller today on a string of PTZ cameras, and noticed the cameras did not respond to any of the commands from my controller project.

I would like to check the RS485 bus to see if anything is getting put on the bus.

I have a USB to RS485 adapter that I could use in a laptop to listen on the RS485 bus, but do not know which software I would need to use for this purpose . . Any suggestions on how to validate the RS-485 portion of this project would be appreciated

Ok, so I used the USB to RS485 stick and a copy of 232Analyzer to "see" what is on the bus.

There was data on the bus, but it was ignored by the cameras because the synch byte was not set properly. Should have been like this :

byte SynchByte = 0xFF;

After making that change, I can see there are some other issues with the command build sections of the code where hex characters are not implied, so I will continue to review and refine to get the results I need.

Good news is: I have the assurance that the hardware is working, and also have an easy way to test the logical function of the program by comparing the Arduino serial out to the rs232Analyzer output.

Just need to work on the code some more to get clean Pelco-D commands with no leftovers.


Success !

I tried this project over the weekend and was able to control our three PTZ cameras with ease using this control system. There is an opportunity for some fine tuning in the sensitivity for the pan and tilt, and still room for improvement on the zoom controls. Also have an issue with storing presets, outlined in the 7a version of code in the first post.

Thanks for the help elsewhere on this forum !


what was the rj45 used for? are these just outputs to turn on your leds? just trying to find out if that part is needed for this to work.


FYI... The rj45 connector optional, and is used for LED tally lights. One of the LEDs will light up to indicate the camera that is currently selected. I took a length of ethernet cable and cut one connector off, stripped out the (4) pairs of wires and soldered an LED to each respective pair, observing correct polarity all the way from the Arduino output pin, resistor, through the connector and returning to ground. Place one LED on the respective camera monitor, and you will be able to tell which of your PTZ cameras will respond to the controls. the fourth LED acts as a power indicator, and can be controlled in the code.

Missing the code? Was looking to start this project but I only see the wiring information.