MP3 Doorbell

Hi.
I'm currently working on a doorbell, based on an arduino pro mini and a DFPlayer MP3 player module.
The main issue is that I can't really code. I can understand basic coding and piece things together to get functionality, but I don't know the programming languages as such.

What I got so far: A working doorbell. It's hooked to the actual ringer in the doorbell, which uses a 12V AC connection to a physical bell. The 12VAC are converted to 5V using an AMS1117 + a rectifier and fed to the arduino, which then triggers the MP3 player. If the mp3 is currently playing, the LED will flash instead and it will wait 2x1 second before allowing it to be played again, to avoid interrupting the ringing mp3.
At first, it would trigger also i.e. if the light in the hallway was turned on.. presumably it caused a brief spike in the 12VAC line, not enough to actually move the ringer, but enough to trigger the impulse on the arduino. I managed to get a debouncing routine implemented, which appears to work properly (set to 500ms, as hardly anyone would push the button for less than half a second).
However, it sometimes triggers randomly nonetheless.. nothing was switched on, no power spike, it just suddenly rang. This happens once every 1-2 hours, I guess.
I understand how the debouncing code works, but I am not sure if at some point, leaving it to run for hours, it overflows or resets to a value that would trigger the mp3 playing.

I'd really appreciate if someone could have a look and see if something in the code could be causing this.

Also, don't mind the "zz" variable.. that was meant for a randomizer that was disabled for the time being.

doorbell_debounce.ino (1.26 KB)

Step 1
read this before posting a programming question

Step 2
Load your code here to avoid the need for everyone to download it.

Ah, sorry. I figured it may be easiest to download the code instead, but here it is:

/*********************************
**Wire: 
*Pin10 - player TX; 
*Pin11 - player RX;
*pin12  - player BUSY
**********************************/
#include <SoftwareSerial.h>
#include <DFPlayer_Mini_Mp3.h>
 
SoftwareSerial mySerial(10, 11); // RX, TX
 //int zz = 1;
 int inPin = 2;
 int val = LOW;
 int play_state = HIGH;
 long lastDebounceTime = 0;
 long debounceDelay = 500;
 
 
 void setup () {
  pinMode(inPin, INPUT);
  pinMode(13, OUTPUT);
  Serial.begin (9600);
  mySerial.begin (9600);
  mp3_set_serial (mySerial);    //set softwareSerial for DFPlayer-mini mp3 module 
  delay(1);                     // delay 1ms to set volume
  mp3_set_volume (30);          // value 0~30
}
void loop () { 
   val = digitalRead(inPin);
   play_state = digitalRead(12);// connect Pin12 to BUSY pin of player
     if ( ((millis() - lastDebounceTime) > debounceDelay) && (val == HIGH) && (play_state == HIGH)) {
    lastDebounceTime = millis();
    mp3_play (1);
    //zz = ++zz;
    //if (zz > 3) { zz = 1; }
    digitalWrite(13, HIGH);
    }
          
  else if ( (val == HIGH) && (play_state == LOW) ) {

    lastDebounceTime = millis(); //set the current time
    digitalWrite(13, LOW);
    delay(1000);
    digitalWrite(13, HIGH);
    delay(1000);
    //mp3_next (); 
    }
}

Much easier, thank you.

How is the input to pin 2 wired ?

Pin 2 is wired as follows:

Both lines of the 12VAC ringer/bell -> rectifier -> AMS1117 -> D2

This way, 5v are applied to pin 2 as soon as the bell would turn on.

The arduino and MP3 player have a seperate 5V power supply, so they're always on (not powered by the bell voltage).

Are you connecting the RX/TX of the MP3 player via a resistor divider, as the MP3 player expects 3.3 volts on those pins, not 5v? This is very important (and the module normally has this marked on the back of it).

See my notes on this in my YouTube video #40, all about the MP3 player. URL in the footer of this post.

There's a 1k resistor on each of the TX and RX lines, as I had issues without them. With those, it works fine.
I followed this page mostly:

The playing of MP3s and control via softserial is working flawlessly, only the random triggering is an issue.

OK, I would still connect a further resistor from the TX/RX pins to ground (you want to reduce the 5v to 3v3 so a 2K resistor to ground would ensure this). As it stands, you are still supplying 5v to those pins albeit at reduced current (which may well lead to the required voltage drop, but it's not as it should be).

The 12v rectified doorbell voltage to pin 2 is smoothed enough (if you have a 'scope it's easy to tell, if not then you will have to show us the circuit you are using). A much better (and safer) way of using external voltages is via an opto-isolator: this means the 12v door bell (or 5v from your AMS1117) just lights up an internal LED and effectively allows the 'other side' of that totally isolated circuit to act as a switch. There's more detail in my YouTube video #18 which, whilst operating a relay via this method, is very pertinent to what you are doing.

This way you are assured of no false triggering caused by mains borne spikes etc.

Just suggestin' :slight_smile:

I've ordered a few optocouplers (4N33) and will give it a try, thanks.

Arakon:
I've ordered a few optocouplers (4N33) and will give it a try, thanks.

Let us all know how it pans out :slight_smile:

In fact I'd really appreciate it if you told us how that particular opto-coupler works out as it is different to what I normally use - specifically the darlington arrangement intrigues me. Does this make it more sensitive (what I expect), faster, more reliable...

Whilst I wouldn't call them expensive, the ones I use are most definitely not, so a quick update on these would be great!

Okay, I got it working with the optocoupler. I honestly can't say anything about the sensitivity/speed in my application (it works as a simple on/off switch afterall), but it does turn on reliably from what I can tell.
Since I happened to be at it, I also stuck a light sensor and some LEDs in it to act as a night light, to give a little light to the corridor at night.

The bell still triggers randomly. However, I am quite convinced now that it's the fault of the actual doorbell system in the house, because I once had the original ringer ring when another persons doorbell was actually rung. At night, and some days, it never triggers when it shouldn't, so this also speaks for the "wrong signal from the actual doorbell" theory.

The house is supposed to get a new doorbell system in the next months, so hopefully this issue will not be one any longer then.

Thanks for the help.

Glad it all worked out. I might get one of those opto-isolators just to try one out :slight_smile: