Harry Potter Themed Flame Thrower
What?
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() { }
#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() { }
Comments
Post a Comment