Simple circuit for spinning a motor, pausing, then spinning the other way - Page 1
Forum section: electronics / beginners

author: vranghel
author_rank: Contributor
timestamp: May 30, 2022, 10:14:12 am
content: Hi everyone,I'm an electronics hobbyist (beginner level) who likes to dabble with building different simple circuits (mostly solar).Since I do not have the expertise to design my own circuit, and google did not help, I'd pose the question to the highly knowledgeable members of this forum:I'm looking to build a very simple analog circuit (made of vanilla components, so no specialized chips) that spins a small (3-4V) geared motor one direction, stops for about 15 minutes then spins the other way, stops for 15 minutes and so on. The motor needs to stop in a certain position therefore a limit switch could be used. Preferably, the circuit would be run off a Li-Ion battery or directly from a 5V batter bank. I looked into a H-bridge to control the direction of the motor. The circuit doesn't need to be very accurate in terms of time, and ideally I'd be able to adjust the time with a potentiometer.This circuit would be used to periodically rotate a small 10 cm tall decorative hourglass once the sand has run out.Thanks!

author: Doctorandus_P
author_rank: Super Contributor
timestamp: May 30, 2022, 10:57:46 am
content: An H-bridge needs at least 4 "power" transistors and two smaller transistors to drive them. What's wrong with using something like an A4950? They can be bought cheap on breakout boards.You can put the end switches directly in series with the motor. That way the motor stops when one of the switches is hit.But the motor has to be able to run back, even when it's leaning against a switch, so bridge each of the switches with a diode. The diode has to be able to pass the full motor current.For a 15 minute delay something like a NE555 will be difficult (maybe you can go that far with the CMOS version, but it would require high value resistors, and low leakage electrolytic capacitors. 15 minutes = 900 seconds, so 1Mega Ohm and 1000uF may get you there.Something like a CD4060 is much better for longer times. It can easily reach a day or two.But there is a potential problem here. You may damage your motor driver transistors if you put switches between the transistors and the motor. Putting a TVS over the motor may help here

author: SmallCog
author_rank: Frequent Contributor
timestamp: May 30, 2022, 11:00:28 am
content: Good excuse to play with a 555 timer for the interval timing. There’s a bunch of other options but if you’ve not experimented with a 555 before then now’s as good a time as any.If you’ve not played with 74 series logic then chuck some of that in there to toggle between directions with the clock pulses from the 555OR a few lines of code in an arduino

author: Doctorandus_P
author_rank: Super Contributor
timestamp: May 30, 2022, 11:11:11 am
content: Instead of an H-bridge you can also use a DPDT relay.So a motor, two end switches, two diodes, a relay, and that just leaves the power supply and timing.Having a relay on for 50% of the time will drain the battery though. Maybe using two relays or a latching relay is a better option.

author: Ian.M
author_rank: Super Contributor
timestamp: May 30, 2022, 11:48:13 am
content: Any long-period discrete analog time-keeping function should be avoided at nearly any cost. Your 15 minute period implies either the baroque complexity of a digital divider chain built out of discrete components i.e. Eccles Jordan bistable (flip-flop) circuits with steering diodes, to get the oscillator frequency up to a more reasonable range, or a RC time constant of approx. 1000 (exact value depends on voltage thresholds. The math says a 1 Meg resistor and a 1000 uF capacitor would do the job, but the math doesn't allow for leakage currents. With a 5v supply, on average the resistor is only going to be passing a couple of uA, but an electrolytic capacitor of that value is likely to be specified to have a max. leakage current of a few tens of uA, so unless you are very lucky and pick a capacitor that's at the extreme low leakage end of the bell-curve, the leakage current will dominate, leading to grossly incorrect timing, or even total failure to reach the end of the timing period.Also analog timing circuits aren't known for their low power consumption. The quiescent current drawn from the battery by the timing circuit is likely to be greater than the average motor current as it has such a low duty cycle.Nowadays, even with the supply chain issues, any sane engineer would say "Use a MCU." Even the lowliest 8 pin PIC or AVR, or one of Padauk's sub $0.04 MCUs can do the job with code space and pins to spare. It comes down to availability and cost of development tools. If you don't already have any sort of MCU experience and tools, €5.49 will get you a Digispark Rev 3 clone with an ATtiny85 MCU on it, self-programmable over USB using the Arduino IDE.Back in the day, before cheap easily reprogrammable MCUs, this would have been a job for 4000 series CMOS logic. The chip of choice would be theCD4060(or one of its many second source equivalents) which has an on-chip oscillator suitable for RC timing, crystals and resonators + a 14 stage binary divider chain. To toggle the final output with a 30 minute period, (so it can directly be used to control the H-bridge for a motor wired with diode across its limit switches so it stops at each limit till the drive voltage to it is reversed), would require its oscillator to run at fractionally over 9 Hz, entirely practical for a RC timing circuit with reasonable resistor and capacitor values. Nowadays one might choose the 74HC4060, which is better for 5V and lower supply voltages.Go back 50 years or so before RCA added the CD4060 to their new 4000 series CMOS product range (launched in 1968), and there was a short window of probably less than a decade when a fairly large board full of transistor flip-flops and logic would have been the preferred solution. Before that, a chain ofDecatroncounters dividing down the mains line frequency would have been the preferred electronic implementation, but in nearly all cases an electromechanical solution of a high reduction ratio synchronous gearmotor driving a cam operated switch would have been preferred, because it was far far smaller, cheaper, lower power and more reliable than a chassis full of 30 Decatrons!

author: vranghel
author_rank: Contributor
timestamp: May 30, 2022, 11:58:57 am
content: I've looked at CD4060 and might be the chip i need for timing:https://www.build-electronic-circuits.com/4000-series-integrated-circuits/ic-4060/However, I do not know how to integrate the chip into the H-bridge circuit with diodes.Would you be able to draw a quick and dirty schematic?EDIT: I have found CD4040 in my parts bin, which apparently is a CMOS 12-Stage Ripple-Carry Binary Counter/Divider, very similar to the CD4060 which is a CMOS 14-Stage Ripple-Carry Binary Counter/Divider and Oscillator

author: themadhippy
author_rank: Super Contributor
timestamp: May 30, 2022, 12:16:46 pm
content: The CD4040 requires a clock to make it work,the cd4060 has a built in "clock" so only needs a couple of resistors and a capacitor added to get it running.

author: vranghel
author_rank: Contributor
timestamp: May 30, 2022, 12:21:17 pm
content: Quote from: themadhippy on May 30, 2022, 12:16:46 pmOh, I see now;I have CD4017, which, according to the datasheethttps://www.ti.com/lit/ds/symlink/cd4017b.pdf?ts=1653912905120&ref_url=https%253A%252F%252Fwww.ti.com%252Fproduct%252FCD4017B%253FkeyMatch%253DCD4017, I think also has a clock?

author: ledtester
author_rank: Super Contributor
timestamp: May 30, 2022, 12:28:57 pm
content: Use the CD4060 to provide the 15 minute clock signal to the 4017.This page describes how to get long timing periods out of the 4060:https://www.gadgetronicx.com/how-to-build-24-hours-timer-circuit-cd4060/

author: Ian.M
author_rank: Super Contributor
timestamp: May 30, 2022, 12:34:09 pm
content: Like the CD4040, the CD4017 requires an external clock. It also only divides by 10, useless for the timing part of your application. However if clocked once every three minutes, it could be useful to drive a discrete complimentary MOSFET H-bridge from its '0' and '5' decoded outputs, without risk ofshoot-through.How to drive an H-bridge from a CD4060 depends on what control inputs the H-bridge has, and for your application, depends on how you implement the limit switches. If you use logic level limit switches its considerably more complex than if they are beefy enough to carry the motor current.Readhttps://www.eevblog.com/forum/beginners/my-12v-dc-motor-is-not-turning/starting at reply #18 noting my comments to get an idea of how simply reversing the motor supply can make it run till it stops at the limit switch. If you've only got ONE limit switch and want the mechanism to do a (nearly) complete rotation, it must be DPST-NC (or DPDT) so electrically it can be wired as-if it was two separate switches.Tell us about your H-bridge or ask us to help you pick or design one.

author: ledtester
author_rank: Super Contributor
timestamp: May 30, 2022, 12:45:52 pm
content: I can imagine that the CD4017 would be useful for implementing the state of the application. It is a flexible way of programming a cycle of up to 10 states.The OP's application only requires 4 states:state 0: drive the motor forwardstate 1: turn off the motorstate 2: drive the motor backwardsstate 3: turn off the motorOnce an H-bridge has been selected we can figure out how to use the outputs of the 4017 to drive the inputs of the H-bridge.

author: vranghel
author_rank: Contributor
timestamp: May 30, 2022, 12:49:18 pm
content: Quote from: Ian.M on May 30, 2022, 12:34:09 pmThanks Ian. Seems I have to order a CD4040. I read your comment in the other thread and I think I get the general idea: Wire the NC switch with a diode, so even when the switch is open, the diode allows it to conduct the other way, so it can reverse until it opens the other NC switch.As for the H bridge, I do not have one in mind, so I'm definitely open to ideas/suggestions, and how to combine the 2 circuits and the switches. The motor running will require low current, most likely under 100mA

author: Ian.M
author_rank: Super Contributor
timestamp: May 30, 2022, 01:05:28 pm
content: *NO* order a '4060', not a '4040' e.g CD4060, MC14060, HEF4060, NTE4060 etc. or a 5V logic version of it, e.g. any brand of 74HC4060 or 74HCT4060, because you *WANT* that built in oscillator to keep the circuit simple.If a running brushed DC motor draws 100mA, odds are its stall current, which it will transiently draw if starting from standstill or reversing will be of the order of 1A.What junk bin power transistors do you have capable of handling >1A? N.B. you need 2x PNP + 2x NPN, or 2x PMOS and 2x NMOS. If using MOSFETs, they must have a min. Vgs threshold voltage <2.5V to ensure you can turn them fully on from only 5V level logic signals.If the answer is none or not enough, you'll probably be best off buying a H-bridge chip or module.

author: vranghel
author_rank: Contributor
timestamp: May 30, 2022, 01:18:37 pm
content: Quote from: Ian.M on May 30, 2022, 01:05:28 pmAh sorry, I meant 4060, but wrote it wrong, since I was looking at both datasheets side by side.I am wondering is there is a way to create an H bridge out of only 2 switches and diodes as seen here:https://en.wikipedia.org/wiki/H-bridge#/media/File:H_bridge_operating.svgUsing the adjustable timer section circuit of the page:https://www.build-electronic-circuits.com/4000-series-integrated-circuits/ic-4060/might work, but I need the timer to reset itself after each run, so when the motor trips the switch

author: Ian.M
author_rank: Super Contributor
timestamp: May 30, 2022, 01:24:59 pm
content: No. A H-bridge needs min. four switching elements. It may also need four diodes to handle the back-EMF from the motor.You don't need the counter/timer to reset after each run. Use a MOSFET H-bridge which draws negligible current when ON in either direction, with the motor disconnected, use limit switches that disconnect the motor till its drive is reversed, and let the counter/timer free-run, simply reversing the H-bridge direction once every 15 minutes.

author: vranghel
author_rank: Contributor
timestamp: May 30, 2022, 01:42:56 pm
content: Would 74HC4060 (https://www.ti.com/lit/ds/symlink/sn74hc4060.pdf) work as a drop in replacement for CD4060?

author: Ian.M
author_rank: Super Contributor
timestamp: May 30, 2022, 01:49:14 pm
content: Sure, up to abs. max. 6V supply. Above that voltage, odds are it would let the magic smoke out!

author: vranghel
author_rank: Contributor
timestamp: May 30, 2022, 02:03:44 pm
content: Any suggestion of an H bridge circuit to use with 4060?

author: vranghel
author_rank: Contributor
timestamp: May 30, 2022, 02:14:45 pm
content: Quote from: Ian.M on May 30, 2022, 01:05:28 pmSince it might be easier, I will order L293D:https://www.ti.com/lit/ds/symlink/l293d.pdf?ts=1653919565123&ref_url=https%253A%252F%252Fwww.ti.com%252Fproduct%252FL293D

author: Ian.M
author_rank: Super Contributor
timestamp: May 30, 2022, 02:25:18 pm
content: *DON'T* buy a L293D. Its a bipolar H-bridge and has excessive voltage drop for low voltage use. See its datasheet section 6.5 Electrical Characteristics. Voh is typ. 1.4V below Vcc and Vol typ. 1.2V above ground, and you'll loose a bit more in the diodes to permit reversing out of the limit across your limit switches, leaving you with 2V or less at the motor with 5V Vcc. Also note its Icc1 and Icc2 supply currents, which IMHO make it unsuitable for a long-duration low power battery powered application.Discrete complimentary BJTs can be driven hard enough to get the total voltage drop under 1V, so suitable for a 5V motor, but the drive circuit quiescent current will be excessive for a battery applicationYou need either a CMOS fully integrated H-bridge IC (beware of H-bridge controllers that need you to add external MOSFETs) or four low Vgs threshold MOSFETs, two each N channel, and P channel.

author: RoGeorge
author_rank: Super Contributor
timestamp: May 30, 2022, 02:31:12 pm
content: Quote from: vranghel on May 30, 2022, 10:14:12 amTo turn an hourglass it would be enough only one direction, so no need for a H-bridge.

author: Ian.M
author_rank: Super Contributor
timestamp: May 30, 2022, 02:36:05 pm
content: Possibly, but that depends on the hourglass mechanism permitting continuous rotation. It would certainly be simpler - drive the motor with a low-side transistor, controlled by a 4060 output. The limit switch would be capacitively coupled to the 4060 RST pin, to reset the 4060, turning off the motor and restarting the timer when the limit position is reached.

author: Terry Bites
author_rank: Super Contributor
timestamp: May 30, 2022, 02:44:56 pm
content: Here's a simple bridge.https://thecodeprogram.com/h-bridge-circuit-and-control-a-dc-motorThe diodes are essential or back emf will kill the transistors- 1N4148s will do. What current do you expect/ measure does your motor need? A little gear motor would work well here. It redcues the current requirment for a given torque and reduces shock on your motor and glassware.

author: Zero999
author_rank: Super Contributor
timestamp: May 30, 2022, 03:05:39 pm
content: I'd just use a DPDT relay, as it's a low current motor.VDDcan be connected to +V and 0V to VSS. The circuit is drawn with them separate, so the motor can be isolated from the control circuit if necessary.D1 and D2 need to be rated to the motor's current.D3 can be smaller, but it might as well be the same as D1 & D2 to simplify the parts list.The input goes to the 4060's output. The 4060 should be set for a period of 30 minutes. SW1 and SW2 are limit switches, which again need to be able to pass the motor's full current. Check pushing the appropriate switch prevents the motor from rotating in the direction which would cause it to stall when limit it reached. It's probably easier to swap the motor connections if it's wrong.K1 is a DPDT (Double Pole Double Throw) relay with the appropriate coil voltage for the control circuit and contact rating for the motor current.It's possible to do this with transistors, but it's more complicated.

author: vranghel
author_rank: Contributor
timestamp: May 30, 2022, 03:13:01 pm
content: Quote from: Ian.M on May 30, 2022, 02:25:18 pmI have cancelled the orderQuote from: RoGeorge on May 30, 2022, 02:31:12 pmYou're totally right, it only needs to spin in one direction, trip the switch so it stops, wait 15 minutes, do half a turn and stop when it trips the switch.Quote from: Ian.M on May 30, 2022, 02:36:05 pmThis sounds like the most elegant and simplest solution. What do you mean when you say 'The limit switch would be capacitively coupled to the 4060 RST pin', what does 'capacitively coupled' mean?

author: Zero999
author_rank: Super Contributor
timestamp: May 30, 2022, 03:16:34 pm
content: Quote from: vranghel on May 30, 2022, 03:13:01 pmConnect it via a small capacitor, so it just gives a short pulse, when the switch is made. The reset pin will still need a pull-down resistor and so will the switch.

author: Ian.M
author_rank: Super Contributor
timestamp: May 30, 2022, 04:03:09 pm
content: Its got to be capable of driving out of the limit, and shouldn't consume any power at the limit position. Therefore use a NC limit switch to ground with a pullup resistor. When it reaches either half-turn position, a peg on the mechanism operates the switch, so its output goes high and it no longer draws current. Use a pulldown resistor on RST at least 20x the switch pullup value + a Schotty clamping diode, anode to Gnd to stop RST going negative when the switch recloses. It will probably also need a small capacitor across the switch to prevent contact bounce when the switch recloses resetting the timer and stopping the motor for another 15 minutes, and 47 ohms directly in series with the switch to limit the capacitor transient discharge current to under 100mA!

author: Ian.M
author_rank: Super Contributor
timestamp: May 30, 2022, 05:30:30 pm
content: Another approach that may be easier to implement is to use a SPST limit switch to connect either a delayed Qn, or a pulldown to RST. The delay (which could be as simple as series R, C to ground) provides time for the motor to drive out of the limit position before the limit reset circuit is reactivated, so contact bounce on opening doesn't re-reset it.

author: BeBuLamar
author_rank: Super Contributor
timestamp: May 30, 2022, 08:12:19 pm
content: Well if I were to do it I would use the programmable controller which I have available to me. But I do understand such an approach is quite expensive if you have to buy the components. I am thinking of using a thru beam photoelectric sensor which looks thru the hour glass. The sand would block the sensor and the motor doesn't run. When the it's empty the motor will rung and turn the hour glass around until the full part block the sensor again then the motor stop. That way I use the hour glass itself as the timing device.

author: rstofer
author_rank: Super Contributor
timestamp: May 30, 2022, 08:58:51 pm
content: I like the stepper motor approach. There is no need for limit switches, just count steps. Whether the forward-reverse approach or forward-forward wouldn't matter.Since the stepper approach, with no limit switch, requires counting, a uC is just about required.Have we settled on a torque requirement?https://www.pololu.com/category/120/stepper-motor-drivers

author: Ian.M
author_rank: Super Contributor
timestamp: May 30, 2022, 10:14:46 pm
content: I've put together a quick LTspice sim of my reply #27 suggestion, using a behavioral model of the 4060's RST and Qn pin timings, showing its immune to vicious switch bounce.Its got a few extra parts - a BAT54S dual series Schottky diode, a 10K resistor and a 1nF capacitor for RST input ESD protection, and also to terminate the RST pulse cleanly when Qn goes low. I've also shown how junkbox BJTs could be used to drive the O.P's motor, though it would be much simpler to drive a low Vgs threshold MOSFET direct from the 4060, with only a 1K series gate resistor to limit the transient 4060 output current.

author: vranghel
author_rank: Contributor
timestamp: May 31, 2022, 07:21:37 am
content: Quote from: Ian.M on May 30, 2022, 10:14:46 pmWoow, this is great Ian! I opened the sim but honestly the details are above my understanding.I understand the schematic in general, and I think i could build it since I have most of the parts:-BAT54S dual series Schottky diode: in only have zenner diodes, 1N4001, 1N4148, 1N914 and Germanium diodes-found an appropriate NC/NO switch (can operate as both) (https://kagi.com/proxy/12-Pieces-Red-Button-Metal-Long-Lever-Arm-Micro-Limit-Switch-Home-LOT.jpg?c=D7u0yXs99oGy9xkm-57YOw_yiy23Lp8lOir26GxuiRppPXbbcSMFyMxCHS_RT3nDYW4553c2Q7MyVHuV0-2bAIakCIPW-Xc8XLcQblY92hD_f0dmwI47OvHF0ZzW3w5g1iTl2cd8gLXtWr0XNNA6TDuW1M5MtaWnH20xutvHjm2P3A4bUwWCJnEyGMExgyD7Can I use only half of the SPDT switch from the schematic, and use a NC switch connected to Gnd?Would the circuit be simplified if i'd replace the transistors with 1 MOSFET? I have IRFZ44N (N-channel, Vgs threshold 2-4 (min-max)) and IRF540N (N-channel, Vgs threshold 2-4 (min-max))

author: Ian.M
author_rank: Super Contributor
timestamp: May 31, 2022, 08:52:16 am
content: As you don't have Schottky diodes for the input clamping, use 2x 1N4148, but add an extra 10K resistor between the junction of the two diodes and the RST input pin.Although the switch was drawn in the sim as two individual NO and NC halves (because LTspice doesn't come with a SPDT switch component), in real life it *MUST* be asinglebreak-before-make SPDT switch (or one pole of a DPDT switch), so there is absolutely no possibility of both sides being on at the same time, even momentarily. If it did it would short the charged capacitor, damaging the switch and loosing the RST pulse. You've found a suitable SPDT switch, so just use it, COM towards the RST pin.If you are unlucky, 4V is too high a threshold voltage, as there isn't much margin between that and the lower limit of your nom. 5V supply voltage, so the MOSFET channel may not enhance enough to pass the motor current. However, odds are its quite a bit lower, so its worth trying the IRFZ44N at 4.5V, source to ground, gate strapped to +4.5V, your motor between its drain and +4.5V, and check the voltage drop drain to source across the MOSFET. It should be under 0.1V with the motor running normally, which means you can use that MOSFET. If its higher, switch off immediately, before the MOSFET overheats.

author: Zero999
author_rank: Super Contributor
timestamp: May 31, 2022, 11:18:23 am
content: Quote from: rstofer on May 30, 2022, 08:58:51 pmHow do you know the motor's position when it's powered on? There are no limits so it's not as though it can be driven to a stop.I agree about using a microcontroller. I'd use the old PIC12F509, purely because I have a load in stock.Quote from: Ian.M on May 30, 2022, 10:14:46 pmVery good, but the wait time is off by a factor of 60. Run the oscillator at 9.1Hz and use the Q14 output to for a half period of 15 minutes.If there's ambiguity, add a line to the NC switch to make it's clear it's normally closed.

author: vranghel
author_rank: Contributor
timestamp: May 31, 2022, 11:22:42 am
content: Quote from: Ian.M on May 31, 2022, 08:52:16 amIan, I have followed your advice and modified the circuit. I created a model for the CD4060 with all the pins as they are laid out, but there are a few pins which I dont know where to connect.See attached my very unprofessional LTSpice schematic. Please correct it and modify it accordingly to make a complete circuit. Thanks!

author: Ian.M
author_rank: Super Contributor
timestamp: May 31, 2022, 11:40:38 am
content: @Zero999,Agreed on using a MCU - if you've got the toolchain ready to go a PIC12F509 makes as much sense as any. The XC8 compiler does a reasonable job of hiding the horrors of the Baseline PIC architecture, so you don't even have to suffer wrangling MPASM assembly code like we had to back in the 90's!Yes, the wait time was off deliberately. If I'd done the sim with the real ratio between the wait time and the other timings, (and the real 4060 oscillator frequency and division ratio) the run-time would have gone through the roof due to LTspice calculating at least two timesteps per clock edge, and as I disabled waveform compression to permit zooming in on the switch bounce transients and the 'runt' RST pulse, the already ridiculous >21 MB .raw (results) file size would have bloated even further, possibly to the point of crashing the waveform viewer.I *SHOULD* have drawn a SPDT switch symbol and created hierarchical schematics for the switch + associated control sources and the behavioral 4060 'lite', but that's starting to turn into a full project rather than a quick 'freebie' proof of concept. The switch bounce part of the simulation is something I've previously posted here and it literally took me under five minutes to grab it, delete the bits I didn't want and add a NC switch model.

author: Ian.M
author_rank: Super Contributor
timestamp: May 31, 2022, 11:54:24 am
content: @vranghel,You *MUST* use aSPSTSPDTchangeover switch to trigger the RST circuit at the desired stopping point(s). A simple switch to Gnd as you have shown will *NOT* work at all - the motor wonts stop till the timer output pin goes low again after another 15 minutes!Take the output from Q14 (pin 3) not pin 4. You'll also need two resistors and a capacitor, values chosen according to the formulae in the '4060 datasheet for aa frequency of 9.1Hz, connected to pins /CLK, Rext and Cext as per the RC oscillator circuit in the datasheet. That should give you the required 15 minute delay.I would also recommend a 100nF decoupling capacitor across '4060 acroos pins 16 (Vdd) and 8 (Gnd), and a 1K resistor in series with the MOSFET gate.

author: vranghel
author_rank: Contributor
timestamp: May 31, 2022, 12:55:25 pm
content: Quote from: Ian.M on May 31, 2022, 11:54:24 am@IanI have made the changes to the circuit you suggested.I have used the resistors and capacitor values from herehttps://www.gadgetronicx.com/how-to-build-24-hours-timer-circuit-cd4060/and a variable resistor, and with output Q14, i should be able to adjust the timer from 8 min to 20 min.However, I do not understand what do you mean about the switch: 'SPST changeover switch 'Are you saying that how the switch is wired in is incorrect, or that the type of switch i'm planning to use (https://kagi.com/proxy/12-Pieces-Red-Button-Metal-Long-Lever-Arm-Micro-Limit-Switch-Home-LOT.jpg?c=D7u0yXs99oGy9xkm-57YOw_yiy23Lp8lOir26GxuiRppPXbbcSMFyMxCHS_RT3nDYW4553c2Q7MyVHuV0-2bAIakCIPW-Xc8XLcQblY92hD_f0dmwI47OvHF0ZzW3w5g1iTl2cd8gLXtWr0XNNA6TDuW1M5MtaWnH20xutvHjm2P3A4bUwWCJnEyGMExgyD7) is the wrong one, or both??I'm sorry for all these questions, i'm a beginner.I have attached the adjusted circuit.

author: Psi
author_rank: Super Contributor
timestamp: May 31, 2022, 01:13:23 pm
content: +1 for relays to control the motor.Probably one that flip polarity and one that is just simple on/off. (It's safer than the alternative way to do it, which could end up shorting the input by mistake)Setup a 555 timer configured to toggle its output state every 15min.If 555 output is low the direction relay is one way, if high it's the other way.Then you just need to handle the limit switch cut-offs.Use a 3rd relay to combine both limit switches into one pseudo switch that changes depending on 555 output / direction.Now use that pseudo switch to control the motor on/off control relay.When the 555 output changes it will change which limit switch is controlling the motor on/off relay and flip the motor direction at the same time.The newly selected limit switch wont be tripped so it will start moving in that direction until it reaches it. etc..In my head that sound like it should work.3x relays and 1x 555 timer.

author: Zero999
author_rank: Super Contributor
timestamp: May 31, 2022, 01:31:09 pm
content: Quote from: vranghel on May 31, 2022, 12:55:25 pmJust use a SPST switch: normally closed to 0V and normally open to +V.I'd just use 620k for both timing resistors and 100nF for the capacitor. The capacitor needs to be non-polarised and 10µF is quite a big value for such a capacitor.Here's a more detailed explanation of how the type of oscillator used in the 4060 works and how to calculate the component values. When the two resistor values are the same F = 0.559/(RC). If you really need to add a trimpot, reduce the value of the resistor going to pin 10 of the 4060 to 390k and put your 470k trimmer in series.https://www.onsemi.com/pub/Collateral/AND9983-D.PDFPresumably this doesn't need to be accurate. If you need precision timing, the only sane way is with a microcontroller using a crystal for the clock. An RC oscillator won't be stable enough, even with a trimmer.

author: Ian.M
author_rank: Super Contributor
timestamp: May 31, 2022, 01:35:03 pm
content: Sorry for the confusion: 'SPST changeover switch' was a typo, which should have been 'SPDT changeover switch'.To use your preferred switch, connect its NC pin to Gnd, NO pin to junction of R1+C1 in your "hourglass circuit.asc", and its C (com) pin to the left end of R2. Arrange two pegs on the mechanism to trip the switch, one for each hourglass orientation, that approach the switch from the hinge end of the lever actuator so they slide over it without catching on it.R1+C1 provide a delay to allow the motor enough time to drive the peg off the switch actuator when the motor starts, before re-enabling the limit switch to RST circuit. Unless the speed is high enough that it coasts off the actuator, past the switch when it stops, Zero999's suggestion of simply switching Vcc to RST will *NOT* work. I looked at capacitively coupling it to allow the motor to restart, but it was difficult to avoid any switch bounce on opening resetting the 4060, and stopping the motor for an additional 15 minutes just after the switch open.@PSI: Build your 50% duty cycle 15 minute 555 timer, then report back to us what type of capacitor you used, and how much off the ideal design RC values you had to go to compensate for leakage current!Then see how temperature sensitive it is . . .

author: Zero999
author_rank: Super Contributor
timestamp: May 31, 2022, 01:41:00 pm
content: Quote from: Ian.M on May 31, 2022, 01:35:03 pmAnd silly me just copied it, without thinking.QuoteIt's possible, but won't be anywhere near accurate. Use it in Schmitt trigger mode, with pin 5 tweaked to give several RC time constants.

author: themadhippy
author_rank: Super Contributor
timestamp: May 31, 2022, 02:40:50 pm
content: QuoteThe 4060 has the option to use a crystal if you want accuracy.

author: Zero999
author_rank: Super Contributor
timestamp: May 31, 2022, 03:02:40 pm
content: Quote from: themadhippy on May 31, 2022, 02:40:50 pmBut there's a limit to the range of crystal frequencies available and you'll need a butt load of ICs to get the desired delay. The 4521 is a better choice, having 24 stages, which would give a period of 512 seconds, with a 32768Hz crystal, but another IC would be required to get 15 minutes. A microcontroller is a more sensible approach.

author: Ian.M
author_rank: Super Contributor
timestamp: May 31, 2022, 03:24:06 pm
content: Yes, we can't get there in one 4000 series chip as the 214max division ratio isn't enough to get a 32768 HZ crystal down to the required 30 minute period (15 minutes on). The best it can do is 2 Hz on Q13. Even if you cascade it with another 4060 or 4020 you'll need to add logic to the first one to reset it early to 'bump' the 8 Hz Q11 output clocking the second counter up to the required 9.1 Hz. Unfortunately Q10 isn't available so the required terminal count of binary 1110 0001 0000 cant easily be implemented. If it was, it could be done by diode logic. The easiest workaround is to go to a 100Hz crystal, take the output from Q13 with a terminal count of 10 1010 1110 1000, for a clock that is 212 pm fast. Ideally it would be 10 1010 1110 1010, but again Q1 isn't available so we cant get it down to only 30 ppm fast. Seven diodes and a pullup resistor later, the first 4060 will be outputting very close to the correct frequency.Of course a MCU is the sane choice as it facilitates the use of arbitrary integer division counts, allowing the final accuracy to be as good as the crystal.

author: RoGeorge
author_rank: Super Contributor
timestamp: May 31, 2022, 03:48:33 pm
content: Alternatively, go to an auto scrapyard and harvest a few windshield motors.Add limiter switches in series with the motor, to turn it off after each half turn, then add a 15 minutes timer to override the limiters for a short while, just enough to start a new spin. Give it a steampunk look so it won't need a case to hide its internals.

author: themadhippy
author_rank: Super Contributor
timestamp: May 31, 2022, 04:23:18 pm
content: QuoteHow times have changed,don't seem that long ago that for a reasonable amount of cash,you could get a crystal "grown" to whatever exotic frequency you required

author: Zero999
author_rank: Super Contributor
timestamp: June 01, 2022, 07:41:42 am
content: Quote from: themadhippy on May 31, 2022, 04:23:18 pmI didn't know that. What was the lowest frequency you could get? For a period of 30 minutes and a 24 stage counter. F = 224/(60*30) ≅ 9320.676Hz, but I've not seen a crystal below 10kHz before and 20kHz is currently the lowest frequency I could find.

author: Psi
author_rank: Super Contributor
timestamp: June 01, 2022, 07:47:19 am
content: Quote from: Zero999 on May 31, 2022, 01:41:00 pmTrue, but does it really need to be that accurate, given the application?I guess only the OP can decide.

author: vranghel
author_rank: Contributor
timestamp: June 01, 2022, 09:06:12 am
content: Quote from: Zero999 on May 31, 2022, 01:31:09 pm@Zero999For the RC oscillator, using same timing resistors, 620k and 100 nF for the cap, i'd get a delay of 17 minutes (from pin 15 (Q10))It doesnt need to be accurate at all. I have added the resistor and trimmer values you suggested in the schematic.Quote from: Ian.M on May 31, 2022, 01:35:03 pm@IanDisregarding what the actual symbol looks like in the schematic, is the switch wired in correctly, if I will use the previously shown switch in NC mode? Since i will only be using 2 pins of the switch to achieve the NC operation, does it matter which way are those 2 poles placed in the circuit? I'd say no.Does the overall circuit look ok?Thanks!Attached the circuit LTSpice and a pic of the circuit

author: Ian.M
author_rank: Super Contributor
timestamp: June 01, 2022, 09:19:12 am
content: No. that wont work. As I explained back in reply #36, it *NEEDS* the changeover switching action, so three wires to the switch, wired as I specified in #40.

author: vranghel
author_rank: Contributor
timestamp: June 01, 2022, 09:27:39 am
content: Quote from: Ian.M on May 31, 2022, 03:24:06 pmI just saw your post Ian, and while most of it flies right above my head, the conclusion seems to be that the 4060 is not suitable for such a long time period.In the calculation from my previous post, i incorrectly used pin Q10, even tho it's not available.What is still unclear to me, is how the circuit outputs? Does it work by being 15 minutes on, 15 minutes off? In that case, for the calculation, do i need to consider 15 minutes, or 30 minutes?I revised my calculation using the values provided by Zero999 and realized that i did a mistake:If i use Q11, using the C and R values suggested by Zero999, i MISTAKENLY thought I'd get a delay of 34 minutes (R= 620000, C= 1E-07; The formula i used is Freq = 0.559/(RC)= 9.02 Hz; Q11 results in 2048 clock pulses, therefore the i did 2^11TIMES9.02 Hz to get the seconds. BUT i should have done 2^11DIVIDED BY9.02 Hz , which results in 25 SECONDS.However, the R and C values suggested in this article:https://www.build-electronic-circuits.com/4000-series-integrated-circuits/ic-4060/shows that it is possible to get both 17 and 34 minutes using Q11 and Q 12 respectively

author: vranghel
author_rank: Contributor
timestamp: June 01, 2022, 09:35:21 am
content: Quote from: Ian.M on June 01, 2022, 09:19:12 amOk, i think i understood this timeI attached a crudely drawn schematic to show what i believe you meant how to connect the switch poles.

author: brucehoult
author_rank: Super Contributor
timestamp: June 01, 2022, 10:22:56 am
content: Quote from: rstofer on May 30, 2022, 08:58:51 pmI'm late to this thread.If it was my project I would absolutely use the cheapest microcontroller I could find (or just one of my stock of $1 ATTiny85's which are vast overkill for this, program size-wise) and a cheap stepper motor (which I also have a stock of).Here is 5 stepper motors and 5 drivers for $14.https://www.amazon.com/ELEGOO-28BYJ-48-ULN2003-Stepper-Arduino/dp/B01CP18J4AThis is the kind of stepper that is universally used for things such as the louvers on air conditioners. They don't bother with limit switches -- at power-on they just drive the thing all the way in one direction and I think let the drive mechanism slip at the mechanical limit. They have a built in geartrain and rotate slowly and with plenty of torque.Here's a video from when I first played with one in 2013:youtube.com/watch?v=-c3MxdvORSAThey have 5 wires. You're supposed to connect the common to ground and pulse each of the other 4 wires in turn, with the direction of rotation determined by which order you pulse them in. But here I was leaving the common wire unconnected and using an H-bridge motor driver (I think) and it works fine. This was the maximum rotation speed, You can go much more slowly.

author: vranghel
author_rank: Contributor
timestamp: June 01, 2022, 10:49:25 am
content: Quote from: brucehoult on June 01, 2022, 10:22:56 amHi Bruce,While this approach maybe would have been easier for some, I dont have any microcontroller programming experience, don't have stepper motors handy and the circuit needs to run on battery.I do, however, have (some) experience with analog circuits, and have a number of geared motors, and am overall more comfortable with them

author: Ian.M
author_rank: Super Contributor
timestamp: June 01, 2022, 11:00:46 am
content: Quote from: vranghel on June 01, 2022, 09:35:21 amStill wrong! As I*EXPLAINED*back in reply #40:Quote from: Ian.M on May 31, 2022, 01:35:03 pmI'll say that again obnoxiously large:NO pin to junction of R1+C1

author: vranghel
author_rank: Contributor
timestamp: June 01, 2022, 11:08:33 am
content: @IanIREALLYhope i did it right this timeFor some reason i thought you were referring to the R and C that set the oscillations. My bad

author: Ian.M
author_rank: Super Contributor
timestamp: June 01, 2022, 12:55:56 pm
content: Much better. Now breadboard it so you understand it properly before you build the permanent version. As drawn you should get about 1 minute delay, great for testing. Take the output (and feed R1 etc.) from pin 3 for the maximum delay of 15 minutes for the permanent build.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: June 01, 2022, 01:06:09 pm
content: Quote from: vranghel on June 01, 2022, 10:49:25 amI'm not Bruce, and I would definitely not use the cheapest microcontroller I could find (I hate those 8 pin jobbies, especially lots of silly changes that make ATmega's and ATtinies incompatible. It's a real nuisance).I would use a microcontroller though.The flexibility of these things, and that you can make them do almost anything by just pushing some buttons on your keyboard make them quite attractive for a lot of quick projects. Power consumption of a microcontroller can also be extremely low. Power consumption can be less then a micro amp when sleeping (with some timer running to occasionally wakeup)But you have to be interested in these things. A project like this is a good start for learning to use microcontrollers, and if you want to do more with electronics in the future, microcontrollers are hard to avoid. With a microcontroller you can also make other things easier. for example, instead of making something with end switches, you can just glue an accelerometer to your device and then measure it's position.Combining a microcontroller with a H-Bridge motor driver IC is also easy. It's just two wires. All these IC's are designed to work with mircocontrollers.For suitable H-bride drivers. Forget about the old L298 and such, but use something modern in a SOIC package or similar. There are lots of variants and you can buy easy to manage breakout boards for them.I would not use a stepper motor tough. A geared DC motor is a better choice for a low power application.

author: Zero999
author_rank: Super Contributor
timestamp: June 01, 2022, 01:12:40 pm
content: Quote from: brucehoult on June 01, 2022, 10:22:56 amThere is no mechanical limit in this case, so a switch or optical sensor is necessary.Quote from: vranghel on June 01, 2022, 10:49:25 amI strongly recommend learning to program a microcontroller. It's not that difficult and it can greatly simply projects. Some see it as lazy, but I don't understand how learning something new can ever be lazy.Quote from: Doctorandus_P on June 01, 2022, 01:06:09 pmWhich one would you use then? I consider anything with more than 8 pins to be overkill in this application. Fair enough, you might only stock larger devices, but they do take up more space.QuoteI agree.

author: vranghel
author_rank: Contributor
timestamp: June 01, 2022, 01:19:25 pm
content: Quote from: Ian.M on June 01, 2022, 12:55:56 pmPhew....I am waiting for the 4060s to be delivered and will breadboard it, test it and tweak the circuit so it spins at the right time interval.Will post updates and pics of the results.Thanks everyone for your advice, help and patience!

author: Zero999
author_rank: Super Contributor
timestamp: June 01, 2022, 01:43:05 pm
content: Quote from: vranghel on June 01, 2022, 09:06:12 amThat doesn't sound right to me. 620k and 100nF should give a frequency of 9Hz. Pin Q10 will go high after 29= 512 counts, which would 512/9 = 57 seconds. The output needs to be taken from pin 3, which will go high after 213counts, giving a delay of 910 seconds, which is just over 15 minutes.

author: vranghel
author_rank: Contributor
timestamp: June 01, 2022, 01:50:39 pm
content: Quote from: Zero999 on June 01, 2022, 01:43:05 pmYou're probably right Zero999, and my calculations were most likely wrong. I'll test around the values and see what is the real life delay

author: Ian.M
author_rank: Super Contributor
timestamp: June 01, 2022, 02:09:40 pm
content: Yep. Use pin 15 for ~ 1 minute delay, ideal for bench testing. 15 minutes delay for the actual application, as you noted, and I also mentioned back in reply #57, requires the highest Q output - pin 3.For those still suggesting a MCU, well then this three page thread would be at least a twelve page one!First you'd have the obligatory three page MCU flamewar with major contributions from the Microchip PIC and Atmel AVR fanbois (though the latter are much deflated since the Microchip takeover of Atmel), while the STM aficionados take pot-shots from the sidelines. Fortunately the one and only rabid PSOC fanboi hasn't been active here for over three years, so it wont turn into a lynch-mob unless an 8051 enthusiast joins in!Then the schematic should only take a page or two, leaving three to four pages for which toolchain to use and how to get its software components installed in a nonbroken state, then four pages to get the O.P's code up to the point where it can successfully implement a simple action loop, busy-waiting on the switch, with a hard coded delay between turning the motor off and turning it back on.

author: brucehoult
author_rank: Super Contributor
timestamp: June 01, 2022, 03:41:33 pm
content: Quote from: Ian.M on June 01, 2022, 02:09:40 pmHow can you forget RISC-V? :pQuoteNot really.ATTiny85 (or 25 etc, but I have a stock of 8 pin DIP 85s) needs zero external components. Just connect power and it runs at 1 MHz. The Arduino IDE perfectly covers up any differences between the Tiny and the Mega. You can program it using an Uno (etc) and a special programmer program that comes with the IDE.And of course "Blinky" is the standard helloworld for any microcontroller, including Arduino.File / Examples / 0.1 Basics / BlinkAdd a 2nd output pin and digitalWrite(). Add an input pin for some kind of limit sensor. And a handful more lines of logic to deal with it.Seems like very easy and just about an ideal starter project.

author: Ian.M
author_rank: Super Contributor
timestamp: June 01, 2022, 06:13:02 pm
content: You did spot the not quite BBCODE tags wrapping my rant?Adding ATtiny 'board' support to the Arduino IDE is a step too far for some of our more coding-challenged members! If the O.P. turns out to be one of those poor souls with a negative aptitude for procedural programming, I suspect we'd still be in for four pages of iterative code refinement even starting with 01.Basics:Blink on a 'vanilla' Uno or Nano.

author: vranghel
author_rank: Contributor
timestamp: June 03, 2022, 11:22:16 am
content: SUCCESS!!I built the circuit on a breadboard using 2x680K resistors for the timing.With the button UNPRESSED, the motor starts spinning after 62 seconds, and stops when the button is momentarily pressed. To reset the timer, the button needs to be (left) unpressed for the timer to re-start counting down.The way I plan to build the mechanism is to have the hourglass spinning, then pressing the switch, and at the moment the motor needs to stop (while the switch is kept pressed), and the timer needs to run; After 15 minutes, the motor needs to spin UNTIL the switch is pressed again(and kept pressed), at which time the motor will stop and the timer runs again.I think i need to tweak the wiring of the switch, but I dont think I know how.

author: vranghel
author_rank: Contributor
timestamp: June 03, 2022, 11:44:16 am
content: I modified the circuit so that the switch needs to be PRESSET for the timer to start.As soon as the motor starts, the hourglass is spinning and slides off the switch, which makes the motor stop.For the timer to be running, the button needs to be pressed, but this condition cannot be met, therefore, it is stuck.Is there a way to wire the circuit so that while the button is pressed the circuit counts down, then the motor is running which causes the switch to be depressed, BUT the motor keeps running UNTIL it the switch is pressed, at which time the motor stops, and the timer counts down.If that's not possible or feasible, then I need to figure out a mechanical way to build it so that the hourglass just momentarily TRIPS the switch.

author: Ian.M
author_rank: Super Contributor
timestamp: June 03, 2022, 11:54:26 am
content: Explain! Post your modified circuit, and a sketch of how the motor is going to press the switch.

author: vranghel
author_rank: Contributor
timestamp: June 03, 2022, 12:19:01 pm
content: Attached the modified circuit:How it currently works with the attached schematic: While the button is PRESSED, the timer runs down. After the countdown, the motor runs, and stops when the button is DEPRESSEDThe way I envision it to work: The hourglass is pressing against the arm lever of the switch. After 15 minutes, the motor spins, the hourglass turns 180 degrees and presses the switch again. At that moment, the motor should stop, and the countdown needs to begin.Now, this is problematic from a mechanical build standpoint: With the circuit as displayed, the motor starts( with the switch pressed) but once the hourglass slides off the switch, the motor stops; Therefore, the mechanism is stuck, with no way to restart (the circuit runs ONLY when the button is PRESSED)As a side-effect, if the switch is left unpressed, after the countdown the motor 'jerks' for a split second, then stops.

author: Ian.M
author_rank: Super Contributor
timestamp: June 03, 2022, 01:20:45 pm
content: Redrawn for clarity:Yes, wiring the switch like that will do that.If you rewire it back to my original switch connections:the motor will run with the switch lever up and stop (reset and start timing) when it is pressed, which is usually mechanically much easier to implement.If that's not how you want it to work, describe the desired sequence of operations in terms of what the hourglass is doing, when the motor should start and stop, and what's happening to operate the switch, noting any significant time delays between actions and their results.N.B. Its just a schematic, not a sim! Attached for your future edits.

author: ledtester
author_rank: Super Contributor
timestamp: June 03, 2022, 01:50:56 pm
content: What about this approach...Use a 15-minute monostable. The monostable is triggered by the switch going from open to closed. The motor is running if and only if the monostable is off.If we assume the motor is running the sequence of events would be...1. the motor turns the hour glass2. the hour glass hits the switch causing an open to closed event3. the open to closed event triggers the monostable to start running4. the monostable running turns off the motor5. when the monostable expires the motor starts running again6. the hour glass will run past the switch causing a closed to open event but this should not affect anything7. after rotating 180 degrees the hour glass hits the switch again causing an open to closed event and the sequence repeatsIt's key to debounce the switch so you get clean open to closed and closed to open events.

author: Ian.M
author_rank: Super Contributor
timestamp: June 03, 2022, 02:05:42 pm
content: There is a simple way to make a RC oscillator CD4060 work as a (retriggerable) monostable, with active low output. Connect a diode between Qn and CLK, cathode to CLK. When the output goers high at the end of the timing period, it stops the RC oscillator 'freezing' it until Reset is pulsed to trigger it again. If you want a non-retriggerable monostable you need to add an AND gate, to drive Reset from combined Trigger and Qn, so Trigger is held off till the timing period ends. This can be done with diode logic with a pullup on Reset, and two diodes, one cathode to the trigger signal (active high) and the other cathode to Qn, though using two gates of a CD4011 quad NAND may be preferable as one of the remaining gates can be used to invert the Qn output so its active high.Note there is *NO* way to 'reset' the '4060 monostable on powerup - it *MUST* run till Qn goes high to enter its stable state, waiting for trigger.

author: vranghel
author_rank: Contributor
timestamp: June 03, 2022, 02:08:36 pm
content: @ Ian:You explained the operation of the original circuit as follows: 'the motor will run with the switch lever up and stop (reset and start timing) when it is pressed,'That is correct but describes only half of the operation, with the continuation as follows: The motor then stops when the lever is pressed (the lever is kept pressed by the hourglass, when it reaches the desired position)Once the sand has flowed, the circuit needs to re-start while the lever is pressed. However, according to but my observation, the motor does not restart (while lever is kept pressed) and only slighty jerks.It needs to start timing with the lever pressed, and once starts spinning (and the lever is DEpressed) it needs to continue spinning until the lever is pressed again (after rotating 180degrees). But currently it does not spin (after the countdown) with the lever pressed. Hope my explanations are clear now.I dont understand exactly what does R1and C1 do, what does it delay.

author: Ian.M
author_rank: Super Contributor
timestamp: June 03, 2022, 02:13:50 pm
content: R1, C1 provides the delay that lets the motor jerk. It needs to be long enough to get the peg off the switch lever. Try increasing C1 to 10uF.

author: vranghel
author_rank: Contributor
timestamp: June 03, 2022, 02:17:39 pm
content: And once that 'jerk' has gotten it off the switch lever will it continue to spin? I'll increase the cap and try to manually test it.

author: Ian.M
author_rank: Super Contributor
timestamp: June 03, 2022, 02:19:04 pm
content: Yes, as once the switch releases, its NC contact holds Reset low (no reset) so the motor stays running (for up to 15 minutes), while C1 continues to charge so the switch can reset the '4060, stopping the motor, when its next hit.

author: vranghel
author_rank: Contributor
timestamp: June 03, 2022, 02:27:08 pm
content: Wow! This is great!Works as intended now: the 10uF gives it a strong enough 'jerk' so it slides off the lever, then continues to spin 180degrees until it stops and rests on the lever.Thank you very much for all your help Ian!! Your knowledge as help was invaluable.I will post pics with the final result.

author: vranghel
author_rank: Contributor
timestamp: June 20, 2022, 09:40:35 am
content: FINISHED!!I built the circuit and after some mechanical and electrical tweaking it works exactly how I envisioned it.Video of the spinning hourglass:https://thumbs.gfycat.com/ZestyBlushingCoral-mobile.mp4I've added a few additional features:test mode switch: to switch between the 1 minute delay pin and the 15 minute delay pin;power switchfemale micro USB: to trickle charge the 3 NiMh batteries (via a resistor and diode)solar panel: used as a base and also charges the batteries via a Ge diodeFor some reason, I built it with only 3 NiMh batteries in series, which don't give enough power if they are a bit discharged. Will add the 4th to give it more oomph and longer running time.I am very happy with the result and it works very well and looks quite nice too.Depending on how it works long term, I might replace the NiMh batteries with a used cell phone battery since it has a much larger capacity and it's easily charged with a small and cheap TP4056 based battery charger boardThanks again to Ian.M and others for the help!