Help

Hello all,

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.

Picture: https://cdn.sparkfun.com/assets/6/f/b/c/7/511568b6ce395f1b40000000.jpg

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?

Yes it needs improvement. First of all, eliminate the 4x repetition of code by using arrays. Your variable naming is strange - you call a button a "cycle" (from my understanding of what you said, it's not even a button). I suggest changing:

int cycleState1 = 0; //initial state the button is in

to

int switchState1 = 0; //initial state the button is in

for example.

Does the code do any debouncing ?

You can lower the resistance of the pullups to make the inputs less susceptible to noise. 1K is probably the practical minimum resistance. A 0.1uF (or maybe higher) cap across the switch can also help to filter noise away from the switch input (AKA hardware debounce).

If you have noise issues, the best way to get help is to post clear, high resolution images of all your hardware, and a full schematic.

Did adding caps have any effect?

Shizzle53: Unfortunately I cannot show pictures of the setup...

Because???

So this is a commercial project? Do I get a cut for my help?

Shizzle53: Product is in test phase and I do not own the rights to it.

Generally speaking, this is an open-source community where people try to help you -- for free. If that model is not suitable, you might consider paying someone to help you -- under NDA.

If you just want to understand then develop an open source project where we can help you learn. If your company wants to perfect the design of this thing and make lots of money on it then hire an engineer. There are plenty out there looking for work. To abuse the open source community for your for profit proprietary work is basically cheating and almost stealing.