I want to play a sound when a door opens

Hello everyone :wink:

I’m new here and don’t know my way around very well.

I want to play a sound when a door opens. the module reacts to high to play the tone. now i would like to write a program with the help of an arduino board.

Button status should be high when the door is closed and low when the door is opened. A high signal should emanate to control the module.
the push button should only go out once. If the door is open, there should be no further signal until I close the door and then open it again.

when opening the door (button Low), a short hight at the exit is required.

I have no plan how to do it now.

Thank you

hello @krisfromhell and welcome to the forum.
I’m not too clear about what exactly you are trying to achieve, but if it’s just a case of having a sound triggered when a switch is opened (or closed) then using an Arduino for it may be overkill. A simple circuit using a switch, battery and tone generator may be all you need. You could possibly use a simple front door bell from your local hardware store, or even a wireless one if the button is a long way from the sound generator, or you need wireless connectivity, and that may be all you need.

Hello and thanks for the answer.
I have a module that can store sounds on an SD card (Voice Playback Module MP3 Music Player).
my problem is that I want to play the sound when a door opens. the switch opens (low) the contact when the door is opened. the module needs a HIGHT to play the sound. and what I still need is that the high signal only appears briefly. after that it has to be low again otherwise the signal runs without a break. the program should turn a LOW signal into a HIGHT signal which is not present all the time, but only stays for a short time. the module receives a brief HIGHT to play the tone and then jumps back to LOW.


Ah, interesting. I still think a simple hardware circuit would probably be an option, with maybe a capacitor that discharges in the time required to switch the switch off again after it’s been switched on (or vice versa) but I don’t know if it’s possible to trigger an mp3 player. I don’t know anything about electronics so I can’t help with that, but there is a website called allaboutcircuits.com where you might be able to find someone in the forums to help you design a simple circuit to do what you need.
Alternatively a simple Arduino program could probably do it too, and probably for a very similar cost. For a simple program like this you may find it easier to use the original Arduino IDE than XOD, and write your program in C. It would probably only be a few lines long and not too hard to put together. There are examples for using buttons connected to an arduino that are used to switch a led on and off in the Arduino examples. Perhaps you could use one of those and add some code to play the mp3 (not sure how to do that but there’s bound to be an example somewhere on the net), then add some logic to wait for the switch to go high again to reset the program to wait for the switch to go low.
It may also be worth having a look around the Arduino forums to see if anyone has already done something similar that you could copy.

Sounds like you want to use a pulse-on-false node to generate a pulse to play music when switch goes low. If you need the signal high longer than just a pulse, then a delay node can be used to turn the pulse into a high signal for a specific amount of time.

I thought something like that would not get any further. tried to do that but somehow I get stuck. the module plays the sound with a HIGHT signal without a break. But I just want to let him play once I achieve that when a short impulse switches to high and then goes back to LOW. I don’t think that’s difficult to program, but that’s where I have my problems.
I thought that this could be done with logic gates.

That was not very clear. I’m guessing what you said is that sending a pulse to the play node does not work because the play node needs the input signal to be HIGH long enough to play the sound (so a pulse is not long enough), but from previous post you can’t just use the switch output because it will continually repeat the play sound instead of just playing it once.

If this is the case, that is what I suggested using the delay node for. delay-SET will be tied to the pulse-on-false node connected to switch so that it starts when door is opened. delay-T should be the time it takes to play the sound (in seconds; you can use 2.5 if the sound is 2 1/2 seconds long). delay-ACT should be wired to the play module; it will be HIGH as long as the delay is doing its count-down. If you want the sound to end as soon as the door closes, add a pulse-on-true node wired to the switch and the delay-RST pin.

Unless the play node sends a signal when the sound is done, I don’t think you are going to implement this just using logic gates since that does not provide a timer. If the node playing the sound sends a signal when the sound is done, you can replace the delay node with a flip-flop and use the “done playing” signal to reset the flip-flop.

If you provide the code you are working with, we might be able to help you figure out where you are going wrong.

Thank you for your all prompt reply :wink:
in the arduino forum nobody answered my question, so thanks to all of you. that’s very nice of you all.

the module only needs a short HIGHT pulse and it plays the tone until the end. if the pulse runs longer than the tone, the tone repeats itself. I would like to play the sound only once when opening the door.

this is my code:

int startPin = A4; // Starttaster
int Lauf = 0; // Kurzzeitgedächtnis

void setup()
pinMode(startPin, INPUT);

void loop()
if (Lauf == 0)
if(digitalRead(startPin) == HIGH)
Lauf = 1;
for (int i=2; i < 11; i++)
pinMode(i,OUTPUT); // Pin als Ausgang definiren
digitalWrite(i, HIGH); // LED an
delay(10); // Pause
digitalWrite(i, LOW); // LED aus
else if (digitalRead(startPin) == LOW && Lauf == 1) {Lauf = 0;}

door closed = signal HIGHT
door open = signal LOW

The door opens and the program turns the LOW signal into a brief HIGHT. as long as I don’t close the door and open it again, nothing happens.

that is the program what i need.

That is Arduino IDE code. The XOD forum is not the appropriate place to ask those questions. The XOD solution would be to use the pulse-on-false node to convert the switch “door open” signal to a pulse that can be sent to a node to play the sound.

To get a pulse to play sound in IDE, use the same code you have for lighting LEDs. The delay() will be the length of your pulse. If you connect your “play sound” wire to pin 11, you can just change your loop condition to i<12 (unless the sound pulse needs to be shorter than the LED pulses or sound needs to play while lights are flashing).

sorry :slight_smile:

Ok I’ll try. thanks for the tip.