-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();
}
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.
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.
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.
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.