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.
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.
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.
Arakon:
I've ordered a few optocouplers (4N33) and will give it a try, thanks.
Let us all know how it pans out
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.