Bump Sensor Interupt

I need help making a program that uses a bump switch interrupt. I need the program to run two motors then when the bump switch is activated i need it to get stuck in a loop that has both of the motors turned off and will not turn back on until a reset. Here is what i have so far. I think that it is close but not sure.

This is on the UNO


Motors are on
bump sensor is pressed
Motors stop and stay stopped untill board is reset

#include <Servo.h>
Servo rightMotor;
Servo leftMotor;
Servo cuttingMotor;
int pos = 0; // variable to store the servo position
const int Light=13;
const int BtnPin = 2;

void setup() {
pinMode(BtnPin, INPUT);
attachInterrupt(0, kill, RISING);
digitalWrite(Light, HIGH);
Serial.println(“setup complete”);

void loop()
Serial.println(“drive motors on”);


void kill ()

Serial.println(“bump triggered”);


The problem with the way you have written it is that after it has finished the kill() function it will return to the position in the code it was in before the interrupt, and so will go back to loop, setting the motors to full speed again. A better way to do it is to have a global variable, which you initialise to 0, when you get the interrupt you set it to 1, then in your loop if the variable is 0 you run the motors, if it is 1 you stop the motors. There are of course lot of ways to do the same thing, but this way can be extended easily to add additional functionality with minimum code changes.

I also noticed that your interrupt is on pin 0, if you are using the serial port, which you are here, this pin is already being used as it connects through to the usb serial connection