Problem with multiple micro switches ( limit switch )

Hi forum,

I have an arduino mega and about 7 limit switches hooked up to the pins. The inputs are configured as INPUT_PULLUP. However, the corresponding input pins was able to read other limit switches. ( pressing any of the limit switch activates the code, although its set to only read from one pin ). also, the other pins couldnt read inputs when any of the switches is pressed. Does anyone knows what might be wrong here?

Thanks !

I didn't understand any of that sorry.

Perhaps a schematic of what you have would help, as would your code.

Then describe what's supposed to happen vs. what actually doeshappen.

I read it again and I think I understand this part:

also, the other pins couldnt read inputs when any of the switches is pressed.

... and I suspect that's becasue you have used delay() in the code, but you haven't shown the code to us.

the actual code is kinda long and yeah i did use some delay. The schematic is basically, its just 5v connected to NO, then ground to arduino pins. The code is basicially do something when the switch is pressed. Thanks for you reply !

sketch_aug29a.ino (13.1 KB)

Did you forget to connect the other terminal of each of the switches to ground?

Post a hand drawn wiring diagram.

its like this but 7 switches. also i should be noted i didnt use a resistor because i kinda dont have 7 1k resistors so i just used to pullup function. however, it still disconnects my arduino when the switches close.

Your drawing shows the switches connected to 5V, not ground.

Connect one leg of each switch to Arduino GROUND, the other leg to a pin that is declared INPUT_PULLUP.

Use your multimeter to verify that each switch is properly connected to Arduino GROUND.

Right on, thank you ! ill try and report back :smiley: thank you sooo much

thank you, ill try that. just to clarify, the GND is connected to COM of the switch?

If you have enablet INPUT_PULLUP, the arduino putts Vcc over a 10K internal resistor to that INPUT.
All you have to do is to connect you switch to that INPUT and GND - that should work.

Just note that this switch is INVERTET - it gives HIGH if no KEYPRESS or LOW if you press the button!
So action has to take place when the Input goes LOW.

FINALLY several with the right answer :slight_smile: GOOD LUCK

Thank you friends. I have tried the recommended method (NO to arduino pins and COM to GND )and the switch is responding perfectly. However, i will still have to test out the initial problem where the switches are interfering with each other and when a switch is activated, that other switches can be read b y the arduino independently. Will report back! thanks again :smiley:

UPDATE!! both of the initial problem is solved. Activating the second pins does not trigger the first pin anymore, also when the first switch is activated, the second can operate normally! I also tried to space out the pins so they are not all cramped in one area . Thank you guys again :smiley:

Also, if anyone got any clue what went wrong with my initial set up, can you please share. Seems like i have a misconception on the fundamentals. If not, its working now anyways :smiley: CHEERS !

if anyone got any clue what went wrong with my initial set up,

The switches were not properly grounded.