It looks like your circuit is a victim of electrical noise. If you run long wires, they should be terminated properly. Have you tried adding small caps, around 100nF near the arduino inputs to these long wires? I'd also add a 10K resistor in series, and, VERY IMPORTANT two diodes to limit the voltage input to gound and +5V. (between the resistor and the arduino)
Protection diodes can be signal diodes, 1N914 or 1N4148 should be fine, since they are protected by the 10K resistor.
If you have any other long wires, they should have at minimum the diode protection. Even the outputs. Never connect a micro-processor, or any CMOS to long wires without this diode protection. Electrical noise can fry your chip.
I have shown basic protection on two of your inputs. You should do the same for the input running to B1 as well, if that's a long wire.
All long wires should be twisted pairs as well, again to reduce noise.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…