# Sound Trigger with Motion Sensor

**URL:** <https://forum.arduino.cc/t/sound-trigger-with-motion-sensor/982024>\
**Category:** General Guidance\
**Created:** [April 17, 2022, 8:50pm UTC](https://forum.arduino.cc/t/sound-trigger-with-motion-sensor/982024 "2022-04-17T20:50:40Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![fotis\_k](https://avatars.discourse-cdn.com/v4/letter/f/4491bb/32.png) [@fotis\_k](https://forum.arduino.cc/u/fotis_k)\
**Post date:** [April 17, 2022, 8:50pm UTC](https://forum.arduino.cc/t/sound-trigger-with-motion-sensor/982024/1 "2022-04-17T20:50:40Z")

</div>

I want to use a motion sensor to trigger sound, so when someone enters the room, a sound file will play from a set of speakers. Does anybody knows what equipment and code should I use?  
Thanks

---

<div class="post-metadata">

**Author:** ![DVDdoug](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dvddoug/32/671533_2.png) [@DVDdoug](https://forum.arduino.cc/u/DVDdoug)\
**Post date:** [April 17, 2022, 9:01pm UTC](https://forum.arduino.cc/t/sound-trigger-with-motion-sensor/982024/2 "2022-04-17T21:01:10Z")

</div>

The Arduino by itself can make "tones & beeps" but if you want to play MP3s or WAV files you'll need an audio shield.

An audio shield will have a slot for an SD card to hold the audio files, and a DAC and it's own little audio processor so the Arduino just acts as a controller to select the file to be played and when to start & stop it, etc.

You'll also need an amplifier for the speakers, or you can use regular powered computer speakers.

---

<div class="post-metadata">

**Author:** ![fotis\_k](https://avatars.discourse-cdn.com/v4/letter/f/4491bb/32.png) [@fotis\_k](https://forum.arduino.cc/u/fotis_k)\
**Post date:** [April 17, 2022, 9:06pm UTC](https://forum.arduino.cc/t/sound-trigger-with-motion-sensor/982024/3 "2022-04-17T21:06:52Z")

</div>

@DVDdoug Thanks for the quick response! Yes, I want to use an mp3 or wav file. So, I will need an Arduino , a sensor and the audio shield, right? Do you recommend a specific audio shield or sensor?  
Thanks

---

<div class="post-metadata">

**Author:** ![8675300](https://avatars.discourse-cdn.com/v4/letter/8/d2c977/32.png) [@8675300](https://forum.arduino.cc/u/8675300)\
**Post date:** [April 18, 2022, 3:16am UTC](https://forum.arduino.cc/t/sound-trigger-with-motion-sensor/982024/4 "2022-04-18T03:16:58Z")

</div>

You can use a Micro SD Card adapter  
[Micro Sd Card adpater](https://www.amazon.com/Module-Storage-Adapter-Interface-Arduino/dp/B07PFDFPPC/ref=sr_1_1_sspa?crid=2TZBXXACIR2EP&keywords=micro+sd+card+adapter+for+arduino&qid=1650251210&sprefix=micro+sd+car+adapter+for+arduino%2Caps%2C83&sr=8-1-spons&psc=1&smid=A2ZDGCOOU4F0SF&spLa=ZW5jcnlwdGVkUXVhbGlmaWVyPUEySTE1QVhZMEhXODZHJmVuY3J5cHRlZElkPUEwMDQxNzYyMThCQkg0NklEVDdCSSZlbmNyeXB0ZWRBZElkPUEwODY1OTkwMUY4SlZNN0NaUlREMyZ3aWRnZXROYW1lPXNwX2F0ZiZhY3Rpb249Y2xpY2tSZWRpcmVjdCZkb05vdExvZ0NsaWNrPXRydWU=)  
and then just get a a micro sd card and then go to somewhere like here [https://audio.online-convert.com/convert-to-wav](https://audio.online-convert.com/convert-to-wav)  
to get your wav file. Drag the file onto the micro sd card, plug it in the sd card adapter and then use a code like this

```cpp
#include <SD.h>
#define SD_ChipSelectPin 4//connect the cs pin of the Micro SD card adapter to pin 4 of the ardunio
#include <TMRpcm.h>
#include <SPI.h>
TMRpcm tmrpcm;
void setup(){
 tmrpcm.speakerPin=9;//connect the speaker pin to 9 if you want
 Serial.begin(9600);
 if(!SD.begin(SD_ChipSelectPin))
 { Serial.println("SD FAIL"); return;
 }
}
void loop(){
  if(digitalRead(7) == HIGH){//This could be your alarm sensor
tmrpcm.play("File.wav");
delay(10000);//Make the delay a little bit longer than however long your audio file is or else it won't play
}

}

```

To play the audio file and then just connect the Micro SD Card adapter's VCC to 5 volts, Miso to pin 12, Mosi to pin 11, and SCK to pin 13. Also in my experience don't name you files more than 4 letters or else it won't load.

---

<div class="post-metadata">

**Author:** ![8675300](https://avatars.discourse-cdn.com/v4/letter/8/d2c977/32.png) [@8675300](https://forum.arduino.cc/u/8675300)\
**Post date:** [April 18, 2022, 3:23am UTC](https://forum.arduino.cc/t/sound-trigger-with-motion-sensor/982024/5 "2022-04-18T03:23:29Z")

</div>

For a alarm sensor you can use a whole bunch a things but how do you want the alarm to be triggered? If it's when a person opens a door you can use a magnet sensor attached to the wall and a magnet attached to the door and the lack of the magnet when it gets moved by the door sets it off, you can also use a distance sensor if the sensor needs to have a little distance so when someone walks in its path it shortens the distance for a little and that triggers it, or an IR sensor if the sensor can be close to whoever is going to trigger it...

---

<div class="post-metadata">

**Author:** ![sterretje](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sterretje/32/391294_2.png) [@sterretje](https://forum.arduino.cc/u/sterretje)\
**Post date:** [April 18, 2022, 4:18am UTC](https://forum.arduino.cc/t/sound-trigger-with-motion-sensor/982024/6 "2022-04-18T04:18:20Z")

</div>

@fotis_k, your topic has been moved to a more suitable location on the forum. _Installation and Troubleshooting_ is not for problems with (nor for advise on) your project 😉 See [About the Installation & Troubleshooting category](https://forum.arduino.cc/t/about-the-installation-troubleshooting-category/847458).

---

<div class="post-metadata">

**Author:** ![fotis\_k](https://avatars.discourse-cdn.com/v4/letter/f/4491bb/32.png) [@fotis\_k](https://forum.arduino.cc/u/fotis_k)\
**Post date:** [April 18, 2022, 8:23am UTC](https://forum.arduino.cc/t/sound-trigger-with-motion-sensor/982024/7 "2022-04-18T08:23:15Z")

</div>

@8675300 Thanks!! You mean that I can use the SD adapter and just the Arduino and the sensor, without the sound shield?

---

<div class="post-metadata">

**Author:** ![Paul\_B](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paul_b/32/216376_2.png) [@Paul\_B](https://forum.arduino.cc/u/Paul_B)\
**Post date:** [April 18, 2022, 10:01am UTC](https://forum.arduino.cc/t/sound-trigger-with-motion-sensor/982024/8 "2022-04-18T10:01:04Z")

</div>

Why do you need an Arduino? 🤔  
[![](https://europe1.discourse-cdn.com/arduino/original/4X/2/8/e/28ee13e754f1a0c7d3831f452c711cea8b9400c3.jpeg)](https://www.aliexpress.com/item/1005001986028946.html)

---

<div class="post-metadata">

**Author:** ![8675300](https://avatars.discourse-cdn.com/v4/letter/8/d2c977/32.png) [@8675300](https://forum.arduino.cc/u/8675300)\
**Post date:** [April 18, 2022, 12:36pm UTC](https://forum.arduino.cc/t/sound-trigger-with-motion-sensor/982024/9 "2022-04-18T12:36:38Z")

</div>

You really don't need an arduino but I would say that having one makes it easier if you're not really familiar in analog circuitry unless you want to just make the speaker beep or something but not if you want an actual alarm sound. As long as you don't use some overkill speaker you won't need any shield for the arduino, I suggest you just use a 5v loudspeaker for arduino and then you definitely won't need a sound shield, which I didn't know was even a thing.

---

<div class="post-metadata">

**Author:** ![fotis\_k](https://avatars.discourse-cdn.com/v4/letter/f/4491bb/32.png) [@fotis\_k](https://forum.arduino.cc/u/fotis_k)\
**Post date:** [April 18, 2022, 1:15pm UTC](https://forum.arduino.cc/t/sound-trigger-with-motion-sensor/982024/10 "2022-04-18T13:15:39Z")

</div>

@Paul_B I want to connect pc speakers with mini jack, to play the mp4 or wav file, so I thought I need an arduino for that

---

<div class="post-metadata">

**Author:** ![Paul\_B](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paul_b/32/216376_2.png) [@Paul\_B](https://forum.arduino.cc/u/Paul_B)\
**Post date:** [April 18, 2022, 10:40pm UTC](https://forum.arduino.cc/t/sound-trigger-with-motion-sensor/982024/11 "2022-04-18T22:40:50Z")

</div>

AFAIK, the DFplayer Mini does all the "playing" for you.

It's a matter of using hardware designed for the purpose. An Arduino is not designed for audio.

Interestingly, there is an "Audio" forum here. I don't go there, so I don't know what sort of things people actually discuss there. 🤨

---

<div class="post-metadata">

**Author:** ![fotis\_k](https://avatars.discourse-cdn.com/v4/letter/f/4491bb/32.png) [@fotis\_k](https://forum.arduino.cc/u/fotis_k)\
**Post date:** [April 18, 2022, 10:50pm UTC](https://forum.arduino.cc/t/sound-trigger-with-motion-sensor/982024/12 "2022-04-18T22:50:40Z")

</div>

Thanks a lot!!

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [October 15, 2022, 10:51pm UTC](https://forum.arduino.cc/t/sound-trigger-with-motion-sensor/982024/13 "2022-10-15T22:51:00Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
