• EUR€
  • £GBP
  • $USD
TUTORIALS RoboticsArduino

Robot driven by PS3 controller through Arduino and Wifi shield

DFRobot Jul 31 2015 680

This is a robot that uses the two left and right joysticks on the PS3 controller to drive "tank-style." The chassis, wheels, and motors are purchased in a kit. An Arduino Uno is mounted on the chassis and a Wifi shield is stacked on top of it. Two separate motor controllers are used to control the motors (one motor controller for two motors). 

The joystick information is sent from the PS3 controller to a computer through a Bluetooth connection. The computer has a connection with a Wifi network. The Arduino also makes a connection with the same network through the Wifi shield. The motor commands are sent through the network and to the Arduino

Project by Linda Zhou, Shan Ali, Justin Ashtiani, and Colin Usher
YouTube video

Step 1: Materials

Chassis kit (Pirate-4WD Mobile Platform, Product Code: ROB0003, Brand: DFRobot)
Arduino board compatible with Wifi shield (we used an Uno)
Two motor controller(2A Dual Motor Controller, Product Code: DRI0002, Brand: DFRobot)
Arduino Wifi shield
PS3 controller
Bluetooth dongle (ASUS USB-BT211 v2.1+EDR)
Wireless Adapter (ASUS USB-N13 Adapter Wireless-N300)
5xAA Batteries
9V battery
9V battery clip (snap connector)
2.1mm power plug
Eight extra pin wires
Crimping tools
Soldering tools
Extra black and red wires
Extra nuts, bolts, washers, screws, and standoffs
Pushpin terminals

Step 2: Construct the mobile platform

We will give steps for constructing the chassis here, but for a more detailed explanation you can watch a video series here. This was the tutorial that we initially followed to construct the chassis. 
The chassis kit also comes with an instruction manual with pictures and names of the materials used to put the platform together. The steps here will follow the steps listed in the booklet, and the names of the parts will also follow the names listed in the booklet.

Start by attaching the motors to the side plates with the screws, washers, and nuts.

After all four motors are screwed in, take the included red and black wires and cut four pieces about 7 or 8 inches long. Split the ends of the wires to divide the red and black wires. Strip the ends of the wires and twist the ends to tighten the fibers inside the wires.

Solder the red and black ends of the wires to the two metal clips on the motors (this video is helpful).

Step 3: Assemble the power switch and jack

Following the manual, connect the battery holder to the base plate with the screws and nuts.
Attach the power switch and power jack to the rear plate with the washers and nuts.
Get another two pieces of red wire about 6 inches long. Strip the ends.
The power switch has three prongs on the back. You will have to solder one red wire to the middle prong. You can then solder the other wire to either the top or bottom prong. Which prong you use does not matter, as long as you put the switch into the rear plate in the orientation that you want. Decide on how you want your switch to work (usually the up orientation is "on" and down is "off"), and use a multimeter to help you ascertain which configuration will give you the desired results.

Step 4: Wires

You should now have four motors with one wire connected to each motor. You should also have two wires connected to the power switch. 
Assemble the frame by attaching the front and rear plates and the side plates with the screws. Use masking tape to label all of the wires. We used this orientation to number the motors (see diagram).
Attach the base plate to frame.
Attach the wheels to the side plates.

Step 5: Making the switch work

Solder the red wire coming from the battery to one of the wires you soldered to the switch.

The other wire attached to the switch then becomes your red “power” line, and you will use this line and the black wire from the battery pack to supply power to your motors.

Because there are two motor controls, there needs to be two black lines and two red lines to supply power to each of the motor controls. Cut two pieces of 8 inch red wire and two pieces of 8 inch black wire. Separate and strip the ends of all the wires.
Take the two newly cut red wires and tightly twist the ends together. Take a wire crimping terminal and push in the end of the twisted red wire as far as it will go. Take a crimper and press on the connection as hard as you can. You can watch this video for help.

Take the red wire coming from the power switch and place it in the other end of the terminal. Crimp that side. You should have two ends of red wire coming off of the red wire that is attached to the switch.
Then do the same to the black wires.

Step 6: Assemble

Find the top plate. Find two holes in the plate that align with your Arduino board. We found that the pre-drilled holes in the top plate only allowed us to place two standoffs in the Arduino because of the positioning of the holes in the plate and the holes in the Arduino.
Find two of the shorter standoffs provided in the kit and place them in the holes you are using. Take two nuts and screw them onto the standoffs from the other side of the plate.
Take the bundles of wires that you have and poke the wires for motors 1 and 2 and the power lines through the front long slit on the top plate. Poke the wires for motors 3 and 4 through the long slit on the other side of the top plate. Screw in the top plate.
*Before screwing in the Arduino and the Wifi shield, try the included Wifi code to make sure that your Arduino can make a connection to the network you will be using. The code is in step 14.*
Take two of the screws and attach the Arduino to the standoffs. Then stack the Wifi shield on top of the Arduino.

Step 7: Mounting


Mount the motor controls onto the upper deck. We had to use our own screws, washers, and nuts to attach the motor controls.
When both motor controls are attached, screw the long copper standoffs provided with the kit onto the top plate.
Place the upper deck over the standoffs and screw the upper deck on with the screws from the kit.

Step 8: Motor controllers

