Switch a relay on for 3 seconds, after a delay.

Status
Not open for further replies.

cupoftea

Advanced Member level 6
Joined
Jun 13, 2021
Messages
3,059
Helped
62
Reputation
124
Reaction score
139
Trophy points
63
Activity points
15,964
Hi,
For this circuit, when the signal goes from 0V to 5V, there should first be a delay of 5 seconds. Then Relay_A must be switched ON for just 3 seconds.
Then when the 5V later goes to 0V, there should again be a 5 second delay, and then Relay_B should be switched on for 3 seconds only

Its achieved by the attached, though can you think of a lesser_component way?
(PDF schem and Ltspice sim attached)

No microcontroller is allowed
 

Attachments

  • Delayed switching of relays.pdf
    180.4 KB · Views: 256
  • Delayed switching of relays.zip
    3.8 KB · Views: 199
Last edited:

You might consider this (cut down on parts) -


I think you can cram this into an ATTINY -




Regards, Dana.
--- Updated ---

My apologies, missed the no micro allowed, ignore post.


Regards, Dana.
 
Last edited:
There are timed relay modules with delay either on activation or shutdown, or both; given the huge amount of discrete components you used in the simulation, I would consider a ready-made option as such.
 
Reactions: cupoftea

    cupoftea

    Points: 2
    Helpful Answer Positive Rating

    c_mitra

    Points: 2
    Helpful Answer Positive Rating
Hi,

I also thought about a small microcontroller.
What about a PLD with a low frequency RC clock?

May I ask why no microcontroller is allowed?

Klaus
 
The 4017 IC is handy for such tasks (1-10 selector / counter).

Apply clock with period = 3 seconds.

Skip outputs 1 & 2 = delay 6 seconds.

Send output 3 to turn on relay for 3 seconds (or turn on transistor which turns on relay).

Etc.

Some finagling of time intervals is necessary If you absolutely need 5 seconds and 3 seconds.
 
Last edited:
I would use an XOR gate with one input slightly delayed by an RC circuit, that would give you a single pulse when the input either went high or went low, in other words a change in input level. From there you just need two monostables. With care, it might be possible to use more XOR gates to provide the monostable function and therefore combine it all into one quad-XOR IC.

Brian.
 
Reactions: cupoftea

    cupoftea

    Points: 2
    Helpful Answer Positive Rating

    c_mitra

    Points: 2
    Helpful Answer Positive Rating
Does signal come from a mechanical switch or contact ? If so it would need
to be debounced.

Do you care about power up/down transients effect on circuits ? Eg. false relay
triggering ?

What is relay swicthing ? Power/Voltage/Current ?


Regards, Dana.
 
Thanks,
The 5V input goes high when car ignition is switched ON...low when OFF.
The relays, are changeover relays on each connection (go and return) to a motor. The relays are connected to pos of input 12v supply when not coil_powered.
Obviously which relay you switch on (contactor to neg of input supply) determines which way the motor spins.
When both relays are off, the motor terminals are thus both connected to pos (of input supply), so it wont spin.
 

So input signal has to be debounced.

This is what core design would look like (with a micro) -



Note I did not include a regulator, could be a 3 terminal regulator with capacitor or
a Zener + Resistor.

I used MOSFETs to switch motors, you could use relays or NPN bipolar. If you want to stay with
relays to switch motor loads you can just use small MOSFET or Bipolar.

The 200 ohm R's are to limit mosfet gate current flow thru ATTINY85 when switching,
the 2.2K to insure when ATTINY85 powers up it does not switch motors before code
takes over. The code also debounces the signal input for relay/mosfet operation.

Show wiring of motors to relays if possible.


Regards, Dana.
 
Last edited:
I think code something like this -



Here is code mBlock generates from the blocks user configures as shown above -

Code:
// generated by mBlock5 for <your product>
// codes make you happy

#include <Arduino.h>
#include <Wire.h>
#include <SoftwareSerial.h>

float CurrentState = 0;
float OldPinState = 0;
float relayApin = 0;
float relayBpin = 0;
float wchRelay = 0;
float inputPin = 0;
float wchedge = 0;
float dbnccntr = 0;
float pinstate = 0;

void debounce (){
  dbnccntr = 0;
  if((CurrentState == 1.000000)  &&  (OldPinState == 0.000000)){
      pinstate = 1;
      dbnctask_N(pinstate);
      CurrentState = 1;

  }
  if((CurrentState == 0.000000)  &&  (OldPinState == 1.000000)){
      pinstate = 0;
      dbnctask_N(pinstate);
      CurrentState = 0;

  }

}

