Harry Potter Themed Flame Thrower

What?

I bought a roofing torch off of Amazon, bent it into the shape of a flame thrower, and made a casing for it. I then programmed a piezo speaker to play the right-hand part of the sheet music for Harry Potter, while a servo motor plays the left-hand part.

Why?

The idea was inspired by Elon Musk's Boring Company 'Not a flamethrower' which is essentially just a roofing torch with a casing.

To further develop my programming skills, I decided to make it a bit more fun and program it to play the tune to Harry Potter, like a water jet speaker, but more dangerous... and fun?

Why Harry Potter you ask? I was watching Harry Potter at the time of conception of this plan. 

Safe to say this was the peak of my lockdown insanity.

The Video



Hardware

The components used in my circuit were as follows:

 

§  1 x 9V battery

§  1 x Elegoo Uno (Arduino knock off) 

§  1 x Piezo speaker (from this Arduino starter kit)

§  1 x Servo Motor


§  1 x Propane

§  1 x Roofing torch, tube, and gas regulator

§  Some spare foam tube for a pipe (I assume) that my Dad had lying around in his shed.

§  Some wood panel my Grandfather had lying around


The assembly process was fairly simple. The pipe was clamped in and bent into shape by hand, then I sawed the wood down and chiseled in a section for the roofing torch to sit, this is the grip. I drilled some holes, and zip-tied it in, using the zip tie to hold down the igniter switch. I cut up the foam and superglued it onto the wood, with some Harry Potter themed decoration.


I wanted to attach the motor to the roofing torch so it could be done hands-free, but I ran out of time before returning to University, so I just ended up holding the motor against the trigger to pull it back. Not ideal, but I didn't want to bring it with me to Uni.


Firmware


The Servo motor I used doesn't move very fast (0.16sec/60°) so it couldn't keep up with the main melody, unless it only pulled the motor half as far back, which would mean half as much fire... and half as much fun. 


So two versions of the code were written. One was for the motor to pull back to the right-hand section of the song, along with the speaker, and another where it plays the left-hand part.


The following code was written in the Arduino IDE, the first one plays the left-hand part of the tune on the motor, the second plays the right-hand part along with the speaker.


Version 1:


#include "pitches.h"
#include <Servo.h>
Servo myservo;


int lenTune = 31;    //Number of notes in the tune
int currentMillis = 0;
int TA = 45; // Angle to move servo to to pull trigger


//duration of note type in ms
int quaver = 250;
int crotchet = 500;
int minim = 1000;

 
// notes in the melody:
int HP_Notes[] = {
  NOTE_B3, NOTE_E4, NOTE_G4, NOTE_FS4, NOTE_E4, NOTE_B4, NOTE_A4, NOTE_FS4,
  NOTE_E4, NOTE_G4, NOTE_FS4, NOTE_D4, NOTE_F4, NOTE_B3, 0, NOTE_B3, NOTE_E4, 
  NOTE_G4, NOTE_FS4, NOTE_E4, NOTE_B4, NOTE_D5, NOTE_CS5, NOTE_C5, NOTE_GS4, 
  NOTE_C5, NOTE_B4, NOTE_AS4, NOTE_AS3, NOTE_G4, NOTE_E4
  };


int noteType[] = {
  crotchet, crotchet * 1.5, quaver, crotchet, minim, crotchet, minim * 1.5,
  minim * 1.5, crotchet * 1.5, quaver, crotchet, minim, crotchet, minim * 1.5,
  minim, crotchet, crotchet * 1.5, quaver, crotchet, minim, crotchet, minim, 
  crotchet, minim, crotchet, crotchet * 1.5, quaver, crotchet, minim, crotchet,
  minim * 1.5
  };

int flameNotes[] = {0, TA, TA, 0, TA, 0, TA, TA, TA, TA, 0, TA, 0, TA, TA, 0,
                    TA, TA, 0, TA, 0, TA, 0, TA, 0, TA, TA, 0, TA, 0, TA};


int tuneElapsed = 0; 
int loopStart = 0;
int fireStart = 0;

//_______________________________________________________________________________

