I am working on a project that keeps track of the number of times a contactor switches back and forth. To track the state the contactor is in, limit switches are used. Originally I was using the Arduinos internal pull-ups with digital pins and had the limit switches connected as pictured below.
The problem came when I noticed some of the pins were false triggering...contactor two would switch but also would display contactor 1 and 4 switched, even though they didn't.
I thought the internal pull-ups were experiencing some noise, so I tried the same setup pictured with external 10K pull up resistors, but encountered the same problem. My code is attached below and I am struggling to find a solution.
I guess my main question is, does it seem possible noise is still the problem, or does my code need improvement?