Approach to control 9 model "fog" cannons

Slumpert:
Loved the video, adding a scripted, random component would be also nice.

Could your power supply support 2-3 going off at once at spaced intervals?

Slight randomness can be added...good idea. Single shot limitation is due to air supply. For smoke burst, max air source pressure is needed.

Also, somewhat slow firing progression gives spectators a somewhat extended effect. Otherwise it's over before they focus on it.

Here is the proposed pin plan. Now to program. Yikes...gotta go study for a while.

And if this goes well, will want to add sound from on-shore sub-woofer. So, as a gun fires, sound from back on shore will be triggered with a slight delay. That means, I think, the on-ship Mega will need to communicate with a board that controls the sound system. Or, more likely, the RC radio Tx will trigger the sound controlled by an UNO timed to the on-ship firing sequence. Hmmm....

Dan if you want to have 2 or 3 overlapping it can be done using MOSFETs to trigger the relays. The current on the mega will be minimal and you can switch your relays on with Hugh side power

wolframore:
Dan if you want to have 2 or 3 overlapping it can be done using MOSFETs to trigger the relays. The current on the mega will be minimal and you can switch your relays on with Hugh side power

So, is having 5 pins simultaneously putting out 5V, 20mA each, total 100mA out of board, too much for the Mega? The whole board must take more than at least 500mA at 5VDC? I can't find that spec.
It's rated at 40mA per pin at 5V.
The durations are low, max 3-4 seconds down to less than 1 sec.

The relay activation coils take only 15-20mA each.

wolframore:
Dan if you want to have 2 or 3 overlapping it can be done using MOSFETs to trigger the relays. The current on the mega will be minimal and you can switch your relays on with Hugh side power

DanLRC:
Dave - wow...thank you for the coaching on this. Really appreciate your time.

Here is my analysis of max current based on the timeline (attached).
At most, 4 total outputs covering three guns will occur at the same time. Here are the two max current situations:

  1. At time about 3.0 sec:
    heat relay 1 ON: 5V, 20mA
    air relay 1 ON: 5V, 20mA
    LED 1 ON: 5V, 15mA
    heat relay 2 ON: 5V, 20mA

TOTAL board output: @5V, 75mA, 0.375W for guns 1 and 2

  1. At time about 3.5 sec:
    heat relay 1 ON: 20mA
    air relay 1 ON: 20mA
    heat relay 2 ON: 20mA
    heat relay 3 )N: 20mA

TOTAL board output: @5V, 80mA, 0.4W for guns 1,2 and three (or subsequent guns in set).

EDIT: forgot relay for main air relay...add another 20mA to totals...so 100mA max total at any time.

So...given that repeat "shots" through 9 guns never requires more than 100mA total from the Mega at any time, the board is well within the spec of 40mA per pin, but what is the max spec total output for the board? I don't see that in the specs I found.

max possible current is
all 8 heaters full on
all 8 solenoids full on
all LED's full on
Min current is idle, nothing but the board
Expected operational current is what you listed.
you can be careful to never allow maximum possible current to occur, but you should at least know that value.
I think that once you start laying out the boards and such some of the parts will fall into place in ways that you do not see at the present.
I can see your point about the time delay.
one shot would get the attentino of the spectators
a longer pause at that point, then the full sequential firing would be an event for all to witness and not miss.
it does sound like a spectacular thing to see.

DanLRC:
So, is having 5 pins simultaneously putting out 5V, 20mA each, total 100mA out of board, too much for the Mega? The whole board must take more than at least 500mA at 5VDC? I can't find that spec.
It's rated at 40mA per pin at 5V.
The durations are low, max 3-4 seconds down to less than 1 sec.

The relay activation coils take only 15-20mA each.

It's in the datasheet. Page 355, section 31 "Absolute Maximum Ratings". 40mA max per pin, 200mA total.

The interesting caveat on that total is that it's limited by the power and ground pins. If you have 40mA going out pin 1 (HIGH) and 40mA coming in pin 2 (LOW) then that current doesn't pass through the power pins and doesn't contribute to the 200mA total.

Yes, in the datasheet - but it's 200mA per VCC pin, so 800mA allowed with a Mega.
I have documented this numerous times, with info from Atmel to back it up:

February 2013

Hello Atmel technical team,
I have a question regarding power utilization in
ATmega328P,
ATmega1284P,
ATmega2560 devices.

