This is not Arduino related, but I have an interesting problem that I hope someone more electrically inclined can help me with (I'm more mechanically inclined myself). Here's the problem: I have a drawer and I want an LED to turn on when the drawer passes the halfway point as the drawer closes. When the drawer is closed completely, the LED will turn off. However, I do not want the LED to turn on when the drawer is being opened. I would like to keep the solution as simple and "dumb" as possible, so I would like to avoid a microprocessor if possible.
I have already looked at JK flip-flops, but haven't been able to find much practical information on how to implement one of these in a physical circuit.
I have also looked at hall-effect sensors, but I haven't been able to find any that have a "directionality" to them.
A single optointerrupter (A) at the beginning of travel point, a pair of optointerrupters (B and C) at the midpoint, and a single optointerrupter (D) at the end of travel point.
Detect the transition of B = true followed by C = true, turn light on, detect transition of D = true, turn light off.
Remove A from system altogether, as it turns out that it is not required. Might come in handy for some other project.
If you want to do this without the use of a microcontroller, then I think that you will need to use a mechanical cam to activate the switch.
You could do this by cutting a tapered cam profile in a long piece of plastic or wood that is mounted to the drawer. The cam would need to be hinged in such a way to allow the cam follower (attached to a micro switch) to activate the switch when the drawer is being closed . . . yet take a slightly different path (bypassing the cam) when the drawer is being opened.
Some ball point pens that operate by pushing the button once to extend and pushing it a second time to retract, work on a similar principle.
I've found some good information about how flip flops work, but I'm still unsure how I would physically implement it. Do you know where I could find a sample schematic of one being used?
Apply power with the drawer open, the light will come on because both FFs are set by the RC circuit.
1/2 close drawer, FF1 gets clocked with 1 on D, light stays on. FF2 changes state.
Drawer closed, FF1 gets reset, light off.
Open drawer, at 1/2 pos FF1 is clocked but has 0 on D so no light. Also FF2 changes state.
Close drawer, at 1/2 position FF1 gets clocked with 1 on D, light stays on. FF2 changes state.
Drawer closed, FF1 gets reset, light off.
etc etc.
I think that's about right although my brain hurts when I do this stuff and I often get my levels arse about face.
The 1/2 closed switch should provide a positive level and MUST be debounced, the closed switch input should provide a low level and doesn't need to be debounced.
No need for flip flops or any electronic parts other than some switches. Use two microswitches. On switch #1, connect the common terminal to +V and the NC terminal connects to the NO terminal of switch #2. Common terminal of switch #2 connects to one side of light bulb or LED. Other lead of light goes to ground.
When drawer is closed, one of the two switches is open and the other is closed -- light off. When drawer is half open, one switch is closed and the other is open -- light on. If drawer is opened past the second switch, one switch is open and the other is closed -- light off.
@Rob - That helps a lot. I've been trying to understand this logic stuff for a while now and that explanation clears some things up for me. I have one question though: Should the 1/2 closed switch be a momentary switch, or does it need to remain closed while the drawer is closed?
Both switches would be momentary, the FFs remember the state. The "closed" switch would in fact remain activated when the drawer is closed, but that doesn't matter.
There are no end of limit switches good for this.
@flyboy. I like the idea of not using any logic at all, but does this differentiate between opening and closing the drawer?
A flipflop circuit is nice but will be plagued by contact bounce.
A switch could detect direction of motion by dragging a probe on the side of the drawer, closed only during drawer close. A simple cam could close and open another switch at the correct times.
I made an assumption in reading your requirements that it didn't need to be directional. If it does indeed have to be directional, a flip flop or some other electronic logic would probably be required.