Micro switch ridiculously sensitive?

I’ve been using a micro switch to start an attachinterrupt but it activates even when I am not touching the switch. The code for it works by having the nano add 1 to a int called oo (oo++; ) and printing oo ( Serial.print(oo); ) when the attach is activated ( (attachInterrupt(0, buss, FALLING); ).

The problem is that oo is being increased by 1 when I’m not pushing the switch. If I move the micro switch to certain positions it works but if I touch the wire or the pins of the switch it breaks and adds 1 more to oo.

I’ve switched out the switch for another mirco switch but it has the same problems.
note: both of them were wired into a power supplies gnd and a nanos digital 2 pin.

Is this my bad soldering or is it the code?

The full code is meant to rotate a stepper backwards when a micro switch is triggered.

#include <TinyStepper_28BYJ_48.h>

// pin assignments, any digital pins can be used. oo is set as an int.
const int LED_PIN = 13;
const int MOTOR_IN1_PIN = 9;
const int MOTOR_IN2_PIN = 8;
const int MOTOR_IN3_PIN = 11;
const int MOTOR_IN4_PIN = 10;
int oo = 0;
const int STEPS_PER_REVOLUTION = 2048;

// create the stepper motor object
TinyStepper_28BYJ_48 stepper;

void setup()
// setup the LED pin and enable print statements
// connect and configure the stepper motor to its IO pins
//the interrupt is set to trigger voidbuss when interrupt pin 0(d2) rises
attachInterrupt(0, buss, RISING);

//makes the stepper rotate once
void loop()
while (oo == 0){


if (oo > 1){
// makes the stepper rotate back


// void buss adds one number to oo and prints it
void buss()


pinMode(2,INPUT); try pinMode(2,INPUT_PULLUP);

However, we need to see your hardware schematic.

Also slow switches and interrupts are hardly ever a good mix. Just look for a change in state and act accordingly.

See the change in state example in the IDE.

You had arranged your input pin to be floating - input pins are isolated(*), they just "sniff out" voltage, so unless you arrange for a pull-up or pull-down resistor to bias the pin it will read random noise picked up from the environment near the switch and pin.

(*) CMOS logic uses tiny MOSFETs internally, in which the gate electrode sits on an insulating oxide layer and affects the output by voltage alone. No current needs to flow to maintain state, and tiny amounts of charge induced on the wiring is enough to change the gate voltage and flip the state.

More precisely they are isolated so long as the voltage stays between Vcc and ground. Outside that range the built-in input protection diodes conduct and limit the voltage.