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