void setup() {

  Serial.begin(9600);
  myservo.attach(9); //servo connected to pin 9
  myservo.write(0); //moves servo to start position

  for (int note = 0; note < lenTune; note++) {
    
    loopStart = millis();
    tuneElapsed += noteType[note];
    Serial.println(tuneElapsed);
    
    tone(8, HP_Notes[note], noteType[note]);
    myservo.write(flameNotes[note]);
    
    fireStart = millis();
    bool leg = true;
    
    while (millis() - loopStart < noteType[note]) {
      
      if (millis() - fireStart >= 1000 && leg) {
        myservo.write(0);
        fireStart = 0;
        Serial.println("Fire off");
        leg = false;
      }
      
    }
    
  }

  myservo.write(0);
  
}

//_______________________________________________________________________________

void loop() {  
     
}



Version 2:

#include "pitches.h"
#include <Servo.h>
Servo myservo;

int lenTune = 31;    //Number of notes in the tune
int currentMillis = 0;
int TA = 20; // Angle to move servo to to pull trigger

//duration of note type in ms
int quaver = 250;
int crotchet = 500;
int minim = 1000;
 
// notes in the melody:
int HP_Notes[] = {
  NOTE_B3, NOTE_E4, NOTE_G4, NOTE_FS4, NOTE_E4, NOTE_B4, NOTE_A4, NOTE_FS4,
  NOTE_E4, NOTE_G4, NOTE_FS4, NOTE_D4, NOTE_F4, NOTE_B3, 0, NOTE_B3, NOTE_E4, 
  NOTE_G4, NOTE_FS4, NOTE_E4, NOTE_B4, NOTE_D5, NOTE_CS5, NOTE_C5, NOTE_GS4, 
  NOTE_C5, NOTE_B4, NOTE_AS4, NOTE_AS3, NOTE_G4, NOTE_E4
  };

int flameNotes[] = {0, TA, TA, 0, TA, 0, TA, TA, TA, TA, 0, TA, 0, TA, TA, 0,
                    TA, TA, 0, TA, 0, TA, 0, TA, 0, TA, TA, 0, TA, 0, TA};

int noteType[] = {
  crotchet, crotchet * 1.5, quaver, crotchet, minim, crotchet, minim * 1.5,
  minim * 1.5, crotchet * 1.5, quaver, crotchet, minim, crotchet, minim * 1.5,
  minim, crotchet, crotchet * 1.5, quaver, crotchet, minim, crotchet, minim, 
  crotchet, minim, crotchet, crotchet * 1.5, quaver, crotchet, minim, crotchet,
  minim * 1.5
  };


int tuneElapsed = 0; 
int loopStart = 0;
int fireStart = 0;

//_______________________________________________________________________________

void setup() {

  Serial.begin(9600);
  myservo.attach(9); //servo connected to pin 9
  myservo.write(0); //moves servo to start position

  for (int note = 0; note < lenTune; note++) {
    
    loopStart = millis();
    tuneElapsed += noteType[note];
    Serial.println(tuneElapsed);
    tone(8, HP_Notes[note], noteType[note]);
    
    myservo.write(TA);
    delay(0.5 * noteType[note]);
    myservo.write(0);
    delay(0.5 * noteType[note]);

    
    
  }

  myservo.write(0);
  
}





void loop() {  
     
}

The code uses a file called pitches.h, which is essentially a library of every music note, and its corresponding frequency, which made writing the array of notes a lot easier. 

Essentially, I made an array of notes and note types in the order in which they appear in the song, and the code loops through playing each note on the speaker for the right amount of time and moving the servo motor.

I put it into the setup loop so that it only plays once, and I can play it again if I want to with the reset button on the Arduino.


Obstacles

I bought this pipe bender off of Amazon to help, but it broke, so I had to bend it by hand by clamping in the curved part of the broken pipe bender and pulling it with my hands.

Maybe surprisingly, the version in which the motor moves to the slower part was a lot harder to do, as I was essentially having to code it to keep track of two different timings, the time in which the motor should move, and the time in which the speaker should play. 

I managed to get around this because the left-hand part plays around every 1500ms, the variable fireStart keeps count of how long it has been on for, and the bool leg becomes False after 1000ms, to make sure it doesn't come on twice in the same loop. 

The code was very hard and required a lot of problem-solving to get around issues like keeping track of two different timings within one loop but that's what I enjoy about coding, with enough time sat there thinking and trying different things, when it finally works it is the most satisfying feeling.










Comments

Popular Posts