From the school of hard knocks:
1) If it isn't in writing, it doesn't exist.
2) In your proposal, include hourly rates or a fixed price. Include a rate for travel time (I use 1/2 the regular rate) and on site time if you are doing on site de-bugging. I usually indicate direct travel expenses will be billed at cost, including a mileage allowance for automobile travel. I also cover secretarial services, copying, and such at a lower rate.
3) Include the phrase "Steve Crotty will not accept consequential costs or liquidated damages." Also, identify the time limit and extent of your service required to fix bugs that don't show up until later: "Engineering services required to correct errors or omissions by SC SuperProgramming LLC and discovered within one year of completion of the programming shall be provided at no charge to the customer"
4) Identify the information (drawings, sequence of operations, schematics, part numbers of vendor supplied equipment, programming software, whatever) that the customer must supply before you can BEGIN work.
5) Identify the scope of work - HMI, PLC, etc. Include things that are NOT part of your services, such as redesign or revised electrical drawings if their design doesn't work, etc.
6) Avoid definite dates for scheduling like the plague. Everything should be expressed as weeks or months from benchmark events. Initial drawigns XXX weeks ARO (After Receipt of Order). Programming XX weeks after customer approval of drawings. On site testing within XXX weeks after completion of customer installation. You get the idea.
7) Identify ownership of any intelectual property. If you are writing logic for a customer defined sequence of operation, it is probably theirs. If you are dong "blue sky" work on a new process or machine, they may have rights to unlimited use, but you may have rights to re-use on "non-competitive" applicatons. If it is totally your own work and logic, developed at your expense prior to this project, they may have a single use license or a royalty arrangement.
8) The contract should release you for any respnsibility for patent infringement or other breches of contract instigated by the client without your knowledge.
9) A mutually binding confidentiality agreement should be part of the proposal to protect you and the client. Something like this for each of you: "Steve Crotty Mega Enterprises and its employees will hold all information of a business and technical nature disclosed to it by the customer and relating to the business of the customer confidential. No information or documents will be given to persons outside the employ of the customer without authorization."
10) Include payment terms, and the remedy if payments are late. "Billing shall be twice monthly, net 30 days, 1.5% interest per month on amounts past due. If at any time in Steve's judgement the customer may be or may become unable or unwilling to meet the payment terms specified, Steve may require satisfactory assurances of full or partial payment as a condition to commencing or continuing any work or payment in advance of delivery and/or installation, or may, if delivery and/or installation has been made, If payments are not made in full and on time, Steve has the right to access to the customer's facilities to erase all programming and recover all documentation."
There is more, but these are some of the "high points".
This may look intimidating, and like you don't trust your customer, but it isn't the case. I have been doing consulting for twenty some years, and I have never had to enforce any of this language by litigation. I have, however, on a couple of occasions, had to refer my customer to some of these terms, and I was glad they were there.
Most clients are good guys, and you won't have to deal with this once you have your contract written. If a prospective client doesn't like this, and can't make a good case for why he wants to change your "standard" terms and conditions, you probably don't want them for a client.