Switch Flip Flop
Moderators: grovkillen, Stuntteam, TD-er
Switch Flip Flop
Hello,
Long time ESPEasy user and have been very happy. I recently installed a reed switch on a door and following the instructions documented here https://espeasy.readthedocs.io/en/lates ... witch.html
Everything seemed to go well, and with the door closed everything appears to be fine, see here...
But when I open the door and leave it open the switch appears to flip flop back and forwards from open to closed to open to closed... etc. I've tried using a connection to ground and a connection to 3 volts as per the guide at the link above, but nothing seems to fix it? The issue only presents itself when the door is lext open... when it is closed it doesn't flip flop?
Any ideas?
Thanks, Mark
Long time ESPEasy user and have been very happy. I recently installed a reed switch on a door and following the instructions documented here https://espeasy.readthedocs.io/en/lates ... witch.html
Everything seemed to go well, and with the door closed everything appears to be fine, see here...
But when I open the door and leave it open the switch appears to flip flop back and forwards from open to closed to open to closed... etc. I've tried using a connection to ground and a connection to 3 volts as per the guide at the link above, but nothing seems to fix it? The issue only presents itself when the door is lext open... when it is closed it doesn't flip flop?
Any ideas?
Thanks, Mark
Re: Switch Flip Flop
- Be sure to use a pull-up resistor on the switch contact, mounted close to the ESP
- Don't use very long wires (>5 meters could be problematic, depending on conditions)
- Use a longer de-bounce time (max possible is currently 250 msec)
- Don't use very long wires (>5 meters could be problematic, depending on conditions)
- Use a longer de-bounce time (max possible is currently 250 msec)
/Ton (PayPal.me)
Re: Switch Flip Flop
You could also place a small capacitor over the GPIO pin and the GND.
Something like 100 nF, but capacity doesn't really matter as long as it isn't too large.
This will cause a slight delay in the processing of the switch, but for a door this doesn't matter a lot.
What it also does, is prevent short electromagnetic signals to be picked up by the wires as signals.
Something like 100 nF, but capacity doesn't really matter as long as it isn't too large.
This will cause a slight delay in the processing of the switch, but for a door this doesn't matter a lot.
What it also does, is prevent short electromagnetic signals to be picked up by the wires as signals.
Re: Switch Flip Flop
Hi Ath and TDer,
Thank you for your replies. I wonder, could you please point me towards an example circuit diagram? I know my way around electronics but have no knowledge of hooking up a reed switch utilising a resistor or capacitor. A diagram would be a massive help.
Thanks, Mark
Thank you for your replies. I wonder, could you please point me towards an example circuit diagram? I know my way around electronics but have no knowledge of hooking up a reed switch utilising a resistor or capacitor. A diagram would be a massive help.
Thanks, Mark
Re: Switch Flip Flop
The generic pull-up resistor would look like this Wikipedia page describes: https://en.wikipedia.org/wiki/Pull-up_resistor
When combining a resistor and a capacitor, this discussion seems appropriate. (Just use the capacity TD-er suggested, not 10 uF)
Both situations assume that the switch (either a reed switch or regular switch) connects the I/O pin to ground when active.
When combining a resistor and a capacitor, this discussion seems appropriate. (Just use the capacity TD-er suggested, not 10 uF)
Both situations assume that the switch (either a reed switch or regular switch) connects the I/O pin to ground when active.
/Ton (PayPal.me)
Re: Switch Flip Flop
In short, a pul-up resistor may pull the voltage of the connected GPIO pin to the same level as on the other side of the resistor unless it is pulled down.
So your reed switch may pull it down as the resistance of the reed switch is close to 0, especially compared to the resistance of the pull-up resistor (typically in the order of 10k)
Thus reed switch closed, level low, reed switch open, level high.
A reed switch may "bounce" a bit when almost closed or being closed.
A capacitor may help to limit this bouncing a bit as the response of the signal is delayed a bit by the capacitor. (it takes longer for a voltage to change)
The wires to the reed switch act as an antenna and thus generate voltage changes, which will be dampened by the capacitor.
The "schematic":
Vcc -> pull-up resistor -> GPIO pin -> capacitor -> GND
Your reed switch will be connected on the GPIO pin and GND.
You may also want to try to twist the wires to the read switch, the same as is done in UTP cables.
So your reed switch may pull it down as the resistance of the reed switch is close to 0, especially compared to the resistance of the pull-up resistor (typically in the order of 10k)
Thus reed switch closed, level low, reed switch open, level high.
A reed switch may "bounce" a bit when almost closed or being closed.
A capacitor may help to limit this bouncing a bit as the response of the signal is delayed a bit by the capacitor. (it takes longer for a voltage to change)
The wires to the reed switch act as an antenna and thus generate voltage changes, which will be dampened by the capacitor.
The "schematic":
Vcc -> pull-up resistor -> GPIO pin -> capacitor -> GND
Your reed switch will be connected on the GPIO pin and GND.
You may also want to try to twist the wires to the read switch, the same as is done in UTP cables.
Re: Switch Flip Flop
I found these diagrams.
This one with a capacitor and resistors:-
And this one... with just a resistor:-
I am thinking it might be an idea to start with the resistor first... or not?
This one with a capacitor and resistors:-
And this one... with just a resistor:-
I am thinking it might be an idea to start with the resistor first... or not?
Re: Switch Flip Flop
The resistor should be used anyway.
Either you have it already in place when you're using a pin which needs a pull-up resistor like GPIO-0 or -2. Or you have checked the "use internal pull-up resistor" in the switch plugin.
Either you have it already in place when you're using a pin which needs a pull-up resistor like GPIO-0 or -2. Or you have checked the "use internal pull-up resistor" in the switch plugin.
Re: Switch Flip Flop
Hi TD-er,
Funny you mention the pull up resistor option in the switch device settings. When I tick the Internal PullUp option the reed switch never detects the door is open, yet when the Internal PullUp is un-ticked the door is detected opening/closing. I will place a resistor as per the resistor only diagram and see what happens.
Very interesting indeed... keeps me entertained during our COVID-19 lockdown
Funny you mention the pull up resistor option in the switch device settings. When I tick the Internal PullUp option the reed switch never detects the door is open, yet when the Internal PullUp is un-ticked the door is detected opening/closing. I will place a resistor as per the resistor only diagram and see what happens.
Very interesting indeed... keeps me entertained during our COVID-19 lockdown
Re: Switch Flip Flop
Hmm when you're experiencing it like this, I wonder how you connected the reed switch.
Did you maybe connect the reed switch between 3V3 and the GPIO pin?
Did you maybe connect the reed switch between 3V3 and the GPIO pin?
Re: Switch Flip Flop
Enable the internal pull up resistor and connect the reed chip between the GPIO pin and GND.
Just make sure you're not using GPIO-0 or GPIO-2 for this on an ESP8266 as you may then prevent the ESP to boot if the reed switch is closed during reboot.
Just make sure you're not using GPIO-0 or GPIO-2 for this on an ESP8266 as you may then prevent the ESP to boot if the reed switch is closed during reboot.
Re: Switch Flip Flop
That was my original design, but it flip/flopped with that... even with the internal pull up turned on. That prompted me to changed it to the 3v3 <---> GPIO and found it flip/flopped that way as well. I think I will try the physical resistor as per the design above. I am using GPIO-13.
Re: Switch Flip Flop
I really think the resistor doesn't play a big role here.
What you can do if you only have resistors laying around, is place 2 resistors.
The internal pull up is in the order of 50k - 100k, so it is a rather weak one.
What you can consider is this:
3V3 -> R1 -> GPIO -> R2 -> GND
R1 is now your internal pull-up and R2 is now not present. (N.B. the reed sensor will short R2 when closed)
You must make sure the resistance of R2 is quite a bit higher than R1.
I would say a factor 5 - 10.
So if you stick with the internal pull-up, your R2 must be somewhere between 470k and 1M
If you also place one for R1, then just pick something like 10k (or +/- 50%) and pick one for R2 which is 5 - 10x as high.
Advantage of lower resistance is less prone to noise.
Disadvantage is higher power consumption and higher current through the reed switch.
You may also want to twist the wires to the reed switch as this reduces noise considerably.
What you can do if you only have resistors laying around, is place 2 resistors.
The internal pull up is in the order of 50k - 100k, so it is a rather weak one.
What you can consider is this:
3V3 -> R1 -> GPIO -> R2 -> GND
R1 is now your internal pull-up and R2 is now not present. (N.B. the reed sensor will short R2 when closed)
You must make sure the resistance of R2 is quite a bit higher than R1.
I would say a factor 5 - 10.
So if you stick with the internal pull-up, your R2 must be somewhere between 470k and 1M
If you also place one for R1, then just pick something like 10k (or +/- 50%) and pick one for R2 which is 5 - 10x as high.
Advantage of lower resistance is less prone to noise.
Disadvantage is higher power consumption and higher current through the reed switch.
You may also want to twist the wires to the reed switch as this reduces noise considerably.
Re: Switch Flip Flop
Hi TD-er,
Thanks for that. Here's a diagram I've drawn from your advice.
Assuming I have it correct, where would the reed switch connect?
Thanks, Mark
Thanks for that. Here's a diagram I've drawn from your advice.
Assuming I have it correct, where would the reed switch connect?
Thanks, Mark
Re: Switch Flip Flop
The reed switch should be bridging the resistor with the highest resistance.
In rest (reed switch open), the voltage over GPIO & GND = 3V3 * (R2 / (R1 + R2))
Or if you're more familiar to reading ratios.
3V3 is split in the ratio R1 : R2
If you short the reed switch, you end up changing the resistor it bridges to a resistance of close to 0 Ohm.
Let's assume you place it parallel to the lowest resistance (R1), then it will hardly change the voltage over GPIO (to GND) as the ratio is already 1 : 10.
If you place it however over R2, then the ratio changes from 1 : 10 to almost infinity : 1.
Thus if you want "reed closed = 1", then you should use R1 with the highest resistance and the reed switch bridging GPIO and 3V3.
To invert it, use the lowest resistance for R1 and bridge GPIO and GND with the reed switch.
In rest (reed switch open), the voltage over GPIO & GND = 3V3 * (R2 / (R1 + R2))
Or if you're more familiar to reading ratios.
3V3 is split in the ratio R1 : R2
If you short the reed switch, you end up changing the resistor it bridges to a resistance of close to 0 Ohm.
Let's assume you place it parallel to the lowest resistance (R1), then it will hardly change the voltage over GPIO (to GND) as the ratio is already 1 : 10.
If you place it however over R2, then the ratio changes from 1 : 10 to almost infinity : 1.
Thus if you want "reed closed = 1", then you should use R1 with the highest resistance and the reed switch bridging GPIO and 3V3.
To invert it, use the lowest resistance for R1 and bridge GPIO and GND with the reed switch.
Re: Switch Flip Flop
I tried a number of combinations, they didn't work. Ended up using one of these boards... works perfectly.
Thanks for all your help TD-er.
Thanks for all your help TD-er.
Re: Switch Flip Flop
What kind of board is it exactly?
I assume it is a flipflop, but what's the trimmer for?
Setting a level?
I assume it is a flipflop, but what's the trimmer for?
Setting a level?
Re: Switch Flip Flop
Here's the link to the board... basically replaced the 'rain pad' with a connection to the reed switch.
https://www.aliexpress.com/item/3261565 ... 4c4djGpVbg
Essentially the same as this board...
https://www.aliexpress.com/item/1005001 ... web201603_
Still working perfectly
Re: Switch Flip Flop
What is the chip model nr?
It looks like an opamp.
Edit:
Ah found a similar looking board, which does have a schematic mentioned:
https://nl.aliexpress.com/item/32764113 ... 3dfewY59YN
Is indeed an opamp.
And it uses 100 nF (10 with 4 zeroes in pF) to filter out noise with a pulse duration of 0.001 sec = 1 msec.
Used this time constant calculator
It looks like an opamp.
Edit:
Ah found a similar looking board, which does have a schematic mentioned:
https://nl.aliexpress.com/item/32764113 ... 3dfewY59YN
Is indeed an opamp.
And it uses 100 nF (10 with 4 zeroes in pF) to filter out noise with a pulse duration of 0.001 sec = 1 msec.
Used this time constant calculator
Re: Switch Flip Flop
Looks exactly like the board I used, and it works well. I must confess, I still dont understand why the other solutions didn't work? Perhaps the distance?
Re: Switch Flip Flop
Looking at the schematic, it does provide some filtering and setting a threshold.
So what it does is very similar to the resistor + capactor I suggested.
With as extra, it allows to tune the level at which it will switch over.
The capacitor does get charged via the 10k resistor on the board, which takes a while. (depending on the resistor + capacitor values)
In this setup the so called "RC-time" is 1 msec, meaning it does take 1 msec to go from 0 to roughly 70% of the charge voltage.
A pulse introduced by noise may have a shorter duration and/or a lower voltage (which is used to charge the capacitor) so it will not cross the level change threshold.
The trimmer on the board can be used to set the level at which you need to trigger a change, which makes it much more flexible, so I would say the perfect solution for your setup.
So what it does is very similar to the resistor + capactor I suggested.
With as extra, it allows to tune the level at which it will switch over.
The capacitor does get charged via the 10k resistor on the board, which takes a while. (depending on the resistor + capacitor values)
In this setup the so called "RC-time" is 1 msec, meaning it does take 1 msec to go from 0 to roughly 70% of the charge voltage.
A pulse introduced by noise may have a shorter duration and/or a lower voltage (which is used to charge the capacitor) so it will not cross the level change threshold.
The trimmer on the board can be used to set the level at which you need to trigger a change, which makes it much more flexible, so I would say the perfect solution for your setup.
Who is online
Users browsing this forum: Ahrefs [Bot] and 34 guests