Need help with touchless on/off switch - detailed working principle and ltspice - Page 1
Forum section: electronics / beginners

author: Ayya
author_rank: Newbie
timestamp: March 22, 2021, 06:30:33 pm
content: First of all i would like to say hello to all of you as it's my first post here.I came here because obviously i need help. To be more specific i'm working with a circuit that will act something like wireless/touchless switch.I have those 2 schematic. Schematic 1 is the one i'm basing on my project and 2nd is what modifications i've done.D2 is a IR diodeIC1 is a CA3140 op amp ( in lt spice i used a universal op amp)Q2 is replaced by the suggestion of teacher on MOSFET transistor ( still dont know which one exactly i need to use)Q1 is a phototransistor ( in lt spice schematic it'a current source because it's easier to implement it there)R4 is a potentiometer used to set a sensivity (in lt spice i did a voltage divider because of same reason as Q1)I replaced D1 and RL1 by inserting a diodeHere i added a D flip flop.The working principle i'm planning to achieve is when voltage source of 5 V is connected, a IR diode emits it's rays on phototransistor (right?) Q1 and when u pass a hand over IR Diode it should light up the LED behind mosfet and when you pass a hand 2nd time over IR diode it will switch off. Dflop is here to provide such an action.Next for what i've already searched on and i think i know that when hand is passed over IR Diode pin 3 non inverting it's turning into high state right?. Pin 2 - inverting is connected to potentiometer and it works only for sensivity (right?) So now a result of turning pin 3 ino high state the signal goes on a pin6 output and it is remembered by d flop and led is lighted up and so turn it off second hand move is needed?I don't know if i explained it well but thanks for any help.

author: drussell
author_rank: Super Contributor
timestamp: March 22, 2021, 07:21:09 pm
content: Are you essentially asking for someone to do your homework assignment for you instead of you experimenting to discover how things work?

author: Ayya
author_rank: Newbie
timestamp: March 22, 2021, 07:26:46 pm
content: Obviously not, all i'm asking is a little help with understanding it, i'm a completly newbie with lt spice as well and can't operate it that good to check if it's either working or not. If this isn't right place to ask such a questions tell so and i will delete my thread. Thanks.

author: StillTrying
author_rank: Super Contributor
timestamp: March 22, 2021, 10:28:35 pm
content: Have you right-clicked over the D flip flop and set Vhigh 5V, the digital parts default to 1V.An easy way to simulate a photo transistor is to use the one in an opto isolator and supply a couple of mA to it's input LED.Here's a working version to tweak.

author: Ian.M
author_rank: Super Contributor
timestamp: March 22, 2021, 11:37:07 pm
content: Actually, LTspice A device digital primitives need a couple more settings to reliably behave as you would expect an ordinary CMOS logic gate to. Ignoring output impedance (as the series 3K3 resistor swamps it), and slew rate (as its negligible with respect to the RC time constant with the MOSFET gate capacitance), you *should* set:Code:Vhigh=5, Td=14n, Tripdt=2nin the component attribute editor, which is based on the typical propagation delay of a 74HC74 @5V Vcc.If you don't set an appropriate propagation delay more complex sequential logic will often fail to behave as expected.Tripdtcontrols how closely spaced simulation timesteps are round gate transitions (if nothing else is forcing close timesteps), and is required to get LTspice to honor specified propagation delays and rise/falltimes. SeeLTspice Help: LTspice(R): Circuit Elements: A. Special Functionsfor details of other A device parameters.N.B. setting separateRhighandRlowrather than a singleRoutcan make the simulation an order of magnitude slower!N.B.2. You can use any of the four attributesValuethroughSpiceLine2for A device parameters, and also control whether or not each attribute is visible on the schematic. In logic designs with a variety of propagation delays, I like to make that visible, though you may wish to put the other parameters that are common to all or most gates in a different attribute and hide them to avoid an excessively cluttered schematic.

author: Ayya
author_rank: Newbie
timestamp: March 23, 2021, 06:06:25 pm
content: Quote from: StillTrying on March 22, 2021, 10:28:35 pmReally appreciate your help. Thank you very much but it lead me to another questions. Really sorry if they are trivial and stupid but ye...i haven't changed anything to dflop my bad. I noticed that in your ltspice simulation when i'm checking the voltage over the wires form voltage source the signal is square and in mine is straight line, what causes this? I've tried adding coil as a relay to see if it's it but no. And 2nd question what is the purpose of this 1Meg R5 connected to the I/O ouf op-amp? It's a inverting op amp to ensure it stability in simulation?And 3rd question - how you choosed those values to current source? They are realted to how much current would phototranistor give?Quote from: Ian.M on March 22, 2021, 11:37:07 pmThank you very much for those informations, they will certainly help with me the next steps where i will have to perform a simulations, for now i'm stuck on what parameters should i choose for current source, and why those.

author: Ian.M
author_rank: Super Contributor
timestamp: March 23, 2021, 07:36:25 pm
content: Post (attach) your sim .asc file, then we can check what you are doing wrong.I would suspect you haven't set appropriate rise and fall times ( PULSE() source fourth and fifth parameters).There's a trap for 'young players': the pulse source ON time does *NOT* include the risetime. See my comments on PULSE() sources here:https://www.eevblog.com/forum/projects/where-is-my-error-in-this-ltspice-simulation/

author: StillTrying
author_rank: Super Contributor
timestamp: March 23, 2021, 10:05:01 pm
content: Quote from: Ayya on March 23, 2021, 06:06:25 pmI'd given the 5V voltage source 0.2R of internal resistance, the supply voltage drops a bit when the relay draws current, it's not really needed in this simple simulation."what is the purpose of this 1Meg R5 connected to the I/O ouf op-amp?"It's just a bit of positive feedback, often needed when the input to a comparator is a slowly changing signal such as a shadow which you want to change into an output pulse with fast edges."how you choosed those values to current source? They are realted to how much current would phototranistor give?"Yes just a guess that there'd be about 1mA flowing through the photo transistor when it's in the IR beam and reduced to 0.1mA when it's in the shadow, about the only way to get closer values would be to measure them.