The ATmega328P, ATmega1284P, ATmega2560 data sheets all show:

Absolute Max for DC current VCC and GND pins............. 200.0mA.

The Electrical characteristics all show greater then 200mA total being supported by the ports with various current limits per port.

(port notes not copied here)

My interpretation of these notes is that:

for the '328P the sum of current across the VCC/AVCC pins can support the current thru the ports, with 400mA max thru the VCC/AVCC & Gnd pins and 300mA thru the ports, (altho SMD parts have an extra VCC& Gnd pin, so 600mA could be taken in)

for the '2560 the sum of current across the VCC/AVCC pins can support the current thru the ports, with 1000mA max thru the VCC/AVCC & Gnd pins and 800mA thru the ports,

and for the '1284P the sum of current across the VCC/AVCC pins can support the current thru the ports, with 400mA max thru the VCC/AVCC & Gnd pins and 200mA thru the ports (altho SMD parts have 4 each VCC/AVCC & Gnd pins, so 800mA could be taken in) So the '1284 seems to be under supported for IO current. But a nice chip none the less that I will continue to use.

Can you confirm that for 328s & 2560s that the higher currents in the notes are supported and the 200mA Absolute Max is for each individual VCC/Gnd pin and Not for the entire device?

Atmel's Response:
Thank you for contacting Atmel Technical support.

The 200mA is the absolute maximum current rating of the power supply pin. Whatever may be the power supply voltage (The power supply voltage should be within the specification), the current through the Vcc pin should not exceed 200mA.

Also the 200mA specification under the absolute maximum rating is for individual Vcc pin. And the AVCC pins should not be considered along with the VCC pins for the total absolute maximum rating. Hence, for the device ATmega1284P, for the DIP package, the maximum current rating will be 200mA, whereas for the TQFP package, the max. current rating will be 600mA.

For 328P, the max current rating is 400mA for the TQFP package. For ATmega2560, the max current rating is 800 mA. Also, please note that this is absolute maximum rating and exposing the device to absolute maximum conditions for longer duration of time could possibly cause damage to the device.

Hope this clarifies. Please get back to us in case of further queries.

Best Regards,
Ineyaa N
Atmel Technical Support Team

Morgan, XRoads,
Thank you. The 100mA planned max the circuit will draw falls well within the spec then. Doesn't the board have overload protection? If not, couldn't a 150, 200 or whatever mA fast blow fuse be used to protect the board?
The program will be tested with LEDs to debug and confirm proper sequential operation, and will be fixed after that. Doesn't that pretty much eliminate unexpected overload?
Again, many thanks to all. You've taught me a LOT in just 24hrs....

DanLRC:
And if this goes well, will want to add sound from on-shore sub-woofer.

I am shocked, shocked I tell you, to find that the requirements have expanded :wink:

This is another reason for using millis to time things and preferably keep the program responsive. Eventually, you come up with some new thing that you want to do in the middle of the carronade sequence and discover that "oops, I would have to entirely rewrite the program to achieve that". Which is a valuable learning experience of course, but avoidable.

I would be inclined to have an array of structs that specifies, for each carronade, what pins control it and how long in milliseconds its startup is from the initial trigger. Also, a status variable to show what's been done to this gun so far.

Then the code in loop waits for the signal and once it's received just checks to see if it's time to do something else. Then you can tweak things just by changing the data.

MorganS:
It's in the datasheet. Page 355, section 31 "Absolute Maximum Ratings". 40mA max per pin, 200mA total.

The interesting caveat on that total is that it's limited by the power and ground pins. If you have 40mA going out pin 1 (HIGH) and 40mA coming in pin 2 (LOW) then that current doesn't pass through the power pins and doesn't contribute to the 200mA total.

DanLRC:
Morgan, XRoads,
Thank you. The 100mA planned max the circuit will draw falls well within the spec then. Doesn't the board have overload protection? If not, couldn't a 150, 200 or whatever mA fast blow fuse be used to protect the board?
The program will be tested with LEDs to debug and confirm proper sequential operation, and will be fixed after that. Doesn't that pretty much eliminate unexpected overload?
Again, many thanks to all. You've taught me a LOT in just 24hrs....

You keep saying that your projected load is Maximum.
The sum of all power, from any source, is maximum
Your expected load is the sum of heaters, LEDs and relays. That you expect at any point in time.
The sum of all channels, plus any other LED's plus any other WiFi or RF devices , is your maximum.
so, your max is your 20mA relay, 20mA solenoid, 20mA LED per channel X your 8 channels.
just your cannons is 60mA x 8 or 480mA
// I keep saying 8 because your relay boards are 8 channel. not the 9 you list.

