One bit of advice I got when I was experiencing knee pain was to make sure i wasn't riding at too slow a cadence (and too high gear). It was really good advice. I increased my cadence to between 80 and 100 (averaging around 90), and the very next ride the knee pain stopped. It's never come back.

I have a cadence sensor that at first really helped maintain the right cadence for me (I would have a tendency to forget to shift), but I hardly look at it anymore. Now I know just by feel what my cadence is.