Question Powering a 12v Piezo Siren

I have built a project using an Uno, two PIR sensors, and one 12v piezo siren. Although the siren works fine on 5 v and the code i found works, I would like to supply 12 v and use a pot to control the volume. The code I have will output to the positive side of the siren but of course not the 12v I would prefer. I would appreciate any suggestions!

Here is the siren I am using. http://www.ebay.com/itm/191084397392?_trksid=p2059210.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

int ledPin1 = 13;                // choose the pin for the LED
int ledPin2 = 12;
int ledPin3 = 11;
int inputPin = 2;               // choose the input pin (for PIR sensor)
int inputPin2 = 3;
int pirState1 = LOW;             // we start, assuming no motion detected
int pirState2 = LOW;  
int val = 0;                    // variable for reading the pin status
int val2 = 0;
int pinSpeaker = 10;           //Set up a speaker on a PWM pin (digital 9, 10, or 11)

void setup() {
  pinMode(ledPin1, OUTPUT);      // declare LED as output
  pinMode(ledPin2, OUTPUT);      // declare LED as output
  pinMode(ledPin3, OUTPUT); 
  pinMode(inputPin, INPUT);     // declare sensor 1 as input
   pinMode(inputPin2, INPUT);    // declare sensor 2 as input
 // pinMode(pinSpeaker, OUTPUT);
  Serial.begin(9600);
}

void loop(){
  val = digitalRead(inputPin);  // read input value
  if (val == HIGH) {            // check if the input is HIGH
    digitalWrite(ledPin1, HIGH);  // turn LED ON
    delay (150);

     if (pirState1 == LOW) {
      // we have just turned on
      Serial.println("Motion1 detected!");
      // We only want to print on the output change, not state
      pirState1 = HIGH;
    }

     delay (150);

    // check sensor 2 after delay
    val2 = digitalRead(inputPin2);
     if  (val2 == HIGH){
    digitalWrite(ledPin2, LOW);
    delay(150);
    digitalWrite(ledPin3,HIGH);
    //playTone(300, 160);
    delay(150);
     if (pirState2 == LOW) {
      // we have just turned on
      Serial.println("Motion1 from sensor 2 detected!");
      // We only want to print on the output change, not state
      pirState2 = HIGH;
    }
    }
    if(val2 == LOW){
    digitalWrite(ledPin2, HIGH);
    //playTone(300, 160);
    delay(150);
     digitalWrite(ledPin3,LOW);
     delay(150);
    }




} else {
      digitalWrite(ledPin1, LOW); // turn LED OFF
      delay (150);
      digitalWrite(ledPin2, LOW); // may be already
      //playTone(0, 0);
      delay(150); 
      digitalWrite(ledPin3, LOW); // turn LED OFF
      delay (150);      
      if (pirState1 == HIGH){
      // we have just turned of
      Serial.println("Motion ended!");
      // We only want to print on the output change, not state
      pirState1 = LOW;
    }
if (pirState2 == HIGH){
      // we have just turned of
      Serial.println("Motion ended!");
      // We only want to print on the output change, not state
      pirState2 = LOW;
    }
  }
}
// duration in mSecs, frequency in hertz
void playTone(long duration, int freq) {
    duration *= 1000;
    int period = (1.0 / freq) * 1000000;
    long elapsed_time = 0;
    while (elapsed_time < duration) {
        digitalWrite(pinSpeaker,HIGH);
        delayMicroseconds(period / 2);
        digitalWrite(pinSpeaker, LOW);
        delayMicroseconds(period / 2);
        elapsed_time += (period);
    }
}

You will need to use an external transistor switch to handle the voltage and current to drive those sirens. You could do worse than use this sort of circuit:

http://playground.arduino.cc/uploads/Learning/solenoid_driver.pdf

Substitute your sirens for the solenoid coil shown. Your sirens will not need the flyback diode, but it wouldn't hurt anything.

I would like to supply 12 v and use a pot to control the volume.

Something like a 1K pot might work but those things aren't really designed to be volume-controlled.

You can try PWM (just like LED dimming) for volume control with the same transistor or MOSFET "booster" that you'd normally use. But since it's not designed to run from PWM, the tone/character of the sound may be affected along with the volume.

Although the siren works fine on 5 v

I hope you are NOT connecting that thing DIRECTLY to the Arduino without a transistor or MOSFET. It requires 200mA whereas the Arduino is only rated for 40mA. You can potentially damage your Arduino, or cause it to behave strangely and "crash".

You will need to use an external transistor switch to handle the voltage and current to drive those sirens.

Gardner, I don't have my hands on a solenoid but I did find a omr-c-105h 5v relay and a TIP31 transistor in my miscellaneous parts box.

I hope you are NOT connecting that thing DIRECTLY to the Arduino without a transistor or MOSFET.

DVDdoug, I learned the hard way with my first Arduino to never do that! :~ I just meant it works using only 5 volts.

infoseek08: [I don't have my hands on a solenoid but I did find a omr-c-105h 5v relay and a TIP31 transistor in my miscellaneous parts box.

I was not saying you need a solenoid (or a relay). My advice is that that your siren could fit into the circuit INSTEAD of the solenoid shown. A TIP31 should be fine to drive the siren.

Hi, You can try it with high speed optocoupler (like 6N135, 6N136 ). its simple and cost effective.

You can try it with high speed optocoupler (like 6N135, 6N136 ). its simple and cost effective.

Avishek_Das, Thanks I will consider that as well.

I was not saying you need a solenoid (or a relay).

Gardner, I see now what you are saying. I have added the transistor and it seems to be working great but I have run into one issue. The siren goes off for a few seconds in the initial power up. I really need it to be quiet until the PIR is activated. Any suggestions on how I could correct this? I am wondering if I could add a delay in my code. If so I am not sure where to add it.

Use an LM386.

I suppose that during startup, when the AVR pins default to inputs, the floating base of your TIP31 must be allowing some current to flow to the siren. Perhaps a simple fix is to put a 10K or 20K resistor from the base to ground, just to anchor the base low for when the Arduino output is floating.

Gardner, I tried adding a resistor but it unfortunately didn't solve the problem of the siren going off when I first power up. I am thinking it's because of the PIR sensor and sure enough that's what I found when I put my meter on the out pin when I turn it on.

I wonder how I could edit the sketch to delay input from the PIR for say 10 secs? Or maybe delay output from pin 12?

I am also waiting on a shipment of PIR sensors that may not act the same way.