your expected load, at this point, is much less.
3 x 60mA = 180mA

depending on how you power your board, say a cell phone charger, the power enters the voltage regulator and that chip is rated for 800mA max, and will self protect. so, it will limit it's output.
if you bypass that and feed power to the board from a separate 5V [ not the 6v you show ] power supply the voltage regulator is bypassed and the new power supply should self regulate.
The trace from the IC to your pin cannot take 800mA
The internal circuit of the IC for any output pin cannot take 800mA
These are two places things can go wrong. I would venture to say we all have a board that has a burnt channel in our cupboard.
Since your expected load is well within the ranges of the board, your expected loads do not need any special protection.
As you develop your sketch, some care should be given to make sure there is no way to have more than half the guns on at any time. Not hard to do.
Since your compressor needs it's own power supply and I assume your heaters have a direct power supply connection, and the relay board has it's own separate power supply, the power supply for the logic part of the project should be well within the ranges of the board.

The relay board has the relay contacts side, they are isolated from the logic side
The relay board has a power input, this is kinda-sorta isolated from the logic, but it gets an external, separate power supply as it needs to power the coils of the relays. this coil power does not come through your Arduino board. it is separate.
Then the relay board's 3rd connections are the low power logic connections, the 8 pins plus either 5V or Ground.
This is separate from the relay board power supply that powers the coils.
Since the logic power is provided by the pins and feeds opto-isolators, each of these will act exactly as if it were an LED. Because that is all the signal does, power an LED inside of the Opto-isolator.
You should be able to feed it 10mA for full saturation to turn the coil on. 20mA is the nominal rating.
I did not read the data sheet for the optos of the board to see.
Don't assume that the 20mA activates the coils and do not connect both power and ground to the relay board. It needs to have a separate power supply.

Your PIN PLAN should show if you have the relay board set so the Arduino pins provides 5V or pulls it to ground.
also, the PIN PLAN should show the external power supply to the relay board, sized for the relay board power consumption. and, I think you need to show the resistor between the Arduino pin and the relay board input for the optocoupler load (load is between 10 and 20mA per channel)

The Songle SRL 5v relay coil is listed at 89.3 mA per relay x 8 on the board
Per your time line, heater1, heater2 and heater3 along with a relay for one solenoid [on a second relay board so it does not add to one relay board total ] = 3 times 90 = 270mA expected load for the relay coils. Since you should provide a separate power supply for the relay board, this goes to your battery selection, not the load on the Arduino board.
MAX load is 8 x 89.3
Expected load is 3 x 89.3
MIN load is for the LED on the relay board to show it has a power supply connected.

Hi Dave,
Thanks for all the time and feedback. I'll try to digest it all.
I'll post a detailed schematic for eval soon.

I understand the distinction between max and expected. But since I don't expect to ever use all the components at once (maximum), is not the expected value good to use for board selection? Just as I would not expect to plug in five 1200W hair dryers on one 15A house circuit. Am I still missing something here? All external components except 9 LEDs will be separately powered.

The pin plan I posted was only to show pin assignment, not meant to be a complete schematic.
Question - for "start" input from the RC receiver, I indicated using the RX0 input pin on the Mega. Haven't researched that yet, but is that the best to use?

Also, for about US$10 I can get Mega boards from our friends in China...I'll probably buy three and expect to possibly lose one in the learning curve.

The reason for the 6V supply is that a 12V SLA battery and a dedicated V regulator will be the power source for the board. I may kick that up to a 7 or 8V regulator, per the spec below.
The spec for the board power is:
"The board can operate on an external supply of 6 to 20 volts. If supplied with less than 7V, however, the 5V pin may supply less than five volts and the board may become unstable. If using more than 12V, the voltage regulator may overheat and damage the board. The recommended range is 7 to 12 volts."

I have three relay boards...3x8=24 total relays.

Only the LEDs will be directly powered by the Mega.
Air relays and heat relays will be separately powered...both coil side and switched power. So I was wrong in saying the board would supply the coil load. I was thinking a bare relay, not the relay board spec. for the logic input.

Still learning....like boot camp....thank you, drill sargeants....

wildbill...I am shocked, too, that I am even thinking about all this.... :o

