Motor is Triggering my interrupts

-editted to make correct statement-
Hello I'm not sure if this is the right section but here I go.

So i created a program that controls some servos and a motor.
i then created an interrupt to put the program to sleep.
the problem is that whenever my motor starts, the interrupt will automatically trigger.
without the motor hooked up, the program runs fine.
the interrupt is an external interrupt hooked up through pin 3 with a pullup resisitor.
The motor is connected through the arduino motor shield r3
any help would be greatly appreciated.

Here is just some of the code

//in the setup()
attachInterrupt(1,interrupt1,RISING);

void interrupt1(){
  start =true;
  sleepy=1;
}

//this is in the main loop()
if((sleepy==1)/* || (counter >= 60000000)*/){
      digitalWrite(7,LOW);
      analogWrite(motorPin,0);
      counter = 0;
      music(0);
      myservo.write(180);    //change
      myservo2.write(0);
      detachInterrupt(1);
      sleepy=0;
      delay(1000);
      sleepNow();
    }

void sleepNow(){
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  sleep_enable();
  attachInterrupt(0, wakeUp, LOW);
  sleep_mode();
  sleep_disable();
  
}

Noise from the motor?

hi,

Are you sure it's the interrupt not a power issue ? The effect would look similar in your case.

Have a read of this

Then watch this, it's about servos, but the same applies to motors

Duane B

rcarduino.blogspot.com

Thanks for the replies.

Well the motor is powered from a 9v battery and is connected through the arduino motor shield r3. i dont think i am getting noise from it.

my program runs fine with the two servos connected. its only when the motor is connected that i am getting problems. It could still be noise but it has a separate power supply, a .01 uF capacitor connected between its leads, and its connceted through the motor shield.

im not really sure what else to do

geereg:
... whenever my motor starts, the interrupt will automatically trigger itself.

Well let's get the terminology right. The interrupt doesn't trigger itself.

You mean, when the motor starts, the interrupt is triggered. Therefore the motor triggers the interrupt.

the interrupt is an external interrupt hooked up through pin 3 with a pullup resisitor.

You don't hook interrupts up to pins. What is connected to the pin? A switch? Which goes to where?

Hi,

One last question to eliminate power, you do not mention how your servos are powered, are they also on separate power ? If not the addition of the motor shield the components of which take some power from the arduino maybe just enough to take it over the edge.

Duane b

rcarduino.blogspot.com

yes you're correct, the motor is triggering my interrupt.

the interrupt is a switch with a pullup resistor connected to INT1, which is pin 3.( arduino uno )

and my servos are powered off my arduino. they say they are powered with 4.8V-6Vs but maybe theres not enough current. i will try powering them separately later.

thanks for the replies.

Digging up an older thread, because is seems to be asking a similar question.

I have an Arduino Uno R3 + Arduino motor shield, and I’d like to power two motors AND use both of the external interrupts for encoder reading.

But pin 3, which corresponds to interrupt1 is used for PWM A on the shield.

So I don’t see how I can do both. Is this correct? Is this what’s causing the issues for the OP?

Possibly, yes. Interrupts can be self-triggered (eg. by the PWM output) - I believe.

In your case you could use pin-change interrupts for the encoder. There is some stuff about them near the bottom of this page:

Be aware that some libraries (like SoftwareSerial) also use pin change interrupts.

So I don't see how I can do both.

You can't. As a PWM pin for the motor, it is an output pin. For the interrupt mechanism to work, it must be an input pin. A pin can not be both at once.