I've been using the circuit below to debounce a reed switch without REALLY understanding it. Could someone point me at an explanation of how a circuit like this works? I want to change it so the switch is between arduino and ground rather than +V (if that's possible).
Pretend the diode is ideal. When the switch is pressed, the capacitor charges with current from V+. The digital input pin reads high at this time. The capacitor stays charged until the switch is released. Then, the diode is reverse-biased and doesn't conduct any current (so pretend it isn't there anymore), but the capacitor slowly (relatively) discharges through the two resistors. Once it's discharged, the voltage is near 0 and the digital input pin reads low.
I want to change it so the switch is between arduino and ground rather than +V
Move the switch contact from + to ground. Move one end of the 10K from ground to +. Reverse the direction of the diode.
Oh yeah...to make it reversed in sense, switch V+ and GND and reverse the direction of the diode.
Pretend the diode is ideal. When the switch is pressed, the capacitor charges with current from V+. The digital input pin reads high at this time. The capacitor stays charged until the switch is released. Then, the diode is reverse-biased and doesn't conduct any current (so pretend it isn't there anymore), but the capacitor slowly (relatively) discharges through the two resistors. Once it's discharged, the voltage is near 0 and the digital input pin reads low.
ok thank you very much. So say this is a bouncy reed switch(it is). On the first contact the cap charges immediately and when it bounces off the cap discharges to 63% of the 5v in the rc time which i take to be 1ms - right? So as long as the bounces are <1ms the interrupt only triggers once.
Here's my picture of the revised circuit:
and in this case, when the circuit is open the cap is not charged. when the circuit closes the cap has to charge before the arduino sees the +V, again around 1ms - right?
sorry if i sound stupid but i just find the analog/diode stuff confusing.
Right!
I have a methane gas meter in my home which have a reed contact inside with a DIN connector. It generates one pulse each 0.1 m3 consumed.
I don't see to expect more then one pulse per minute even when you're cooking and heating the house.
Do you think it's still useful this circuit to avoid false readings? Is it enough to hook the "Interrupt pin" to a Arduino digital i/o?
If you just use a plain digital I/O (no interrupt) then you can filter it in software. Just sample the pin several times (spaced by a few ms apart between samples) and don't consider the pin "steady" until the readings are all the same.
Thank you for the reply!
Pardon for the newbie question but do I need any protective circuit between the reed contact and the Arduino? The meter is outdoor and I don't want to fry the electronics with ESD...
If you are using hardware debounce that adds a bit of protection. Otherwise see:-
http://www.thebox.myzen.co.uk/Tutorial/Protection.html