Take the motor controllers and two pushpin terminals and place the terminals over the pins for M1 and E1 and M2 and E2 on both motor controllers. You don’t have to do this, but with the pushpin terminals you will not have to solder the wires to the pins.
Take the wires labeled for the motors and screw them into the terminals. It doesn’t matter which color you screw into the plus and minus sides; for now, just screw them in and you can change them later after testing the code and seeing whether the motors drive forward when you tell it to drive forward.

Step 9: Wiring the motor controllers

You will need another black wire to connect from the GND on the motor control to the WiFi shield. You will need to find two wires that are long enough to screw into the terminals and reach the GND pin on the Arduino.
Take one of the black wires coming from the battery and twist the end with your new black wire. Push them into the terminals and screw the top down. Take the other end of the new black wire and place it into one of the GND pins on the wifi shield. Do this for both motor controls.
Take the red wires coming from the power switch and screw the ends into the “VS” holes on the power terminal on the motor controllers. 
Make sure the jumper is connected on the motor controllers.

Step 10: Connecting the Arduino and motor controllers


Find 8 new wires. They don’t have to be the same color or even follow the color code that we used, as long as you can keep track of which wires go to which pin and motor.

Attach the pins to the WiFi shield and motor controllers according to the wiring diagram above. This step can be a bit of a pain, so grab a pair of pliers and have patience when threading those wires in the small space between the Wifi shield and the upper deck.

Step 11: Power the Arduino

To run the robot without having it connected to the computer, you have to have a separate power source for your Arduino.

Take a 9V battery, a 9V battery clip (snap connector), and 2.1mm power plug.
Follow the instructions on this website to make a battery adapter. Connect the adapter to the power plug on the Arduino.
Your mobile platform should now be entirely assembled!

Step 12: Connect your PS3 Controller to your PC using Bluetooth

To connect your controller to your PC, download and install the Motioninjoy software.

Launch the software, plug in your controller and Bluetooth dongle, and install the drivers for both devices.

Note: make sure that you will not use the Bluetooth dongle for any other purpose, as the drivers will make the Bluetooth dongle proprietary to the Motioninjoy software. Make sure the Bluetooth dongle also supports both Enhanced Data Rate ACL 2 Mbps mode and Enhanced Data Rate ACL 3Mbps mode.

After pairing the device with your controller plugged in, move back to the Profiles tab, and unplug your controller. The connected game controller(s) dropdown box will change to (Bluetooth). You can test the Bluetooth connection by selecting Vibration Testing.

Step 13: Acquire the files for the PC code

Before you begin, download the zip files that are included to help you acquire joystick data and send the values over Wi-Fi.  These files can be built using Microsoft Visual Studio Express Edition.

The included code files are:
1) PS3Controller.h
2) PS3Controller.cpp
3) UDPCon.h
4) UDPCon.cpp
5) PS3Interface.cpp
6) PS3 Controller Documentation Final.pdf (code explanation)

See the included document (document 6) for more details on the actual functions in the code.

Make sure to modify the ConfigRecieveAddr() function in the UDPcon.cpp to fill in the proper IP address of your Arduino Wifi Shield.

Example:  RecvAddr.sin_addr.s_addr = inet_addr( Arduino WIFI IP Here);

Open the file PS3Interface.sln in Microsoft Visual Studio and click on the green play button (Start debugging). Run the software to test the operation of the controller and the wifi.  When you run the code, you will see a command window with four values constantly updating (see picture above).  These values are the X and Y values for the left and right analog stick respectively.

Ps3Interface.zip 22 MB

Step 14: The Arduino code

The .zip file below includes the Arduino code to run and an explanation of the code. 

If you are experienced with Arduino and programming you may not have to read the explanation file. This information can be helpful if you experience problems with your code.
Make sure you have downloaded the Arduino IDEPull up the code, type in your ssid, password, keyIndex, and localPort, and then upload the code to your board.

***note:  Test your Wifi shield before you attach the Arduino and Wifi shield to the platform and the motor controllers. Try some of the examples in the Arduino libraries, and then test the included Arduino code. Run the code and open the serial monitor. The Serial.print() functions in the code will print information on the serial monitor and you will be able to tell if your shield has connected to the network. However, before you can see the information on the monitor, you have you uncomment the Serial.begin(9600);  function in the setup. Pins 0 and 1 on the Arduino are used for serial communication, so if you have motor pins connected to pins 0 and 1, you cannot use pins 0 and 1 for both serial communication and enabling on the pins. When you connect the motor controls, simply comment out the Serial.begin function and the code will run and you will be able to control the motors.

Arudino code.zip 114 KB

Step 15: Drive the robot

Once you have your PS3 controller connected to the computer with Motioninjoy and Bluetooth (step 12) and the Ps3 interface running (step 13) and the Arudino code uploaded to your board (step 14), you can drive your robot.
Place it on the ground and turn on the on/off power switch. 
Wait about 10 seconds for the Wifi shield to make a connection with the wireless network. 
Drive your robot! You can drive forward by pushing both joysticks up. You can turn the robot by only pushing one joystick. You can make a 360 degree turn by pushing one joystick up and one joystick down.
Youtube Video

Step 16: Known problems

The Wifi signal to the shield tends to drop out after a period of time. In our experience, this loss can happen after a minute of driving or less. Sometimes it stops after two seconds of driving. The robot loses its stream of data from the Wifi and starts driving in the direction that it was last commanded to do. We do not yet know the cause or solution to this problem.