Ok folks I have put together the wiring diagram, code and parts list
If you would like the files in a higher resolution email me here and I will send them to you
welshchrisinireland@yahoo.co.uk
I can also send the sound file!
I am in no way a programmer so my code may be a little scrappy, some of it is adapted from a Stormtrooper E11 code used on a different project, there is a section in it for a rotary switch that is no longer being used, I tried to remove it but it seemed to affect the circuit so I just left it in, it doesn't affect the way the rifle operates so use the code as it is or feel free to tinker with it if you wish.
Also there is a slight pause with the sound on the first press of the trigger (no idea why), after that it works fine.
You might want to move the on/off switch to a different position, where I placed mine it was getting knocked off by my glove, I solved it by rewiring the switch in reverse so it gets knocked on rather than off, if that makes sense!
****Important!!!!!, Please be careful when wiring, if you look closely there are basically two power circuits 7.2v from the battery, this powers the led drivers and the Arduino, the rest is powered from the Arduino's 5v output, trigger switch, mp3 player, amplifier chip, dont mix these up or you may very well burn something out!
If anything goes wrong I take no responsibility!
Any questions feel free to ask
Code:-
/*
Project "Cylon Rifle"
Version 1.0 : Light and Sound
*/
// Define Pin layout
const int PinTrigger = 2; // Trigger function
const int PinLED1 = 5;// Led closest to Trigger
const int PinLED2 = 6;
const int PinLED3 = 7;
const int PinLED4 = 8;
const int PinLED5 = 9;
const int PinLED6 = 10;
const int PinLED7 = 11; // Led at nozzle
// Define const for Firing modes
const int FireModeSingle = 1; // DigitalValue (0001)= Rotarypos 1 for Single fire mode
const int FireModeBurst = 9; // DigitalValue (1001)= Rotarypos 9 for Burst fire mode
const int BurstMode = 3; // Amout of sequence repeats on one trigger action
const int Hold_Delay = 50; // [msec] time the trigger must be pushed before activation
const int DelayTime = 50; // [msec] delay between LEDs
const int DelayTimeEnd = 200; // [msec] duration of LED at nozzle
// Variables
int TriggerState = 0; //Reads status of Trigger
int SwitchValue = 0; // Readout of Rotary switch
int SequenceRepeats = 1; // Amount of sequences per Trigger
int PreviousState = 0; // PreviousState of Trigger
unsigned long TimeTriggerPressed; // Time at which the trigger is pressed
boolean SequenceStart = false; // Allow Sequence to Start
void setup() {
// Setup pin modes
pinMode(PinTrigger, INPUT); //Trigger
pinMode(PinLED1, OUTPUT); // Pin Led1 (closest at trigger)
pinMode(PinLED2, OUTPUT);
pinMode(PinLED3, OUTPUT);
pinMode(PinLED4, OUTPUT);
pinMode(PinLED5, OUTPUT);
pinMode(PinLED6, OUTPUT);
pinMode(PinLED7, OUTPUT); // Pin Led7 (Led at nozzle)
digitalWrite(PinLED1,LOW); //Turn off led1
digitalWrite(PinLED2,LOW); //Turn off led2
digitalWrite(PinLED3,LOW); //Turn off led3
digitalWrite(PinLED4,LOW); //Turn off led4
digitalWrite(PinLED5,LOW); //Turn off led5
digitalWrite(PinLED6,LOW); //Turn off led6
digitalWrite(PinLED7,LOW); //Turn off led7
Serial.begin(9600); //Baudrate
Serial.write(0x7E);
Serial.write(0x03);
Serial.write(0xA7);
Serial.write(0x1d); // volume (hexadecimal conversion 1-31 --> 1f = max / 14 = medium)
Serial.write(0x7E);
}
void loop() {
TriggerState = digitalRead(PinTrigger); // read trigger status
// Check state Trigger
if (( TriggerState == HIGH) && (PreviousState == LOW)) { //Mark pressing moment
SequenceStart = true;
TimeTriggerPressed = millis();
}
if (( TriggerState == HIGH) && ( PreviousState == HIGH) && ( SequenceStart == true)) {
if (( millis() - TimeTriggerPressed) >= Hold_Delay) {
for(int x = 0;x<SequenceRepeats; x++) {
// play Led sequence
digitalWrite(PinLED1,HIGH);
delay(DelayTime);
digitalWrite(PinLED1,LOW);
digitalWrite(PinLED2,HIGH);
delay(DelayTime);
digitalWrite(PinLED2,LOW);
digitalWrite(PinLED3,HIGH);
delay(DelayTime);
digitalWrite(PinLED3,LOW);
digitalWrite(PinLED4,HIGH);
delay(DelayTime);
digitalWrite(PinLED4,LOW);
digitalWrite(PinLED5,HIGH);
delay(DelayTime);
digitalWrite(PinLED5,LOW);
digitalWrite(PinLED6,HIGH);
delay(DelayTime);
digitalWrite(PinLED6,LOW);
digitalWrite(PinLED7,HIGH);
delay(DelayTimeEnd);
digitalWrite(PinLED7,LOW);
Serial.write(0x7E);
Serial.write(0x04);
Serial.write(0xA0); // A0 for SD card
Serial.write(0x00);
Serial.write(0x01); // track number
Serial.write(0x7E);
}
SequenceStart = false;
}
}
PreviousState = TriggerState;
}
Parts list, most with links
1. Arduino Nano (the software I use with this clone is 'Arduino 1.0.6')
https://www.ebay.ie/itm/Nano-V3-0-Mini- ... nrcpbSjN7g
2. WT5001M02 28P U disk Audio Player Card Voice Module MP3 Sound For Arduino&WS
https://www.ebay.ie/itm/WT5001M02-28P-U ... SwzaJX4N5D
3. 2 Channels 3W Digital power PAM8403 Class D Audio Amplifier Board USB 5V
https://www.ebay.ie/itm/10PCS-2-Channel ... SwRQlXdzT6
4. EN-EL9 7.2V 1200mAh battery 2 + LCD display USB charger + USB cab J9P8 (these are cheap chinese ones but work fine for me!, the nikon ones are really expensive)
https://www.ebay.ie/itm/For-Nikon-EN-EL ... SwbKRbP6gu
5. Led Diver
https://www.ebay.ie/itm/New-3W-700mA-DC ... 2380834ee2
6.1w led smd White
https://www.ebay.ie/itm/50pcs-1W-LED-SM ... 2749.l2649
7.1w led smd Blue
https://www.ebay.ie/itm/10x-50x-1W-3W-5 ... Z20-jHtbQA
8. 4Ohm 3W Round Inside Magnet Loudspeaker for USB Bluetooth Speaker
https://www.ebay.ie/itm/2W-0-5W-8Ohm-4O ... ayxCv6WG1g
9. Micro on/off switch
https://www.ebay.ie/itm/20pcs-lot-SS12F ... Swf-xZnsC6
10. Red Mini Lockless Momentary ON/OFF Push button Switch
https://www.ebay.ie/itm/10pcs-Red-Mini- ... SwxKtYBw2U
11. 1/8w 1kohm resistor
https://www.ebay.ie/itm/1000PCS-High-Pr ... SwuHJbD4fw
12. 1/4w 10kohm resistor
https://www.ebay.ie/itm/1Set-100pcs-1-4 ... SwqYBWmLyY
13. Solder
https://www.ebay.ie/itm/100g-0-8mm-60-4 ... 4b199ca121
14. Heat shrink tubing (sizes between 1.5mm to 3mm)
15. JST XH 2.5mm connectors and crimping tool (not necessary for the circuit but handy for maintenance)
https://www.ebay.ie/itm/50SETS-of-JST-X ... GK2XOKQVvw
https://www.ebay.ie/itm/Mini-Mirco-JST- ... SwevlaJ6h3
16. 22 gauge Wire (red and black mostly, I used different colours for the Led control cables but you could just use red or black either)
https://www.ebay.ie/itm/Equipment-Wire- ... xydlFSyOxp
17. A good quality soldering station (you will need it for fine soldering, below is the one I use but its up to you what one you choose)
https://www.ebay.ie/itm/AOYUE-INT9378-6 ... SwWxNatUeV
18. Solder sucker
https://www.ebay.ie/itm/190mm-Soldering ... Sw8FBbF6Op
19. Micro SD card (sandisk are good)
20. precision side cutters, wire stippers and mini needle noose pliers
21. Helping hands (you will use these a lot!)
Probably some other stuff I haven't thought of too, I will add if I think of anything else