This tutorial will show you how you can fix any PS3 controller for most problems.
This fixed my PS3 DualShock 3 which wasn't charging and fixed my PlayStation Move controller which was not functioning properly.
I got this guide from the PlayStation Forum, but it was not so good so I've changed it and added stuff to the guide to be more user friendly and posted here.
Reset controller image is from PlayStation Knowledge Center.
NOTE: In this guide, "the one controller" means the controller which is not fixed and you want to fix it.
1) Turn off the PS3 so that the PS3 power LED is in Red color. Put the back power button to OFF and unplug the PS3 from the power source.
2) Disconnect any device connected to the USB ports, including the USB cables.
3) Reset the one controller (Press the button inside the small hole between the L2 button and the big screw hole with a paperclip, pin or pen etc.).
4) Connect the one controller with the USB cable to the PS3.
5) Plug the PS3 again to the power source and put the back button to ON.
6) Press the PS button on the controller.
7) Turn on the PS3 by pressing the front power button(near eject button).
8) Press PS button on the controller again.
9) The controller will be recognized as #1. (Keep pressing the PS button until you have it recognized.)
10) Don't press any buttons, just wait for at least 60 seconds.
11) Then press and hold the PS button for at least 10 seconds, then let go off your hands from the PS3 controller.
12) You should see a menu with the Controller #1 and Charging written on it.
13) Just wait until it says Charge complete.
14) Then you have to unplug the USB cable from both sides.
15) Keep pressing the PS button until you have it recognized.
If your controller is still not fixed, try the official Sony steps.
Troubleshoot DUALSHOCK®3/SIXAXIS™ Controllers
This should work for all PS3-compatible devices.