I/O between arduinos with opto coupling. Sample schematic

You really need to define your meaning of " long distance "

For distances of up to 20 mtrs + then look at using a pair of MAX232 chips