Counter Program for Fire Boxes

Hello, wondering if somebody can guide me in the right direction. I am a member of a fire department and we still use the fire alarm boxes located on the poles around town. It is a basic telegraph system. It is an old technology but works very well and reliable as it does not matter if the internet, telephone or electricity is on.

I am trying to develop a program that can take a contact closure (basic push button), count them and refer to a chart. In our application we use 3 digit "box" numbers.
Example:
Box 162

You would get a 1 button push followed by a 2.75 second pause then 1 push followed by a 1.5 second pause then 1 push followed by a 1.5 second pause then 1 push followed by a 1.5 second pause then 1 push followed by a 1.5 second pause then 1 push followed by a 1.5 second pause then 1 push followed by a 1.5 second pause then a 2.75 pause then 1 push followed by a 1.5 second pause then 1 push followed by a 1.5 second pause followed by an 8 second pause which would signal the end of the box.

What I thought up was to set 3 variables A B C, I am just having trouble setting these with respect to time. There are countless youtube videos on Gamewell fire alarm boxes as well.

Thanks in Advanced!

What do you have so far?

You go through an example but it is hard for me to follow.
Do you have a set of rules that are used for the number of presses and the length of the pauses?

Box 162

You would get a 1 button push followed by a 2.75 second pause then 1 push followed by a 1.5 second pause then 1 push followed by a 1.5 second pause then 1 push followed by a 1.5 second pause then 1 push followed by a 1.5 second pause then 1 push followed by a 1.5 second pause then 1 push followed by a 1.5 second pause then a 2.75 pause then 1 push followed by a 1.5 second pause then 1 push followed by a 1.5 second pause followed by an 8 second pause which would signal the end of the box.

It looks like this paragraph could be factored.

As far as I can see, you count pulses separated by 1.5 seconds until you get a delay of 2.75S. That gives you a digit of the box number.

You continue with that until you get an eight second delay instead of the 2.75. Then you have all the digits you are going to get.

In the OP's case, they're all three digits so the final eight isn't really needed, although you would be ill advised to rely on that.

Before this thread goes to much further, can you verify that you and perhaps other people can time their button pushes to match the rules you have laid down?

Paul

Oh come on! People used to be able to dial phone numbers for free by tapping the hook switch!

TheMemberFormerlyKnownAsAWOL:
Oh come on! People used to be able to dial phone numbers for free by tapping the hook switch!

Been there and done that. MY point is to be able to time :delay of 2.75S, etc.

Paul

MY point is that the “2.75s” gap is going to be…flexible.
Just like the “exact” 10pps dialling restriction.

I would probably start with using 2.125 seconds to differentiate between the 1.5 second and 2.75 second timing, halfway between the two. Would be similar to decoding an old pulse telephone dial, except for the fixed interval between digits. I suspect a large allowance would need to be made for switch bounce.
Would help to have a bit more information, in particular what type of signal, in terms of voltage and current, is being used. Are the boxes wired in a current loop system?

Thanks for all the replies so far. I've been busy with work so I might only be able to reply once or twice a day. I'm not the best with programming but I've built a basic counter program to count button pushes and store in a variable, (and then display it if needed). I'll try to get a video up here as well.
So, the timing can vary slightly.The way the system is designed, each stroke or push is separated by 1.5 seconds, each number (or variable here) is separated by 2.75 seconds. So if nothing is detected after 1.5 seconds, we can assume that we can move onto the next number. To give us some play we can make it 2 seconds.

What I'm thinking is, after the first button push we begin a timer to count down 2 seconds, if a second (or third etc) button push is detected in that 2 second period, we increment counter b]A[/b] and reset the timer back to 2 seconds, if not then we move onto counter B. Same deal on counter B, after the first button push a counter counts back from 2 seconds, if the timer ends without a button push we move onto counter C. Same deal for counter C, first button push we start counting backward from 2 seconds, every push increments variable C until there is no button push for two seconds.

Example

PUSH(1.5 second Pause) PUSH(1.5 second Pause) PUSH (2.75 second Pause which is > 2) Counter A = 3
move to counter B
PUSH (2.75 second Pause which is > 2) Counter B = 1
move to counter C
PUSH(1.5 second Pause)PUSH(1.5 second Pause)PUSH(1.5 second Pause)PUSH(1.5 second Pause) (2.75 second Pause which is > 2)Counter C = 4

