attachInterupt not working

Hello, I am making a motion activation system for a friend that starts operating with a remote signal. I am trying to use attachInterupt to activate the sequence but for some reason it triggers no matter what, even if the pin is completely disconected. Here is my code:

int fire = A2;
int pirPin = 3;
int pirValue;
int rn = 0;
int activate = 2;

void setup() {
  Serial.begin(9600);
  pinMode(fire, OUTPUT);    // Set the ledPin as output
  pinMode(pirPin, INPUT);     // Set the pirPin as input
  digitalWrite(fire, LOW);  // Turn off of the buildin LED
  attachInterrupt(digitalPinToInterrupt(activate), start, RISING);
}

void loop() {
  Serial.println(rn);
  if(rn == 1){
    pirValue = digitalRead(pirPin); // Read the PIR value
    if(pirValue > 0){
      digitalWrite(fire, HIGH); // Write the PIR value to the buildin LED
    }
    //Serial.println(pirValue);
  }
}


void start(){
  rn = 1;
}

Describe this.

A floating pin can float any direction, so it's not surprising you see spurious interrupts occurring.

Start by defining the pin as INPUT_PULLUP.

Can you share a schematic of your circuit and details of the sensor/thingy that sends the 'activate' signal? Also, what Arduino board are you using?

Also, is there any compelling reason to use an interrupt in the first place? I bet there isn't and polling is probably far easier and more dependable.

Even if everything is completly disconected from that pin, it will still trigger. I have tried all the diffrent kinds of trigger values and they all do the same thing.

One sec, I need to make a diagram

Net port 2 is the input from the circuit. I cannot find any data on it becuase it is some obscure Chinese circuit.

OK, thanks. Can you post a clear photo of both sides of the PCB of this circuit?

Also, consider my remark that an interrupt is not necessary for this. You're switching a relay, which suggests you can suffer a few milliseconds' delay. This means there's no need for an interrupt; just poll D2 in loop.

PS: the section around the relay isn't very clear to me. Perhaps you could redraw that in a different way that makes it clear what goes where.

PPS: I'd include a diode across the relay's coil. Your circuit will freak out ever time the relay disengages.

The issue is I have no Idea what the output of the ciruit is or how long it last. That is why i'm using attachInterupt

So let's have a look at it.

And of course simply try it out. Poll the pin and see if you can detect when the 'thing' trips. I bet you can catch it.

The other side doesn't have any traces only a 12.000 crystal timer and antenna.

Thanks; any chance of a focused version that makes the letters on the components legible?

What's the 'thing' supposed to do/detect? I assume if you want to interface with it, you have a vague idea what it's for, right?

OK, great. So probably some kind of 433MHz receiver?

Exactly, it's for a remote control toy. As for the letters, I could barley understand them using a light and magnifying glass. However the board does say HX-174R-A 20-01-15 YFC-2967.

OK. Have you tried connecting a resistor and LED to the output so you can visually see what happens if the thing triggers? If the flash is visible, it'll be detectable by your Arduino with ease.

How have you figured out there's an output you can interface with to it to begin with?

Also, you do realize that if you are going to take a signal from this into your D2 pin, you also need to connect the GNDs of both devices (Arduino + Chinese thing)?

1 Like

The problem is not that I don't have the equitment to test it, I have a perfectly functioning osciloscope, but that I have no way of activating it as my friend did not give me the remote or battery for it.

Go back to your friend and get the remote. This is pointless if/until you can't test the device.

Good luck! Best regards to your friend.

PS: you don't need an interrupt.

Ok, thank you.

I just checked for kicks, and for some reason pin 2 has almost 5v on it? I have no Idea how this happend becuase I double and triple checked and there are no shorts. Also this happens to any pin I set activate too.

By activate do you mean this?

or did you try:

You should be able to test whether yout "attachInterrupt not working" is due to coding by using a pushbutton. And if that works, the problem is interfacing with the unknown device.