Introduction: Playing Imperial March on a Fast Switching Valve

I thought that there have been dozens or Imperial marches played by floppy drives or step motors so I might as well do something new...

The sound you hear is produced by high pressure air rushing out of the valve - it opens and closes very very fast and produces sound. The valve I used here is Festo's MHE3-MS1H-3/2G-QS-6.
Its switch on time is 2.3 ms and it switches off in 2.8ms - very very impressive piece of hardware and they are pretty pricey - luckily I got it for next to nothing.


1. The circuit is very simple - just a ULN2003A used as a driver for the valve. Check the diagram.
(note that I had to substituted the valve with a solenoid - but hey it's a SOLENOID valve after all. Ohh and by the way - if you don't have a pneumatic valve the circuit will work with just a regular solenoid - just mount it so that it strikes a metal object and it should produce sound too ).
CIRCUIT DIAGRAM ->>
http://s7.postimg.org/p459aly0r/ULN2003a_Driving_a_relay.jpg


2. Here's the arduino code (it's a slightly modified version of a sketch created by Carlton Shepherd) - just copy & paste build the circuit as described and it should work just fine

 
    const int c = 261;
    const int d = 294;
    const int e = 329;
    const int f = 349;
    const int g = 391;
    const int gS = 415;
    const int a = 440;
    const int aS = 455;
    const int b = 466;
    const int cH = 523;
    const int cSH = 554;
    const int dH = 587;
    const int dSH = 622;
    const int eH = 659;
    const int fH = 698;
    const int fSH = 740;
    const int gH = 784;
    const int gSH = 830;
    const int aH = 880;
    
    const int buzzerPin = 2;
  
    
    int counter = 0;
    
    void setup()
    {
      //Setup pin modes
      pinMode(buzzerPin, OUTPUT);
    
    }
    
    void loop()
    {
    
      //Play first section
      firstSection();
    
      //Play second section
      secondSection();
    
      //Variant 1
      beep(f, 250); 
      beep(gS, 500); 
      beep(f, 350); 
      beep(a, 125);
      beep(cH, 500);
      beep(a, 375); 
      beep(cH, 125);
      beep(eH, 650);
    
      delay(500);
    
      //Repeat second section
      secondSection();
    
      //Variant 2
      beep(f, 250); 
      beep(gS, 500); 
      beep(f, 375); 
      beep(cH, 125);
      beep(a, 500); 
      beep(f, 375); 
      beep(cH, 125);
      beep(a, 650); 
    
      delay(650);
    }
    
    void beep(int note, int duration)
    {
      //Play tone on buzzerPin
      tone(buzzerPin, note /4, duration);
    
    
    
      //Stop tone on buzzerPin
      noTone(buzzerPin);
    
      delay(50);
    
      //Increment counter
      counter++;
    }
    
    void firstSection()
    {
      beep(a, 500);
      beep(a, 500);   
      beep(a, 500);
      beep(f, 350);
      beep(cH, 150); 
      beep(a, 500);
      beep(f, 350);
      beep(cH, 150);
      beep(a, 650);
    
      delay(500);
    
      beep(eH, 500);
      beep(eH, 500);
      beep(eH, 500); 
      beep(fH, 350);
      beep(cH, 150);
      beep(gS, 500);
      beep(f, 350);
      beep(cH, 150);
      beep(a, 650);
    
      delay(500);
    }
    
    void secondSection()
    {
      beep(aH, 500);
      beep(a, 300);
      beep(a, 150);
      beep(aH, 500);
      beep(gSH, 325);
      beep(gH, 175);
      beep(fSH, 125);
      beep(fH, 125);   
      beep(fSH, 250);
    
      delay(325);
    
      beep(aS, 250);
      beep(dSH, 500);
      beep(dH, 325); 
      beep(cSH, 175); 
      beep(cH, 125); 
      beep(b, 125); 
      beep(cH, 250); 
    
      delay(350);
    }