Limit switch and noise

For my solar tracker Arduino project I installed 2 limit switches and wired them with a 10k resistor as per Arduino's button tutorial (

Problem is that the noise from the solar tracker motor is generating false triggers.

I've read that the solution is to add a capacitor to this circuit. Can someone help me update the above circuit with the capacitor? Ideally, with minimal rewiring. What size capacitor should I use?

Try a 0.1uF or 1uF capacitor in parallel with the resistor. A 1uF capacitor will be polarized so connect the negative pin to ground.

A lower value resistor (1K) may also help (with or without the capacitor).

It's also possible for motor noise to get in through the power supply.

A lower resistor value may help.

Try a capacitor across the motor.

Show us a good schematic of all your circuit.
Give links to components.
Posting images:

There are a couple of problems here.

One is that you have given no indication of how your project is either wired or constructed from what parts.

The "button tutorial" is misleading in that is suggests switches are wired between Vcc and an Arduino pin. It is almost always preferable - and this would be a good example - for them to be wired between an Arduino pin and ground. You can often use pinMode(thispin, INPUT_PULLUP) but in this case you probably should use a lower value pull-up resistor. The wires to the limit switch must run as a pair from the switch to the Arduino board.

Forget the capacitors and resistors (except the one across the motor :grinning: ). You need to "debounce" the switch inputs by polling in software. Research that term. Do not attempt to use interrupts.

If using software to implement limit switches, consider whether it matters when the software fails and the limits are not detected. If it is possible to cause damage or become unsafe, then the limit switches must act directly on the motor (in addition to the software).

Consider using opto isolators on the limit switch inputs - it’s never a good idea to use long lead lengths feeding straight into the processor .