If someone else reads this and decides to go down the 555 (or Arduino/uC) route, note that you will have to drop the voltage of OUT2 from 24v down to 16v (for the 555) or 5v (for the Arduino/Atmega). You can do this most simply with a voltage divider (e.g. 2.2k and 10k resistors to drop to 4.38v). You'll need to use a relay that matches the resulting logic level - like a 5v relay if you use an Arduino. This may also mean dropping the 24v power line that comes into the relay (and Arduino) to 5v as well. Use a 7805 or LM317 based regulator circuit for that.
Edit: Got it working great. Don't forget that the relay coil should be driven by an auxiliary transistor between the coil and the micro's output pin. Atmega (Arduino) and other uC's can't typically drive a relay coil unassisted. My relay's coil draws 70 mA. The Atmega is only capable of sourcing 40 mA.
Here's the Arduino code:
Code: Select all
/*
This program is designed to hold an output high for 5 seconds after an input goes low. If
the input toggles low and high during the 5 second timeout, the timer is reset.
This was originally designed for air assist control on a laser cutter and engraver. The laswer
controller (AWC-608) has an output that goes low when the laser is active and high when it
is inactive. This output can be used to turn air assist on and off with the laser. This is fine
for cutting, but engraving tends to toggle the laser frequently, and toggling the air pump
that frequently could cause premature wear of the pump, and can cause insufficient air flow.
This program solves that problem.
*/
// Constants. Modify these to match your connections. Arduinos typically have
// built-in LEDs on pin 13.
const int inputPin = 7; // the number of the pushbutton pin
const int outputPin = 8; // the number of the output pin
const int ledPin = 13;
// Program variables
int ledState = LOW; // the current state of the led pin
int lastInputState = LOW; // the previous reading from the input pin
int outputState = LOW; // relay control state
long lastInputHighTime = 0; // the last time the output pin was toggled
long outputHoldTime = 5000; // the output hold time
void setup()
{
pinMode(inputPin, INPUT);
pinMode(outputPin, OUTPUT);
pinMode(ledPin, OUTPUT);
// Get the current input state. Output should be opposite.
// LED and output states need to match.
lastInputState = digitalRead(inputPin);
ledState = !lastInputState;
digitalWrite(ledPin, ledState);
digitalWrite(outputPin, ledState);
}
void loop()
{
// read the state of the switch into a local variable:
int reading = digitalRead(inputPin);
// if intput toggles high, laser just turned off.
if (reading != lastInputState)
{
if ( reading == HIGH )
{
// Reset the timer
lastInputHighTime = millis();
}
else
{
// Pin is low. The relay should be energized any time the pin is low
outputState = HIGH;
ledState = HIGH;
}
}
if ((millis() - lastInputHighTime) > outputHoldTime)
{
// input has been high for longer
// than the hold, so take it as the actual current state:
// Set the output to low to turn off the relay
if (reading == HIGH)
{
ledState = LOW;
outputState = LOW;
}
}
digitalWrite(outputPin, outputState);
digitalWrite(ledPin, ledState);
lastInputState = reading;
}