I am curious about a behaviour I observed on my Arduino-like (I use a cheap copy of a Nano but I expect it would be the same with pretty much any Arduino)
I uploaded this code, and did not connect anything physical to the board
I would expect that the pin 2 is in high-impedance mode and should either fluctuate randomly or stay in any state, but actually the above program prints out "50" !
Why does my floating pin oscillate ? Is it because of the 50Hz mains ? I have plugged in my board to my computer using a mini-usb cable, I did not expect to have any noise from the mains...
You set the value of the variable "state" to zero, and then print out it's value 1 second later.
If the interrupt is being triggered by mains interference, then it will have incremented "state" to 50 in that time.
You could make the interrupt pin less sensitive to noise pick-up by connecting a resistor and/or capacitor between that input and ground. Also used screened cable to connect to your input.
You haven't told us what you want the interrupt to detect.
That code is not supposed to do anything, just curious about this behaviour...
Is the 50Hz perturbation coming from the PC (maybe the USB is not properly regulated), or is it coming from ambient electromagnetic fields created by the mains in the house ?
I can think of many applications such as detecting a power short out (I saw someone looking for a way to to just that here about a week ago)
Wow ! I tested this today, and I can follow my mains through the wall with it ! In europe (220V 50Hz), with a simple jumper wire connected to port 2 as an antenna, it detects 50Hz up to 30cm of the wire...