BOX 314 Received

Again, thanks for the help guys. Is this feasible on an Arduino? I've just never been able to write anything with respect to multiple time counters.

David, you are correct it's just a simple loop system. We have a uniform time relay that rings a bell.
We can use the same type of relay to just make a simple contact closure on the Arduino, literally just like if you have a push button connected to the Arduino through the analog input pins. (Essentially if you touched two output wires together and got a message "button pushed")

Basic Button Push with Arduino
If I hooked the fire alarm system up to that it would work except I would have a #8 instead of the 314 because that program doesn't care about time.

So, the timing can vary slightly.The way the system is designed, each stroke or push is separated by 1.5 seconds, each number (or variable here) is separated by 2.75 seconds. So if nothing is detected after 1.5 seconds, we can assume that we can move onto the next number. To give us some play we can make it 2 seconds.

Ah, so the actual length of the "push" is not specified, only the intervening timing.

What I'm thinking is, after the first button push we begin a timer to count down 2 seconds, if a second (or third etc) button push is detected in that 2 second period, we increment counter b]A[/b] and reset the timer back to 2 seconds, if not then we move onto counter B. Same deal on counter B, after the first button push a counter counts back from 2 seconds, if the timer ends without a button push we move onto counter C. Same deal for counter C, first button push we start counting backward from 2 seconds, every push increments variable C until there is no button push for two seconds.

You can measure time intervals easily by recording the value from millis() when the button is released and again when it is pushed, then calculate the difference between the two values, which gives you the time interval in milliseconds.

It looks like You work for the firebrigade. Are You allowed to hook up into their system? A malfunction of Your equipment would send the resque units all ower town.

Railroader:
It looks like You work for the firebrigade. Are You allowed to hook up into their system? A malfunction of Your equipment would send the resque units all ower town.

I actually maintain the system part time so no worries there.

I will try to write the code tonight. Are there any examples to use the millis() function?

swker:
I will try to write the code tonight. Are there any examples to use the millis() function?

You want to do something like:

unsigned long oldTime;
unsigned long newTime;
unsigned long elapsedTime;

// if pulse is detected
newTime = millis();
elapsedTime = newTime - oldTime;
oldTime = newTime;

swker:
I actually maintain the system part time so no worries there.

I will try to write the code tonight. Are there any examples to use the millis() function?

That feels safe, for the first time during a long time.

Try the tutorials made by @Robin2, "How to use millis", How to do several things at the same time".

What kind of help are you looking for? I'd be happy to code something up to get you started. Or would you rather do it yourself with some occasional critique?

Thanks everyone, I will give it a crack tonight and see what I come up with and post back!

Ok, I obviously don’t remember as much as I thought from college. I have a basic loop to read in the button presses and I’m using 2200ms (2.2 seconds) as my limit to break out of the loop. This is what I have so far:
int numa=0;
int numb=0;
int numc=0;
unsigned long oldTime;
unsigned long newTime;
unsigned long elapsedTime;
void setup() {

pinMode(2,INPUT_PULLUP);
Serial.begin(9600);
Serial.println(“Waiting For Input…”);

}

void loop() {
if(elapsedTime<2200){
int pushButton = digitalRead(2);
if(pushButton == LOW)
{
Serial.println(“Button is pushed.”);
numa++;

Serial.println(elapsedTime);
newTime = millis();
elapsedTime = newTime - oldTime;
oldTime = newTime;
delay(500);
}
Serial.println(numa);
}
}

My question is how do I add a second and third loop for the second and third number?

swker:
My question is how do I add a second and third loop for the second and third number?

Avoid that by making an array to hold the accumulated numbers byte nums[3]. You'll need an index variable to step through this array. Set the index variable to zero to start. When a number sequence starts, count pulses into the current array element nums[k] on the falling edge of the switch. Then monitor the pulse length. If less than 2-point-something just wait for the next pulse. When the end pulse (length 2.75) is detected increment the index value to point to the next array element and start over. On third end pulse you're done and the received code will reside in:

nums[0], nums[1], nums[2]