Firework Igniter Project

Hi all, I am new to Arduino world. I have been playing with 2 Mega 2560's and 2 HC-05's and (6) 16 Channel relay boards.

My plan is to use my android Galaxy s7 edge to trigger each relay to provide 12v to firework igniter. I am going to use ALL digital pins on the megas as outputs.

Currently using MIT App Maker 2, I have successfully connected to HC-05 and turned on and off 2 leds. (training/understanding software)

I want to link every digital pin on the megas to a PB on smartphone app. What I am running in to is the app sends the text "1" and the relay closes but doesn't reopen after PB pressed. I would assume there is still a "1" in the register.

I have tried the Click and Touch Down block in the MIT app maker.

Could I have some code move a zero into the register at the end of IF statement?

I'm sure there might be a better setup with different devices, but this is what I am working with at moment.

What IF statement? Show your code. In [ code ] tags please.

Currently using MIT App Maker 2

I don't know anything about that...

If you can write a phone app, you can write an Arduino sketch (program). :wink: But, if you are using "App Maker" without knowing how to program, you may find it more difficult.

Yes. By using an if-statement and a delay() or some other timing, and a variable to "remember" if the relay was triggered, the Arduino can turn-off the relay after a short delay, and then you can ignore the fact that you've sent a "1", and you can ignore any further 1's to that relay (until the system is reset, etc.).

The two most important concepts in programming are conditional execution (if statements, etc.) and loops (doing something over-and-over, usually until some condition is reached). Once you understand those two concepts you can start writing useful programs.

Note that the delay() function pauses your program during the delay time. You don't want to hold-up the next action, so look at the Blink Without Delay example and the link at the top of the forum about doing multiple things at a time.

I'm sure there might be a better setup with different devices, but this is what I am working with at moment.

As long as your power supplies can provide the current for the relay coils and the igniters (however many you are activating simultaneously) you should be good to go.

But, I'd be nervous about going wireless with a fireworks display. :wink:

I like this thought.
((By using an if-statement and a delay() or some other timing, and a variable to "remember" if the relay was triggered, the Arduino can turn-off the relay after a short delay, and then you can ignore the fact that you've sent a "1", and you can ignore any further 1's to that relay (until the system is reset, etc.).))

I plan on having a main disconnect for my 12v supply to my firework igniters.

I am looking to fire each firework with a PB per output. No sequence or timers.

Here is the code for the 4 buttons I have been playing with.

void loop()
{
while (Serial.available()) //Send data only when you receive data
{
char c = Serial.read();
readString += c;
}
if (readString.length() > 0)
{
Serial.println(readString);
if (readString == "1")
{
digitalWrite(Spark2, HIGH); // IGNITE 2 FIREWORK ON
}
if (readString == "2")
{
digitalWrite(Spark3, HIGH); //IGNITE 3 FIREWORK ON
}
if (readString == "3")
{
digitalWrite(Spark4, HIGH); // IGNITE 4 FIREWORK ON
}
if (readString == "4")
{
digitalWrite(Spark5, HIGH); //IGNITE 5 FIREWORK ON
}
}
}

I would agree and understand the reasoning behind it but don't understand the code language yet. Could you provide an example?

Thanks

Make sure you turn each relay off after it has finished igniting, otherwise your power supply will drop as you continue turning on more and more relays.

There's nothing in your code to switch the relay pins back to LOW. So of course they'll remain engaged forever.

You're also trying to read multiple characters off the Serial while all you want is a single one. In case there's a second character in the buffer, this goes wrong. This would happen if two characters come in at the same time - e.g. you want to ignite two pieces of fireworks on two different relays.

if (Serial.available()) {
  char c = Serial.read();
  
  // your if statements switching on the relays go here!

}

To switch them off again you must give the relay and the igniter sufficient time to react, so you'll need to add a delay() or other form of timing. Delay() is blocking, nothing else gets done in that time.

I am not getting any response with my leds when I changed Serial.read code. what am I doing wrong?

