# How to trigger a sound file in my motion sensor code?

**URL:** <https://discourse.processing.org/t/how-to-trigger-a-sound-file-in-my-motion-sensor-code/13603>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [August 26, 2019, 3:26am UTC](https://discourse.processing.org/t/how-to-trigger-a-sound-file-in-my-motion-sensor-code/13603 "2019-08-26T03:26:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![blorglue](https://avatars.discourse-cdn.com/v4/letter/b/73ab20/32.png) [@blorglue](https://discourse.processing.org/u/blorglue)\
**Post date:** [August 26, 2019, 3:26am UTC](https://discourse.processing.org/t/how-to-trigger-a-sound-file-in-my-motion-sensor-code/13603/1 "2019-08-26T03:26:39Z")

</div>

I am trying to add a sound trigger to my code, but nothing I’ve done seems to work.  
things I’ve tried:  
compared strings with == and .equals  
used a boolean  
made the arduino send a number instead of a string to compare

here is a copy of my code:

```
import processing.sound.*;
static String alert="intruder alert!";
 void setup(){
 file = new SoundFile(this, "intruder.mp3");
 file.amp(0.5);
       }
  void draw(){
    while(mySerial.available() >0){

      myString = mySerial.readStringUntil(nl);//Strip data of serial port

    if(myString !=null){

  background(0);
   myVal=float(myString);
  print(myString);
  if(myString.equals(alert)){
  file.play(1);

}
}

  }
}
```
