My garage door opener project is using reed switches to detect whether the door is opened/closed. They are the type of switch that is normally closed.
http://www.explainthatstuff.com/howreedswitcheswork.html (scroll down to the heading Normally Closed).
These switches are mounted on the metal rails that the door slides on. I’m guessing this is the normal way everyone does these garage door switches.
Switch used to detect if door is open. On top of metal rail that door slides on.
Switch used to detect if door is closed. Here the door is in a closed state or what I’m calling an ‘activated’ state. The two pairs of the switch are within 1" of each other thus causing the switch to activate and open the circuit (turn if off). I used black duct tape to fasten the other half of the switch to the door.
Each switch is connected directly to analog pins (A5 and A2) and ground. When the switch is activated the readings generally fall below 20. When it’s not activated, and in the normally open state, the readings are all over the place but seldom go below 20. I took some readings over time of an activated and non-activated switch with nothing moving during that time. The readings were taken every 5 seconds (via serial console) over a period of 25 minutes for 300 separate data points. analogRead value is Y axis and minutes is X axis.
The way the above values are jumping all over the place just seems so weird like I must be doing something seriously wrong. There seems to be some kind of sine wave pattern to the fluctuations which makes it even more strange – like it’s moving up and down according to some mysterious cosmic force. The lowest value in this chart was a 16.
I don’t see a sine wave pattern here.
- Is this wild fluctuation for a non activated switch somehow the normal expected behavior ? If it is normal then I’d sure like to know how it makes sense this could be happening.
- Do I just continue to make a best guess of what the threshold should be to determine if the switch is activated? Right now I’m using 20 but it seems that this value is not absolute as there was one case where switch returned a 16 even though the switch was not activated! And when the switch activated there was a case where the value was above 20 (as shown in the chart). So it making an impossible situation where there is no 100% certain way to determine the status.
- Is my approach all wrong and I’m needing to do some kind of hardware thing to fix this so the determination can be made with something closer to 100% certainty ?