I would like to set the registor back to zero after the:
{digitalWrite(Spark2, LOW); // sets the IGNITE 2 OFF
delay(1000);
How would I do that? the LED goes off but comes back on. So I assume I could move or set a zero ?

int Spark2 = 2;
int Spark3 = 3;
int Spark4 = 4;
int Spark5 = 5;


String readString;  
void setup()  
{  
    Serial.begin(9600); // Baud Rate    
    pinMode(Spark2, OUTPUT);
    pinMode(Spark3, OUTPUT);
    pinMode(Spark4, OUTPUT);
    pinMode(Spark5, OUTPUT);
   
      
}  
  
void loop()   
{
  if (Serial.available()) //Send data only when you receive data    
    {    
        char c = Serial.read();  
    } 
     
    if (readString.length() > 0)  
    {  
        Serial.println(readString);  
        if (readString == "1")
        {  
            digitalWrite(Spark2, HIGH); // IGNITE 2 FIREWORK ON
            delay(2000);                  
            digitalWrite(Spark2, LOW);    // sets the IGNITE 2 OFF
            delay(1000);                  
        }  
        if (readString == "2")
        {  
            digitalWrite(Spark3, HIGH); //IGNITE 3 FIREWORK ON  
            delay(2000);                  
            digitalWrite(Spark3, LOW);    // sets the IGNITE 3 OFF
            delay(1000);                  
        }   
        if (readString == "3")
        {  
            digitalWrite(Spark4, HIGH); // IGNITE 4 FIREWORK ON
            delay(2000);                  
            digitalWrite(Spark4, LOW);    // sets the IGNITE 4 OFF
            delay(1000);     
        }  
        if (readString == "5") 
        {  
            digitalWrite(Spark5, HIGH); //IGNITE 5 FIREWORK ON
            delay(2000);                  
            digitalWrite(Spark5, LOW);    // sets the IGNITE 5 OFF
            delay(1000);                  
        }    
    }  
}

I am fairly new to arduino but this is how I would do it. I would set up the app so that each virtual button sends a number corresponding to an arduino pin. So the arduino says If I get a one set pin one to high, if I get a 2 set pin 2 to high, etc. for however many seconds it needs to be high and then turns it back to low. kind of like this.

unsigned long timer1;
unsigned long timer2;
unsigned long delayTime=(how many millis you want the igniter on for)

void setup(){

}

void loop(){

unsigned long currentMillis=millis();


int whichOne=serialRead();

if (whichOne==1){
    timer1=currentMillis;
    digitalWrite(1,HIGH);                                  
    whichOne=0;//reset whichOne
}
if (digitalRead(1)==HIGH && currentMillis-timer1>=delayTime){

    digitalWrite(1,LOW)
}


if (whichOne==2){
    timer2=currentMillis;
    digitalWrite(2,HIGH);                                  
    whichOne=0;//reset whichOne
}
if (digitalRead(2)==HIGH && currentMillis-timer2>=delayTime){

    digitalWrite(2,LOW)
}

//repeat for each pin.

What do you guys think?

Thats about as simple as I was thinking it should be. Is that not what I have here?

when INTP mentioned to turn the relays off after Ignite, is when I realized i needed to turn output off after each ignite.

Any one have a better app maker to use? This MIT App Inventor 2 was the first thing I came across.

int Spark2 = 2;
int Spark3 = 3;
int Spark4 = 4;
int Spark5 = 5;
int Received = 0;


void setup()  
{  
    Serial.begin(9600); // Baud Rate    
    pinMode(Spark2, OUTPUT);
    pinMode(Spark3, OUTPUT);
    pinMode(Spark4, OUTPUT);
    pinMode(Spark5, OUTPUT);
   
      
}  
  
void loop(){
    
    if (Serial.available() > 0)
    {
        Received = Serial.read(); 
    } 
if (Received == "1"){       
            digitalWrite(Spark2, HIGH); // IGNITE 2 FIREWORK ON
            Received = 0;
            delay(2000);                  
            digitalWrite(Spark2, LOW);    // sets the IGNITE 2 OFF                
        }  
        if (Received =="2"){
            digitalWrite(Spark3, HIGH); //IGNITE 3 FIREWORK ON
            Received = 0;
            delay(2000);                  
            digitalWrite(Spark3, LOW);    // sets the IGNITE 3 OFF               
        }   
        if (Received =="3"){
            digitalWrite(Spark4, HIGH); // IGNITE 4 FIREWORK ON
            delay(2000);                  
            digitalWrite(Spark4, LOW);    // sets the IGNITE 4 OFF
            Received = 0;  
        }  
        if (Received =="4"){
            digitalWrite(Spark5, HIGH); //IGNITE 5 FIREWORK ON
            delay(2000);                  
            digitalWrite(Spark5, LOW);    // sets the IGNITE 5 OFF
            Received = 0;                  
        }    
    }

Please fix your indentation; it's confusing like this.

Secondly: you read Serial then you put the result in a char c, but you're looking for the content of a variable called readString which you never even initialise nor later assign another value. I notice you fixed that part already.

No idea on this "app maker", I'm using the Arduino IDE for sketch development.

it does seem to be the same, except you are using delays so if you wanted to set off three at once you couldn't. look into blink without delay. Gammon Forum : Electronics : Microprocessors : millis() overflow ... a bad thing?

The only thing I am not sure about is if, in the code I posted, when it comes around to whichOne=serialRead serialRead will still be the previously inputed value. I don't know how the serial buffer works, does it clear the buffer when it is read or is there a command that has to be entered to clear it?

Serial.read() reads a character and removes it from the buffer. It doesn't clear the buffer, any more characters will stay there.

In your case, if you send two commands at the same time, one gets executed, then there's the 2 second delay, then the second command gets executed.

I am using the Arduino IDE for sketch development. The APP maker was for making the App for android phone to be my buttons for the mega 2560, and the mega2560 control the relays.

No idea on this "app maker", I'm using the Arduino IDE for sketch development.
[/quote]

wanted to say thanks for the advice with my project. It worked great, Firework show was awesome. I sat back and set 60 fireworks off with my Galaxy S7 Edge!