Sound Trigger with Motion Sensor

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

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.

@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

You can use a Micro SD Card adapter
Micro Sd Card adpater
and then just get a a micro sd card and then go to somewhere like here 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

#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.

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...

@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 :wink: See About the Installation & Troubleshooting category.

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

Why do you need an Arduino? :thinking:

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.

@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

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. :face_with_raised_eyebrow:

Thanks a lot!!

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