Output pins, solenoids, delay and coding order

I'm getting some unusual behavior from my solenoid (SolenoidTrPin). Here are 2 segments of code that "SolenoidTrPin" should behave the same way (30 ms press):

//CODE VARIANT A
digitalWrite(SolenoidTrPin, HIGH); //line1a
delay(10); //line2a
digitalWrite(RelayPin, HIGH); //line3a
delay(20); //line4a
digitalWrite(RelayPin, LOW); //line5a
delay(0); //line6a
digitalWrite(SolenoidTrPin, LOW); //line7a

//CODE VARIANT B
digitalWrite(SolenoidTrPin, HIGH); //line1b
delay(10); //line2b
digitalWrite(RelayPin, HIGH); //line3b
delay(10); //line4b
digitalWrite(RelayPin, LOW); //line5b
delay(10); //line6b
digitalWrite(SolenoidTrPin, LOW); //line7b

Details:

  • SolenoidTrPin and RelayPin are set to OUTPUT during setup.
  • SolenoidTrPin is a solenoid triggered by a transistor. RelayPin triggers a relay for another device function.
  • Using an ATTINY
  • ATTINY and all components draw power from a wall outlet. Regulators with filter caps reduce voltage to the amounts needed for the components
  • I can't change line 2 (has to do with warm-up time)

"SolenoidTrPin" does not quite behave the same in both cases. I'm not sure if this is what it is, but in executing code variant "B", there seems to be a "hop" at the end. It's like SolenoidTrPin loses power for an instant around line 5 and then re-energizes, resulting in a double-hit (hop). I need to know why this happens.

SolenoidTrPin needs to work flawlessly with it's timing, so I need to figure out what is going on. It seems that Variant A is more reliable, but then I can't change the timing of SolenoidTrPin without changing the timing of RelayPin (and remember that I can't change line2). Why doesn't Variant B perform as expected?

Before you go much (any?) further you should have a look at the approach used in the BlinkWithoutDelay example, also available in the IDE at File > Examples > 2.Digital

You may find a delay-less approach much better in the long-run, although you'll have to invest a bit of effort up-front.

Do relays actually move in 10 to 20 millisec pulse on the coil?

Delay (0); Is pointless.

Weedpharma

JimboZA:
You may find a delay-less approach much better in the long-run, although you'll have to invest a bit of effort up-front.

Will probably go that route for my next project. I don't see how it would help this project, however.

weedpharma:
Do relays actually move in 10 to 20 millisec pulse on the coil?

I have the datasheet around here somewhere, but I'm pretty sure the answer is yes. But my concern is with the Solenoid/transistor timing, not the relay timing.

Could we see a drawing of your circuit?

You need snubber circuit or free-wheel diode on both the solenoid and relay - do you have these?

The demo Several Things at a Time is an extended example of BWoD

...R

weedpharma:
Do relays actually move in 10 to 20 millisec pulse on the coil?

Delay (0); Is pointless.

Weedpharma

Reed relays respond in a couple of ms, it all depends on the size and intertia of the moving parts.

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you please post a copy of your sketch, using code tags?
They are made with the </> icon in the reply Menu.
See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

Also what is the application that needs relays and solenoids to operate so fast?
Can you post a link to the spec for your relays and solenoids please.

We can't see line 2 because we do not have a copy of your sketch.

Tom..... :slight_smile: