Hi,
Is there a simple hardware way of making a SPST toggle switch work like a momentary switch on every state change? It would have to send momentary low signal for say 100ms.
Thanks.
Hi,
Is there a simple hardware way of making a SPST toggle switch work like a momentary switch on every state change? It would have to send momentary low signal for say 100ms.
Thanks.
Use the technique in the state change detection example to detect the transition from off to on (or visa versa) and send the 100ms pulse when the right transition is detected.
groundFungus:
Use the technique in the[ state change detection example
[/quote]But that's a software solution. OP asked:
Seedler:
Is there a simple hardware way
Right. I misinterpreted the requirement. You could use the switch to trigger a 555 timer in monostable mode, but it would be much simpler to do it in software if an Arduino is involved. If an Arduino is not involved then this is the wrong forum.
Hi,
I know how to do it using an Arduino and code, but I thought that was over complicating things, and was just wondering is there was a simpler solution.
Sorry if this is wrong place to post.
Ill look into 555 timer. Thanks for your help
Yes, an exclusive-OR gate (74HC86). Use one gate to buffer the switch and its pull-up, then that goes directly to one input of the second gate and also to the second input via a series resistor and parallel capacitor of the required time constant.
The simplest way is to connect the comm pin to the Arduino input with a pull-down resistor to ground, and the
other two pins to Vcc.
No need for anything more complicated, unless this is a make-before-break switch (which is very unlikely).
(Whoops, I misread it as a SPDT, not SPST - for SPST you need an RC delay and XOR gate normally.)
You could probably make something work with a capacitor in series with your switch and a resistor for charging/discharging the other terminal slowly. You might have to put in a schottky diode or something, somewhere to avoid negative voltages while switching the switch back off again.
I'd still prefer doing it in software though!
Paul__B:
Yes, an exclusive-OR gate (74HC86). Use one gate to buffer the switch and its pull-up, then that goes directly to one input of the second gate and also to the second input via a series resistor and parallel capacitor of the required time constant.
I haven't played with logic gates before. I'll probably need more explanation. Tell me if this is correct what I'm thinking. So I have two wires coming from my switch. One is connected to ground and the other to 3.3v via a pullup resistor. These wires are then connected to input A and B of the first gate, 3.3v pullup side to A and ground side to B. When the switch is open, input A is at 3.3v and input B is at 0v, so the gate outputs 3.3v. When the switch is closed both A and B are connected to ground, so the gate outputs 0v. Is that correct so far?
After that I am lost. Do capacitors conduct until they are charged? And then act like a brake in the circuit? What is the resistor doing?
MarkT:
The simplest way is to connect the comm pin to the Arduino input with a pull-down resistor to ground, and the
other two pins to Vcc.No need for anything more complicated, unless this is a make-before-break switch (which is very unlikely).
I thought of this, but not all switches have com and two pins. Some are just SPST.
GeronimoDK:
You could probably make something work with a capacitor in series with your switch and a resistor for charging/discharging the other terminal slowly. You might have to put in a schottky diode or something, somewhere to avoid negative voltages while switching the switch back off again.Why does pulsed DC pass through a capacitor? - Electrical Engineering Stack Exchange
I'd still prefer doing it in software though!
Could you explain this more? I am still considering code. Its just nice to know all the options
Thanks.
Seedler:
Could you explain this more? I am still considering code. Its just nice to know all the options
You can't change the voltage across a capacitor instantaneously; so what happens is if you apply 5V to "the left side" of a discharged capacitor is that the right side will also be 5V if it's not connected to any kind of voltage/current source!
If you have a resistor to ground to slowly charge/discharge on the right side of the capacitor what will happen is when you go from 0V to 5V on the left side, the right side will also go to 5V instantaneously, but then slowly discharge back to 0V following an exponential curve.
You can calculate the time it will take to discharge to a certain voltage:
https://www.electronics-tutorials.ws/rc/rc_1.html
The chip on the Arduino has a certain voltage threshold above which it will read HIGH and another below which it will read LOW if configured as a digital input. You can use the above mentioned capacitor and resistor discharge curve to calculate the discharge time to LOW voltage level.
Now you may have a problem when you switch back to 0V; if you have 5V more on the left side of your capacitor than on your right side, in the instant you switch your switch back to 0V you will have -5V on your right side until the capacitor has charged back to 0V! This is why you may need to put a reverse schottky diode in parallel with your resistor to avoid damaging your digital input (I think somewhere in the region of -0.3 to -0.2V on the input shouldn't hurt it, but better look it up)
Seedler:
I haven't played with logic gates before. I'll probably need more explanation.
OK, just for you, here is the circuit. I have marked it as 5 V - clearly that does not matter.
OK, just for you, here is the circuit. I have marked it as 5 V - clearly that does not matter.
Thanks, so how does this give a 0v pulse if the switch is turned on or off. I know I'm definitely reading it wrong, but it looks like either a high or low output continuously.
The pin I will be connecting the output of the second XOR to will be pulled high and needs a 0v pulse to switch. Sorry I'm not getting this
I will get a 74HC86 and experiment
If you have a resistor to ground to slowly charge/discharge on the right side of the capacitor what will happen is when you go from 0V to 5V on the left side, the right side will also go to 5V instantaneously, but then slowly discharge back to 0V following an exponential curve.
You can calculate the time it will take to discharge to a certain voltage:
Will that not give me a 5v pulse? I need a 0v or ground pulse when the switch is either opened or closed.
Thanks.
Seedler:
Thanks, so how does this give a 0v pulse if the switch is turned on or off. I know I'm definitely reading it wrong, but it looks like either a high or low output continuously.The pin I will be connecting the output of the second XOR to will be pulled high and needs a 0v pulse to switch. Sorry I'm not getting this
Oh, now you want a LOW pulse instead of a HIGH pulse!
Grumble ... grumble ...
Empty imported post
Paul__B:
Oh, now you want a LOW pulse instead of a HIGH pulse!Grumble ... grumble ...
One last question just to be annoying
Do these chips work on 3.3v?
That you so much for all the help you have given over the years
The 74HC86 data sheet will tell you the recommended supply voltage range.
Seedler:
Will that not give me a 5v pulse? I need a 0v or ground pulse when the switch is either opened or closed.
Yes it will, you didn't say that before, but if you think a little about it it's just a question of rewiring the components, if you have the charge resistor to 0V or to 5V really doesn't make much difference!
Now however you will have a problem when switching back to 5V that you may get an over voltage peak, and you still need the schottky diode to not damage your input.
To be honest I did miss the part about the switch being SPST, I thought you had a SPDT and I did have that in mind. It should however still be possible with a SPST, but you will need another resistor in the circuit.
EDIT:
You could try something like R2 = 560, R1 = 5k6, C1 = 22µF
I put those values in a simulator (by trial and error) and it looks okay
groundFungus:
The 74HC86 data sheet will tell you the recommended supply voltage range.
Thanks. Sorry I got lazy
GeronimoDK:
To be honest I did miss the part about the switch being SPST, I thought you had a SPDT and I did have that in mind. It should however still be possible with a SPST, but you will need another resistor in the circuit.
Thanks, I like the look of that. I'll give it a try also
Seedler:
Thanks, I like the look of that. I'll give it a try also
You can, but you originally stated you wanted a pulse on both opening and closing the switch which is what the circuit I gave - and no other that has been cited here so far - provides.
I have not however included de-bouncing, if that is required. Of course, it gets more complicated and clearly if you are using a microcontroller, it is absurd to use any hardware at all to do what the microcontroller does easily and with complete reliability.
You can, but you originally stated you wanted a pulse on both opening and closing the switch which is what the circuit I gave - and no other that has been cited here so far - provides.
Paul_B, it works like a charm. Thank you