# AttatchInterrupt Constantly interrupts

I am a new to electronics. I am trying to setup the radio control for the arduino. I hooked up the Reciever's Channel 1 to the Arduino Mega 2560's Digital pin 2, Reciever Vin to Arduino 5V, and Ground to Ard Ground. Here is my Source Code.

void setup() {
Serial.begin(9600);
}

void loop() {
Serial.println("I AM IN THE LOOP");

}

{

Serial.println("I AM IN THE INTERRUPT");
}


I tried using other interrupt pins,3.3 V instead of 5 and also tried Arduino Uno and differnt kinds of Interrupt Values like RISING, LOW and FALLING but it constantly prints " I AM IN THE INTERRUPT" without me touching the transmitter. Any suggestions.

[UPDATE] After a great deal of discussion on http://forum.arduino.cc/index.php?topic=184283.0 I came to this conclusion. Radio generates PWM signal .. If you have an interrupt pin connected to a channel. It will interrupt regardless of what you do because it is constantly generating a PWM. So I am leaning towards interrupt is not a good idea for radio control.

• What kind of receiver are you using? Some of the cheap OOK receiver modules will receive junk the whole time there's not a carrier. – PeterJ Aug 24 '13 at 4:42
• Yes it is a hobbyking T6A V2 6 channel reciever 30 dollar kit. – Rabin Aug 24 '13 at 14:39
• I don't know if this is the right way to check ,, But when I check the data line of the reciever, the Voltage is 0.27 constant, On change of the transmitter handle the voltagegoes to 0.32/ 0.22. So I don't think there is any junk. Or what do you think? – Rabin 52 mins ago – Rabin Aug 24 '13 at 15:58
• If I'm not mistaken - this is a model aircraft remote. The receiver drives "servos" directly - it is not a logic on/off output. It provides a PWM type output that controls a servo with a varying frequency pulse stream. You would have to decipher the output as such - not by sampling for logical on/off. – Ron J. Aug 24 '13 at 20:48
• Yes you are correct. – Rabin Aug 24 '13 at 20:50

As you've determined that kind of receiver will have a PWM output to control a servo, the Wikipedia Servo Control article has some good information about it. If you wanted to use it anyway the normal neutral position will be 1.5mS so you could use something like the following code that uses the pulseIn function to treat a pulse of 1.75mS or longer as being on:

#define MY_PIN 0

void setup() {
Serial.begin(9600);
pinMode(MY_PIN, INPUT);
}

void loop() {
if (pulseIn(MY_PIN, HIGH) >= 1750)
Serial.println("TX on");
}


Note that the typical period between pulses is 20mS so your code will be stalled in pulseIn for around that period. If that's a problem you could go back to using the interrupt and set it for CHANGE and keep track of the time between when the line goes high and low again. It would be something like the following untested code:

#define MY_PIN 0 // Make sure this matches the interrupt line
unsigned long start_micros = 0;
unsigned long last_duration = 0;

void setup() {
Serial.begin(9600);
pinMode(MY_PIN, INPUT);
attachInterrupt(0 , PWM_handler, CHANGE);
}

void loop() {
if (last_duration >= 1750)
Serial.println("TX on");
}

void PWM_hander()
{
start_micros = micros();
else
last_duration = micros() - start_micros;
}


I am unsure if the receiver has an open collector output or not, but it is quite likely. I believe the interrupt pin is pin 2. Add a pinMode( 2 , INPUT_PULLUP ); before the attachInterrupt.

Also your interrupt routine may be a bit long (in duration). It is better to just flash LED on pin 13 or set a flag in the interrupt routine then do some smart stuff with that flag in the main loop.

You may want to check with an oscilloscope if the LED is constantly on or not.

• I tried the LED with the pinMode( 2 , INPUT_PULLUP ); The LED constantly flashes.. That means its still going in the interrupt – Rabin Aug 24 '13 at 15:05
• Does the flashing stop if you disconnect pin 2? – jippie Aug 24 '13 at 15:08
• Yes the flashing stops when I turn off my transmitter or disconnct pin 2 – Rabin Aug 24 '13 at 15:11
• Then it seems an issue with the receiver, not with Arduino. – jippie Aug 24 '13 at 18:47