Here is a first cut at the schematic. Critique welcome.

Also, my first sketch, modified from Arduino Blink example. It is supposed to simulate the flickering flash from the muzzle of the model cannon.
This is a first attempt at the LED part of the overall sketch for the system.

NOTE EDIT: Schematic corrected to v.3 - flyback diode correction, board power supply question

Starting to learn Blink without Delay.
I'm working with an event timeline that has a complication for one sub-event.
The attachment shows the timeline and problem.
Is B w/o D still applicable here?

I'm starting to use an UNO kit to learn...pretty cool.

Thanks.

Would it help to think of it as seven events? Just because the LED has multiple actions, doesn't mean that they need special handling. Use of millis is still the way to go. Indeed, you have to really, because each carronade's events overlap with others.

However you do it, try to ensure that there's one piece of code that handles a carronade. Provide it with data that lets it do it the same way for all nine, but with different output pins and start time offset.

If you look at the way I wrote some fake code,
I set the clock and then just check how long it has been.
if it has been 1.1 seconds, do another thing

none of the 'other' things every interfere with anything else going on.

you would start one cannon
the start time would be recorded and each event after would be a set time.
since you have on and off and heater and solenoid and LED, you have a few things going on.
if you can get that to work to your liking, it is easy to copy that 8 times.

the LED was on/off twice.

if you wanted a 1 second delay between cannons, you can just set

