How to build a relay timer

NO, I mean reed switch. You somehow have to move the magnet away and it is attached to the belt, but the belt and motor have stopped.
You need a timer to start after the motor stops and when it times out to then start the motor again to move the magnet away, NOW you can re-enable the code loop to check for the reed switch being closed. You can do that with another timer but of fairly short duration.

Only until the motor starts again, which is after the time period.

That is my understanding of the clear(er) description @mikmaster63 offers in post #16.

Magnet comes by, motor stops for awhile. Motor starts, dragging the magnet away from the red switch and the logic resets.

a7

You keep forgetting, the reed relay is still closed until the magnet is moved. That means you can NOT resume checking for the magnet as you would immediately detect it. You need another very small delay between when the motor starts and you start checking. In any case I am tired of this so am muting. Good luck.

No, it means YOU can't. We can, have done and are doing.

a7

you are proposing the the relay is driven solely by the switch. you seem to think there's no logic between the two. you seem to be suggesting there's nothing but wire connecting the switch to the relay and something else is needed to disable the circuit

you seem to ignore the fact that there's a processor involved, or are grossly under-estimating the capabilty of anArduino AVR processos

the processor turns on the relay only when it detects that the reed switch changes state AND becomes active. The processor won't turn the relay back on until after the processor times out because the switch has turned off

I would have thought a cap in the base leg of the NPN in the active high switch I mentioned above would give the required action......no????

what does the transistor do, pulse the relay on or hold it on for the required time? does releasing the switch cause a pulse that retriggers the circuit?

i'd be curious to see a completely hardware implementation that satisfies the requirements, possibly using a 555 timer. (is it simply a one-shot)?

When the magnet is present, does the reed switch close or open? How is the reed switch wired to the Arduino?
When the motor starts, how long before the switch changes state? How long does it take for the magnet to come back around and stop the motor again?

Since you're not the OP I will address this to milkman.

You only stop when the pin changes at certain way. Not when the switch is LOW or HIGH or switches back but only when the magnet wasn't there and then it is. Reed switches are mechanical contacts so there will be some bounce to get past so really you seek change plus stable state which can be as short as 3 or 4 ms without a bounce. Consider learning this a forum rite of passage and know there are many ways to code for it and even libraries dedicated to buttons and debounce.

You can do this as a matter of change over time instead of coding for only Now. The big lesson is watching what is relative to what was.

We sense events over time to cause events on time.

My own method watches a pin all the time and turns the last 8 reads (at regular intervals) into a constantly updated byte. If the byte is binary 10000000 then that is was HIGH to LOW for 7 reads in a row == 127. A function looks for == 127 and change + stable period is detected. It can be shortened, the idea is that the pin hardware watcher is independent of the function that controls what is done so that part doesn't include hardware details, just looks for if == a number.

Prepare to read why that's not necessary and note the alternative structuring.

Hello mikmaster63

My imagination is limited.
Send some photos of the mechanical setup to see details.

Pseudo code:

If (not on limit switch)
run motor;
else
Stop motor, start delay timer;
if (delay expired)
send start pulse just long enough to drive off limit switch;
repeat;

you do understand the difference between the press of a button, change in state, and being pressed?

[Nick Gammon's commonsense tutorial on detecting switch changes.](Gammon Forum : Electronics : Microprocessors : Switches tutorial

The interesting things happen over time.
We track When What Happens to control what we want.

In Arduino the clock us always running.
We can save When in unsigned integer variables.

Always to the limit of the size variable:
Elapsed Time = End Time - Start Time

With unsigned long and millis() the longest interval is > 49 days.
With unsigned long and micros() it is > 70 minutes.

With unsigned int, > 65 seconds and > 65 ms.

If I knew if the OPs reed switch OPENED or CLOSED when the magnet was present AND if the output pin activated the motor when HIGH or LOW, I could dash out a simple sketch.
But, I don't so I can't.
BTW: I would use a Hall effect sensor that doesn't bounce.

1 Like

magentic device don't bounce like mechanical switches, but the system will know when the motor is running AND if the sensor wasn't active and became active

1 Like

This would likely suffice as a 555 input on pin 2.

555 trigger

doesn't there need to be a resistor on the pin 2 side of the capacitor? (is there a need for a series resistor)?

with a resistor pulling the other side of the capacitor high, there is no charge across the capacitor and pin 2 is HIGH. Pressing the switch pulls the pin 2 side of the capacitor LOW until it charges thru the resistor on pin 2 and triggering the 555 when it goes LOW

the 555 generates a pulse turning off the motor for the timeout period.

the motor restarts at the end of the timeout period which releases the switch, causes the capacitor to discharge thru the diode/resistor to Vcc on pin 2, which remains HIGH (the diode keeping it voltage near Vcc)

compare to below
waveforms-tim38

Reed switch closes when there is enough magnetic field strength present or it is faulty. Magnetic field strength falls off by the inverse cube of distance from the magnet in air, twice as far away is 1/8th as strong, the change with distance is fast.

The negative pulse needs to be short....in the Op's arrangement, the switch is still closed the entire time the belt is stopped.
That becomes the issue.

If the switch state == LOW does not stop the motor but instead the switch has to go from HIGH to LOW to stop the motor, then when the code starts the motor back up while the reed switch is LOW the code won't turn the motor off cause it takes HIGH then LOW to stop the motor. When the magnet moves away enough, the reed switch will open and the pin will go HIGH and be ready to go LOW later which the code will see and stop the motor.

Arduinos and reed switches article.

The article taught me something I didn't know. I didn't know how close the contacts are when it is open, about 1/10th the thickness of a human hair. It does not take much field to activate a reed switch and the movement is very short!