Arduino Sequencer

Post Reply
VK5HP
Frequent Poster
Posts: 53
Joined: Thu Dec 27, 2012 7:52 am

Arduino Sequencer

Post by VK5HP »

Hi, I am trying to work out how to pulse 1 of the outputs on then off and it continue to turn the other on and stay on. On switching off it turn the outputs off and pulse one on then off.

The reason is I am using a latching relay and don't want to hold the coil powered all the time.

Cheers Paul VK5HP






/******
Flexible 4-Port Sequencer Version 1.0

Designed by Dennis Kidder W6DQ 5 Jan 2014

This sketch when used with the purpose-built hardware described in the
book, "Arduino Projects for Ham Radio," will provide a completely
configurable sequencer. Two sets of two arrays configure the ON sequence
the OFF sequence and the delays between each step. This allows the ON
and OFF sequence order to different along with the ON and OFF times for each
step through sequence.
******/

/******
The following four lines of code allow the user to configure the ON and OFF
sequence and delay times for each step. The default configuration turns
the relays on in the sequence "1,2,3,4" (represented logically by digital
IO pins 0, 1, 2, and 4) and to turn them off in the reverse order "4,3,2,1."

The delay between steps is expressed in milliseconds and the default is 50.
The order of the values in the array corresponds to the order in which the
relays are turned ON or OFF.
******/

#define DEBOUNCEDELAY 10

int relayPin[] = {6,7,8,9}; // order to sequence relays on
int onDelay[] = {50,50,50,50}; // ON times in sequence

int relayPinOff[] = {9,8,7,6}; // order to sequence relays off
int offDelay[] = {50,50,50,50}; // OFF times in sequence

int inputInd = 13; // pin 13 drives the input indicator LED
int pttInput = 10; // pin 5 is the PTT input

int arrayElements = (sizeof(relayPin) / sizeof(relayPin[0])); // elements

void setup()
{
for(int index = 0; index < arrayElements; index++)
{
pinMode(relayPin[index], OUTPUT);
pinMode(inputInd, OUTPUT);
pinMode(pttInput, INPUT);

digitalWrite(pttInput, HIGH);
}
}

void loop()
{

if (debounce(pttInput) == true) {
digitalWrite(inputInd, HIGH);
for(int index = 0; index < arrayElements; index++)
{
delay(onDelay[index]);
digitalWrite(relayPin[index], HIGH);
}
}
else {
digitalWrite(inputInd, LOW);
for (int index = 0; index < arrayElements; index++)
{
delay(offDelay[index]);
digitalWrite(relayPinOff[index], LOW);
}
}
}

/*****
This function is a pretty standard debounce function so we can determine
that the switch has really been pressed.

Parameter list:
int pin the pin that registers the switch state

Return value:
boolean true if the switch was pressed, false otherwise

*****/
boolean debounce(int pin)
{
boolean currentState;
boolean previousState;
int i;

previousState = digitalRead(pin);
for (i = 0; i < DEBOUNCEDELAY; i++) {
delay(1); // small delay
currentState = digitalRead(pin); // Read it now
if (currentState != previousState)
{
i = 0;
previousState = currentState;
}
}
if (currentState == LOW)
return true;
else
return false;
}
VK4TI
Forum Diehard
Posts: 708
Joined: Wed Dec 19, 2012 6:25 am

Re: Arduino Sequencer

Post by VK4TI »

User avatar
VK5ZD
Forum Diehard
Posts: 700
Joined: Tue Feb 17, 2009 7:18 pm
Location: PF95ih
Contact:

Re: Arduino Sequencer

Post by VK5ZD »

Hi Paul

My first observation is that the setup() function appears to have a minor error; the closing brace for for(....) loop should be after the pinMode(relayPin[index], OUTPUT); line. Note that this error has no effect on the end result; it just means that following 3 lines get executed 4 times instead of once, which is all that's needed.

Re the latching relays, you will need to allocate another 4 pins as outputs. e.g. Pins 0, 1, 2 & 3 are used to turn the relays on and pins 4, 5, 6 & 7 are used to turn the relays off (you'll need to decide the actual pins you want to use). I assume there's a transistor or something on each out pin to drive the relay; this will need to be duplicated for the other 4 outputs. The on pins will be set in the int relayPin[] = {0,1,2,3}; // order to sequence relays on statement and the off pins set in the int relayPinOff[] = {4,5,6,7}; // order to sequence relays off statement.

To pulse each pin you'll need replace the digitalWrite(relayPin[index], HIGH); and digitalWrite(relayPinOff[index], LOW); statements something like:

In the turn on loop
digitalWrite(relayPin[index], HIGH);
delay(50); // pulse length
digitalWrite(relayPin[index], LOW);


In the turn off loop
digitalWrite(relayPinOff[index], HIGH);
delay(50); // pulse length
digitalWrite(relayPinOff[index], LOW);


In practice you'd declare a value at the start of the code for the pulse length instead of hard coding the 50 as I've done.
Please note that I've never done any Arduino programming so, as they say, E&OE. :oops:
73
Iain Crawford - VK5ZD
Munno Para West, SA - PF95ih
VK5HP
Frequent Poster
Posts: 53
Joined: Thu Dec 27, 2012 7:52 am

Re: Arduino Sequencer

Post by VK5HP »

Thanks Iain ,

I see if I can make your ideas work ...
Post Reply