I am building a bale stroke counter for a farmer. It has a wire running from the cab to the magnetic switches on the baler. I am using PortB with pull-ups on a 16F872. Would it be a good idea to put in a optical isolator between the switch and the Pic???
If you're running long wires about, it's probably always a good idea. However, presumably the baler uses a diesel engine , and it isn't as noisy an enviroment as using a petrol engine.
I would tend to try it and see what happens, using screened leads will help reduce any potential problems as well. Although using opto-isolators won't do any harm, and if you were designing a PCB for the circuit, you may as well include it on the board - then it's always available if needed.
Magnetic switches? Are these sensors powered like those inductive proximity switches? In which case, they usually output a signal from 0Volt to 12V-24V. Unless they are the open-collector type without any other load, you may have to use optoisolators to bring the signal down to 0V-5V levels.