Sound System Using An Arduino

Status
Not open for further replies.

opqdan

New Member
Rather than start yet another Ironman build thread with barely any content and nothing “new” (so far only helmet has been filled and sanded, and the chest, back and neck have been glassed) I thought I would focus on some of the areas that people seem to gloss over: the electronics. Specifically, this means lights and sounds, the goal of this thread being to hook up sound to various parts of a suit. While this is Ironman specific, the idea can be easily applied to any armor or weapon that needs to produce a high quality sound.



This project is based off of an Arduino Duemilanove. More info on Arduinos can be found at http://arduino.cc/. A quote from that site describing what an Arduino is:

“Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software.”

The Arduino is programmed using a simple to understand language based off of C++. In this situation, an Arduino might be a bit of an overkill, but a hobbyist like myself has a one sitting around anyhow. In addition to the Arduino, I used a Wave Shield project from Adafruit Industries (http://www.ladyada.net/make/waveshield/). This board connects directly to the Arduino, and reads WAV files off of an SD card.



Triggers for the sounds are based off of changing the input value on one of the pins. For this example, I use pull down resistors on the pins, with a switch that causes a connection to Vcc. For hooking up repulsors, a simple normally open momentary switch is used to change the value. During normal operation, the input is pulled to LOW by the resistor to ground, then the switch is closed it goes HIGH and plays the sound of a repulsor firing. When the switch is released, the pin returns to LOW and that state change causes the "repulsor charging" sound (kind of like a charging camera flash) to play. The helmet works similarly, the switch is pressed when the faceplate closes playing the characteristic "thunk." When the faceplate opens, the PIN value returns to LOW which causes it to play an opening sound (which right now is nothing). This could be extended to have a small switch play anything you wanted, even theme music.



I mentioned that I used pul-down resistors, here is how that is set up. Note however, that I will probably be changing the design to work backwards with pull-up resistors instead (pull down resistors on TTL circuits use more current than pull-up resistors).





For the code side of things, here is what I wrote. This was written in only a few minutes and is probably rife with bugs.

Code:
#include <FatReader.h>

#include <SdReader.h>

#include <avr/pgmspace.h>

#include "WaveUtil.h"

#include "WaveHC.h"



SdReader card;

FatVolume vol;

FatReader root;

FatReader file;

WaveHC wave;



// Setup input pins

#define REPULSOR 8

#define HELMET 9



int lastRepulsorState = LOW;

int lastHelmetState = LOW;



void setup()

{

  // Setup inputs and outputs

  pinMode(REPULSOR, INPUT);

  pinMode(HELMET, INPUT);

  

  Serial.begin(9600);

  // Initiallize the SD card

  card.init();

  // Optimized reading

  // Not sure if this makes a difference or not.

  card.partialBlockRead(true);

  // Open the FAT16 volume

  vol.init(card);

  

  // Open the root directory in the volume

  root.openRoot(vol);

}



void loop()

{

  // Get the current state of the pins

  int repulsorState = digitalRead(REPULSOR);

  int helmetState = digitalRead(HELMET);

  

  // Amount of time to delay to simulate debouncing a switch

  int debounce = 500;

  

  // Check for signals to play a sound effect.

  // Sound effects play on state changes on the input pins

  // WAV files play asynchronously, so a new one will start before the first can be finished.

  

  // For the helmet, low means the helmet is open, high means it is closed.

  // The switch will be normally open with a pull down resistor on the pin.

  // This value is tied to the eye lights (on/closed = HIGH)   

  if(helmetState == HIGH && lastHelmetState == LOW)

  {

    // Helmet just closed

    char *name1 = "helmcls.wav";

    playByName(name1);

    delay(debounce);

  }

  else if(helmetState == LOW && lastHelmetState == HIGH)

  {

    // Helmet is opening

    char *name2 = "helmopn.wav";

    playByName(name2);

    delay(debounce);

  }

  

  // Repulsor sounds, fire when the button is pressed, charge when it is released.

  // Button is normally open and there will be a pull down resistor on the pin.

  if(repulsorState == HIGH && lastRepulsorState == LOW)

  {

    // play the repulsor fire sound

    char *name3 = "repsht.wav";

    playByName(name3);

    delay(debounce);

  }

  else if(repulsorState == LOW && lastRepulsorState == HIGH)

  {

    // play the repulsor charge sound

    char *name4 = "repchg.wav";

    playByName(name4);

    delay(debounce);

  }

 

  // Store the states from the last iteration

  lastHelmetState = helmetState; 

  lastRepulsorState = repulsorState;

}



void playByName(char *name)

{ 

  PgmPrint("Playing: ");

  SerialPrint_P(name);

    

  // open file by name

  if (!file.open(root, name))

  {

    PgmPrint("Error opening file.");

  }

    

  // create wave and start play

  wave.create(file);

  wave.play();

}



The Arduino with a waveshield:





Hooked up to a DIP switch for testing.





I need to etch the circuit board for the repulsors tomorrow (can't do it tonight since we're brewing beer :p), and then hook the whole thing up, at which point I will post a complete video.



Let me know if you have any suggestions, or questions.
 
This looks pretty interesting, though I don't understand it...



What I really posted this for is I basically love you. I've been looking for a way to get the programming done for my elite project and haven't been able to find anything... until now. This may have solved my problems, if only to a small extent. I'm actually really excited now, since this was posing the biggest problem yet.



You should possibly expect a pm about this...
 
cool setup i may use this for my repulsers (if thats ok XD)



so if im correct this could be installed into the forearms so that when the hand goes back it hits a presure switch (or something like that)and it will play the authentic sound?
 
I could never get motivated before about Arduino because the projects seemed dull...until now! Thanks for posting this information, now I have good reason to learn more about Arduino
 
spartan-381 said:
cool setup i may use this for my repulsers (if thats ok XD)



so if im correct this could be installed into the forearms so that when the hand goes back it hits a presure switch (or something like that)and it will play the authentic sound?

You're better off placing the Arduino/WaveShield system into the chest cavity and running wire down the forearm to the repulsor unit. The arduino unit isn't very big, but it would be hard to keep in the arm, and it would need to connect to a speaker as well. Otherwise, you'd need to reproduce the whole thing for the other arm as well and anywhere else you wanted sound. The idea with this is to keep a centrally located processing unit capable of producing the sounds for the whole suit. In other cases, it could be mounted wherever, like if you wanted to make a gun from Halo, you could keep it inside of the stock (an Arduino would also be able to do cool things like drive the ammunition display).



The plan right now is to have each repulsor unit standalone (that is power, activation, everything is all located in the forearm and guantlet) with the option of having 2 wires run back, under the rest of the arm armor into the chest piece where this unit would be mounted if sound is needed. The switch on the diagram above could be as simple as a relay tied in to the firing part of the repulsor, which in turn could be managed in a number of different ways (like a pressure switch as you mentioned). I should have my repulsor unit working tomorrow, I just received my shipment of surface mount white LEDs so I've got to etch some PCBs tonight and start getting it all soldered together.
 
Last edited by a moderator:
oh yeah duuur didnt think of the speaker lol



the whole setup seems a great idea to me and im interested in seeing/hearing it working :D
 
The aurdiuno's atmega chip has internal pull up resisters you can activate. No need for the external part.



For a display to be controlled by the aurduino, I recommend one of the many inexpensive serial displays available from sparkfun.
 
thatdecade said:
The aurdiuno's atmega chip has internal pull up resisters you can activate. No need for the external part.



For a display to be controlled by the aurduino, I recommend one of the many inexpensive serial displays available from sparkfun.

I knew there was something I was forgetting. I had written the software to expect LOW to HIGH transitions, so I built the project that way and somewhere in there I forgot I could just:

Code:
pinMode(REPULSOR, INPUT);           // set pin to input

digitalWrite(REPULSOR, HIGH);       // turn on pullup resistors

And reverse it all. That saves a bit of wiring, Thanks!
 
Last edited by a moderator:
I must say that I am quite impressed. I mean, most of this is just greek to me, but i get the basic concept. It would be most excellent to pull off that level of authenticity in your build. I look forward to seeing how it turns out!!
 
I started a little bit of work on the repulsor side of things and since it's related to this, and I don't want to start another topic: here it is.



First, I etched a PCB to hold my components. I'm mounting 8 surface mount white LEDs in parallel (so each LED also gets a 100 ohm resistor), this is designed to run at 3 volts, but I found that I could get a huge increase in brightness by pumping it up to 4V, though it will probably lower the life of the LEDs.



The etched board with the components in place (the center spot is for something special). This is at 3V.





The same board at 4volts (see the power supply in the background... uses 70 milliamps when running).





The same board with the center "device" mounted.





That center part is the bulb out of a disposable camera flash, and the circuit next to it is the transformer/capacitor unit that drives the flash. This was done so that I could have the repulsors always have some level of light (provided by the LEDs) and have a "fire" mode which would be provided by the flash (and would produce the "fire" sound from the previously posted sound device).



A word of warning: Camera flashes can be VERY dangerous. Whenver I handle the unit, I use a pair of rubber handled pliers, and whenever I need to do work with any wires I have to discharge the capacitor first. I do this by touching a screwdriver (you are better off using a resistor for this) across the leads which results in a loud pop and a bunch of sparks. Capacitors like this aren't toys, touching those leads packs a bigger punch than sticking your finger in a light socket (depending on the flash, you're looking at anywhere from 300-1000v depending on what's going on). I have at least one burn on my finger from messing with this and scars from screwups on similar circuits in the past (for years I had a small square scar from grabbing a transistor that I'd managed to superheat through bad wiring), and it is not pleasant. Please, if you have no experience in electronics or don't have the proper safety equipment, don't mess with this stuff.



When done, the whole flash circuit will be protected by a plastic casing preventing any part of it from coming into contact with other bits of the circuit. The LEDs are driven by a separate supply and the sound trigger will be either a DPST switch or a relay, this is all so that the camera flash is completely isolated from the rest of the electronics.
 
Last edited by a moderator:
Good note on the warning. As you said, the discharge current from camera flash capacitor will give you wicked bad burns.



Maybe an optoisolator will allow you to control the camera flash the way you want. Keeping it near 100% isolated.



Edit: What kind of PSU is that in the background?
 
thatdecade said:
Good note on the warning. As you said, the discharge current from camera flash capacitor will give you wicked bad burns.



Maybe an optoisolator will allow you to control the camera flash the way you want. Keeping it near 100% isolated.



Edit: What kind of PSU is that in the background?

The optoisolator looks to be a great choice. I'll have to pick some up on my way home from work. Hopefully I can have this thing it total working shape by the end of the weekend.



The power supply is this one: http://www.frys.com/product/5095835
 
Last edited by a moderator:
Status
Not open for further replies.
Back
Top