Periodically clean the interiors of the machine with water, baking soda (half cup) and white vinegar (3 cups). Run the machine without load after filling water with the above substances. All residues and deposits formed inside will be removed. If necessary consult the company representative about the preventive maintenance. In the case of new machines make use of the free maintenance service offered by the manufacturers. Remember the adage "prevention is better than cure".
The above list is not exhaustive, but it's a great starting point. Washing machine repair is by no means a simple task, but it becomes a lot more manageable for the average homeowner when you're at least somewhat familiar with the parts that you're looking at. Take a minute to look over the owner's manual that you received when you purchased your current unit; there should be a complete diagram with all of the parts labeled. If you misplaced the manual or can't locate a helpful diagram, there are countless online resources that can help you with your DIY repair by allowing you to look up your exact model specifications and helping you identify exactly which parts may be at the root of your washer's malfunction.