several millis with Relais?

Hey there,

So, basically, I want to build a remote fireworks firing system with several arduinos, each connected to a 16-Relay board that are all part of a MQTT network with a RasPi as WiFi host and MQTT borker that runs the script and/or waits for a message from my mobile phone.
(Yeah, I know... This might not be the best first project to do if you don't know what the hell you're doing, but time is ticking, and I want the basic version done before NYE :o )

Anyways, each arduino should wait until I send the command to turn on a specific relay (usually just one after another from 1-16).
I'd like to have each relay on for about 2 seconds and then turn off again, while still checking for new messages coming in.

I've found the millis() function and I think this would be the best way to go, but I'm not sure how to set it all up.

My idea was to have each arduino to listen to their own MQTT topic and have the pi send the Cue/Relais/Pin # to turn on. The arudino should then turn that one on, record the time and once 2seconds are over turn it back off and ideally stop checking for that time.

I'm not sure how to actually check the timing of several relais at once and if it makes a difference if it tries to check all 16 times while still checking for new commands?
Maybe there's a better/simpler way to get this done?

Thanks for your help! :slight_smile:

The demo Several Things at a Time illustrates the use of millis() to manage timing without blocking. It may help with understanding the technique.

Have a look at Using millis() for timing. A beginners guide if you need more explanation.

Areolys:
(Yeah, I know... This might not be the best first project to do if you don't know what the hell you're doing, but time is ticking, and I want the basic version done before NYE :o )

I wish you well but I think it's much too ambitious for such a short timescale.

...R

@Robin2.
Before which NYE....? Not expressed….

Hi,

best of luck with it but it sems to me to be a lot of things that could go wrong...

phone, network, Arduinos, relays...

I guess that for a firework display you need to time things down to the second and it just seems a bit risky to me?

I'd always go for cable connections if I could as I've never fully trusted 'wireless' communications (I was a voice / data / security network engineer for the last 15 years that I worked).

Peter

Robin2:
The demo Several Things at a Time illustrates the use of millis() to manage timing without blocking. It may help with understanding the technique.

Have a look at Using millis() for timing. A beginners guide if you need more explanation.

I wish you well but I think it's much too ambitious for such a short timescale.

...R

Thanks for the links. They certainly did help me.

For now, I've decided to keep it simple and just turn off all relays if nothing happens for 2 seconds and to reset the timer each time a new close command comes in.

I know, it's kind of a tight schedule, but I'll try it anyways. I've got parts of it set up already and I think I should be able to pull it off. :slight_smile: We'll see :wink:

Peterd51:
Hi,

best of luck with it but it sems to me to be a lot of things that could go wrong...

phone, network, Arduinos, relays...

I guess that for a firework display you need to time things down to the second and it just seems a bit risky to me?

I'd always go for cable connections if I could as I've never fully trusted 'wireless' communications (I was a voice / data / security network engineer for the last 15 years that I worked).

Peter

Thanks for your input.

Yeah, but with all the wires for the ignition there's just too much chaos on site already. Plus, I figured since even professional systems work with 433mhz frequency to transmit the signals, I should be okay with WiFi. :slight_smile:

Areolys:
I figured since even professional systems work with 433mhz frequency to transmit the signals, I should be okay with WiFi. :slight_smile:

I'm no expert but I wonder why the professionals prefer 433MHz?

WiFi can suffer from significant latency. It is generally designed to be reliable rather than timely. Suppose there are several other people using WiFi at the same location ?

...R

Areolys:
Anyways, each arduino should wait until I send the command to turn on a specific relay (usually just one after another from 1-16).
I'd like to have each relay on for about 2 seconds and then turn off again, while still checking for new messages coming in.

My idea was to have each arduino to listen to their own MQTT topic and have the pi send the Cue/Relais/Pin # to turn on. The arudino should then turn that one on, record the time and once 2seconds are over turn it back off and ideally stop checking for that time.

I'm not sure how to actually check the timing of several relais at once and if it makes a difference if it tries to check all 16 times while still checking for new commands?
Maybe there's a better/simpler way to get this done?

The way I read this, the RPi will signal each Arduino and tell that Arduino, turn on relay # x
The Arduino will
receive the signal,
turn on the relay,
count for 2 seconds
turn off the relay
at the same time, the Arduino will
listen for a stop
listen for new relay
if this is the case, yes, this is simple and would work well
no clue about network timing....
Did you rush order the fuses from E-bay ?

If you are going to be controlling fireworks, I would consider putting arming switches in somewhere. Arming switches off, electronic setup cannot fire anything.

Start with arming switches off, turn on the electronic fire control system, let everything get stabilized so no pins are floating and relays are good, then turn on the arming switches. You don't want accidental discharge during boot up.

If you have the time, installing LED's to provide visual feedback on inputs and outputs may be very helpful in system testing.

Thanks again for your replies.

I've already got all the parts needed for the project here and started setting things up.

And yes, I do plan to have an arming switch after the relays that will only be turned on after the system is ready to go.


I thought about it some more and came to the conclusion that it'd be better off running the code for each module on the arduino itself, this would result in the following:

I press go on my phone, that sends command go to the pi (maybe even via SSH),
Pi sends command Module 1 - Go (repeatedly until message recieved)
Module 1 (Arduino) runs though script, opening & closing relais from a set function, listening to STOP commands (just in case we want to abort the show for whatever reason.)
Once done, the Arduino sends command done to Pi,
Pi gets command and tells Module 2 to start,
etc. etc.

That way, I send out a lot less commands.

OR: I send the GO command to all Modules (in my case that's 3 modules) at the same time and have module 2 & 3 loop for minutes until it's their turn.

Not sure what way would work better to keep it all in sync. (+/-1 second would be ideal).

The internal clock in an Arduino is not accurate enough to keep time over weeks and months but it is good for the duration of a fireworks display. If you really get into it then there are some that use better crystals but it is best not to enter that pissing contest.

So just start all your modules at once and let them run.

The code structure for the timing should be relatively simple. Something/anything turns on a relay and records when it did so. Thousands of times per second, the main loop looks at everything which is on and turns off any whose time has expired.

I would look at a few Christmas lights tutorials to see how others have done the timing for that.