if (elapsed time == 1000) {
cannon2Time = millis();

and then cannon2 would start it's timing.

There are a few different ways to use the concept of Blink Without Delay .

the correct one is the one that works for you.

Bill, Dave,
Thank you. I didn't see each LED flicker being a separate line event. That really clarifies it for me.
I am struggling with the code stuff, but getting there.
Dave, I am referencing your fake code...thank you... just trying to work thru it.
As you suggest, I've set up an UNO with three leds to for the separate events. When I get that working, I'll go to the overlapped 9 cannons.
I REALLY appreciate your help and patience.
Best,
Dan

Now I think about it, it might be easier to model it as fourteen events: one for each change (turn on/turn off). Then the driver code is even simpler. Provide a one time list of timing and then keep checking which are due and do them as they crop up. Keep flags to tell you which have been done. Almost trivial :wink:

YIKES!!! Thank you!
I'm amazed. I tried just writing one cannon as a simple list like I think you meant. The timing sequence is more critical than absolute time, so I got a result that is great!
I used only a few delays, and those so short relative to the key heat and air timing that the whole sequence plays out nicely just as a series.
Next step is to confirm times by hooking up the actual devices and tweaking times to get desired effect. Times should be close based on prototype hardware testing I've done.

Anyway, here's the sketch that works perfectly with LEDs on a test board. Now, I have to digest all the feedback you all have given and figure out how to get 9 overlapping repeats of the one gun sequence.
The timing target will be about 1.5 seconds between shots.

This is habit forming....especially with the support from you all on this forum.

New Q. If I initiate the sequence by just switching board power to "on", and then stop after the nine shots by turning power off (with the R/C transmitter and an R/C receiver switch), then just switching on again for next "broadside", will that work? Pretty simple if that works.

Mega 2560 R3 just delivered! Have all major components now.

Sketch:

// the setup function is for the three functions needed

void setup() {
 // initialize digital pins as output
 pinMode(2, OUTPUT); //heat
 pinMode(4, OUTPUT); //LED
 pinMode(6, OUTPUT); //air  
}

// basic test with loop for 1 cannon
void loop() {
 digitalWrite(2, HIGH);  //time 0, heat on, stays on until write low near end of sketch
 delay(3500); //preheat time
 digitalWrite(6, HIGH);  // air on, stays on until written low at last code line
 delay(200); //time allows smoke to show at muzzle just as flash occurs
 digitalWrite(4, HIGH); // flash sequence for LED starts
 delay(150);   //these delays don't seem to effect pins 2 heat, or 6 air                    
 digitalWrite(4, LOW);   
 delay(15);                       
 digitalWrite(4, HIGH);
 delay(100);
 digitalWrite(4, LOW);
 delay(15);
 digitalWrite(4, HIGH);
 delay(150);
 digitalWrite(4, LOW);
 delay(15);
 digitalWrite(4, HIGH);
 delay(100);
 digitalWrite(4, LOW);
 delay(15);
 digitalWrite(4, HIGH);
 delay(75);
 digitalWrite(4, LOW); //LED flash sequence ends
 digitalWrite(2, LOW); // heat goes off
 delay(300);
 digitalWrite(6, LOW); // air off after heat goes off - clears barrel
 delay(4000); //4 sec to start again.   Can end activity by turning board power off?
}

DanLRC:
New Q. If I initiate the sequence by just switching board power to "on", and then stop after the nine shots by turning power off (with the R/C transmitter and an R/C receiver switch), then just switching on again for next "broadside", will that work? Pretty simple if that works.

Yes, that can be made to work, but why have an Arduino set up to be so dumb? There are probably other useful things it could be doing like animating the sailors on the deck when the cannons aren't firing. Then the cannon sequence just needs a button or signal to start.

DanLRC:
Sketch:

Please edit your post to add code tags.

Then try to change your sketch to remove the delays entirely, just working from millis() timing and a list stored in an array.

if you set the clock at 0
then at 1 second do a thing
at 1.1 seconds do another thing.....

you never delay, you just keep doing everything else, but at the right time, you do a thing.

try 2 LED's connected to pins 6 and 8

there is a difference between the preferred way to code, and easily read code that is more like a list
since your first cannon will need the LED's and solenoid to work together, this snippet is made so you can easily see the timing.

we use flags to tell us if a thing is an some state.
the flag1 can tell us that is has passed a time, without every knowing the time.
you can see that it is long but if you look at it, there are two if() statements.
the first prevents the LED from coming on later in the timing. the second sets the prescribed time.

what is missing is a way to start this, for this exercise, you reset.
and also missing is the heater.

this is a variation of Blink without delay.

/*
 * cannon fodder
 * this exercise is to flash an LED on and off using the clock.
 * the Arduino is started and the system clock millis() is at 0 and 
 * as the system clock counts up, the lights go on and off
 */

const int LED1 = 6;// the number of the LED pin
const int solenoid1 = 8 ;  the number of pin for the solenoid, but now for an LED to test
const int buttonPin = 2;     // the number of the pushbutton pin
   
// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status
int fire1,   fire1_active , fire_flag1 , flag1, button, solenoid1_flag;
unsigned long timing1, start1 ;


void setup() { //+++++++++++++++++++++++++++  setup  ++++++++++++++
  Serial.begin(9600);
  pinMode(LED1, OUTPUT);   // initialize the LED pin as an output:
  pinMode(solenoid1, OUTPUT); 
  pinMode(buttonPin, INPUT);   // initialize the pushbutton pin as an input:
  flag1 = 0 ;
  solenoid1_flag = 0 ;

}

void loop() {  //+++++++++++++++++++++++++++  LOOP  ++++++++++++++

timing1 =  millis() ; 

if (solenoid1_flag ==1) { if (timing1 >= 3500) { digitalWrite(solenoid1, LOW) ;solenoid1_flag=2; }}
if (solenoid1_flag ==0) { if (timing1 >= 2300) { digitalWrite(solenoid1, HIGH) ;solenoid1_flag=1; }}

if (flag1 ==11){ if (timing1 >= 3000) { digitalWrite(LED1, LOW) ;flag1=12; }}
if (flag1 ==10){ if (timing1 >= 2900) { digitalWrite(LED1, HIGH);flag1=11; }}
if (flag1 ==9) { if (timing1 >= 2800) { digitalWrite(LED1, LOW) ;flag1=10; }}
if (flag1 ==8) { if (timing1 >= 2700) { digitalWrite(LED1, HIGH);flag1=9; }}
if (flag1 ==7) { if (timing1 >= 2600) { digitalWrite(LED1, LOW) ;flag1=8; }}
if (flag1 ==6) { if (timing1 >= 2500) { digitalWrite(LED1, HIGH);flag1=7; }}
if (flag1 ==5) { if (timing1 >= 2400) { digitalWrite(LED1, LOW) ;flag1=6; }}
if (flag1 ==4) { if (timing1 >= 2300) { digitalWrite(LED1, HIGH);flag1=5; }}
if (flag1 ==3) { if (timing1 >= 2200) { digitalWrite(LED1, LOW) ;flag1=4; }}
if (flag1 ==2) { if (timing1 >= 2100) { digitalWrite(LED1, HIGH);flag1=3; }}
if (flag1 ==0) { if (timing1 >= 2000) { digitalWrite(LED1, LOW) ;flag1=2; }}

}