void dbnctask_N (double pinstate){
  while(!(dbnccntr > 5))
  {
    _loop();
    _delay(0.02);
    dbnccntr += 1;
    if(!((digitalRead(inputPin) == pinstate))){
        dbnccntr = 0;

    }

  }

}
void PulseRelay_N (double wchRelay){
  _delay(5);
  digitalWrite(wchRelay,1);
  _delay(3);
  digitalWrite(wchRelay,0);

}

void _delay(float seconds) {
  long endTime = millis() + seconds * 1000;
  while(millis() < endTime) _loop();
}

void setup() {
  pinMode(relayApin,OUTPUT);
  pinMode(relayBpin,OUTPUT);
  pinMode(inputPin,INPUT);
  pinMode(wchRelay,OUTPUT);
  relayApin = 9;
  relayBpin = 10;
  inputPin = 5;
  digitalWrite(relayApin,0);
  digitalWrite(relayBpin,0);
  CurrentState = digitalRead(inputPin);
  OldPinState = CurrentState;
  while(1) {
      CurrentState = digitalRead(inputPin);
      if(!((CurrentState == OldPinState))){
          debounce();
          if(CurrentState == 1.000000){
              PulseRelay_N(relayApin);

          }else{
              PulseRelay_N(relayBpin);

          }
          OldPinState = CurrentState;

      }

      _loop();
  }

}

void _loop() {
}

void loop() {
  _loop();
}

Its not complete, needs timeout code when pin bounces in case there
is persistent noise on pin but you get the idea. I set it up if a pin shows a steady
state after pin change for 100 mS is legit.

But you can see if you follow the blocks fairly straightforward. Not I did not add comments
to blocks, that should be done for code readability.


Regards, Dana.
 
mBlock is really implementing binary variables as float? Surprizing.

It's no problem if you have a controller with 8k flash like ATtiny85, a cost optimal solution would however target to really tiny 50 cent processor.

there would not be sufficient quantities required to warrant a microcontroller.
???
 
Thanks,
I must admit, ill just be honest and say the circuit is for door mirrors.......fold them in when ignition off, and out when ignition back on again. (they keep getting knocked off otherwise)
I dont know the full spec.
They are currently manually operated with a switch.
Im not getting payed for this.

Its a powerfold motor, thats all i know...i cant find details on it.

I already suggested a micro and they threw it back.

But with analog its hard to handle all the exceptions......like someone putting ignition on/off for just 3 seconds etc.
They said they didnt want the mirrors to fold out/in only half way.

Circuit has to work with whats already in there........so thats a changeover relay at each 'side' of the motor.
The "bit of schem" i was shown doesnt show anything else but that.

Judging by the name of the car company, they must have solved this themselves by now, but its interesting anyway. (then again maybe not as its low volume) I was actually emailed the task a month back, but only just got to it.
 

mBlock is really implementing binary variables as float? Surprizing.

It's no problem if you have a controller with 8k flash like ATtiny85, a cost optimal solution would however target to really tiny 50 cent processor.


???
Actually might fit in a smaller ATTINY part -

https://en.wikipedia.org/wiki/ATtiny_microcontroller_comparison_chart

Looks like it fits in a ATTINY40 which is a 51 cent part.

In fact could take mBlock code and convert to integers and probably get into a
30 cent part. But then using C at that point makes more sense.

Floats, thats how mBlock is transparent interface for in-experienced user. Obviously
waste of memory / speed, but for stuff like this frankly who cares. Used by kids 6'th
grade and up to program robots. Compromise similar to the compromise we all
made moving from ASM to C/C++. Traded ease of use with.....


Regards, Dana.
 
Last edited:
The real advantage of a micro is that it can easily implement motor stall detection and other protection features.

Nevertheless you can implement the timer with discrete BJT, CD4000 gates, quad 555 or in many others ways. To start the design at all, we would collect missing specifications, e.g. power supply conditions, acceptable quiescent current, timing accuracy requirements, expected behaviour for cancelled start pulse.

Car electronics is expected to handle ISO 7637 transients, including load dump and cold start.
 
Given this is fold in mirror application you have safety issues as well like
knowing the position for power fail recovery. Or stalled motors.

Considerable design issues you face.


Regards, Dana.
 
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…