DigiGong - SD card digital door bell with an AVR
This article describes a microcontroller based digital door bell circuit that plays different sounds from an SD card. Instead of the boring "ding-dong" you can play your favourite song, a cool 303 acid sound, a Stephen Hawking phrase, a drum solo, animal sounds or what ever comes into your mind. The video above shows an example implementation of the digital door bell in a mask inspired by this guy.
While playing with the first prototype I noticed that having just one sound is quite boring and doesn't allow to distinguish visitors with their different ringing habits. Finally I added some functionality to the code to play different sounds for a different number of door bell presses and press durations. There is also a second input so you can use the gong for two doors, e.g. the house and the garden door. The code can be easily customised for your particular needs. The code and the eagle PCB layout can be downloaded in the Download section below.
Here are the features in short:
- Two button inputs, e.g. different sounds for house and garden door
- Different sounds depending on the number of button presses and press duration. This way the circuit supports "ringing codes" and "aggressive ringing"
- Sounds are given as WAV files of arbitrary length
- All SD cards work (as far as I could test)
- 12 VAC inputs for simple replacement of your standard door bell
- Audio amp for higher speaker power
- No external supply needed, extreme battery live
- AVR based, DIY friendly
- Open source C code and eagle layout allow easy customisation
The circuit is based on the ATtiny861 AVR microcontroller from Atmel.
This chip provides some extended PWM functionality which allows playing
sounds at high quality.
My starting point for the development was the
255-Voice PCM Sound Generator
project published by ChaN from Japan.
Thanks for sharing!
The circuit relies on Chan's own
FAT implementation and needs just a few external components.
I adapted the circuit in several aspects to work as a door bell. My major concern was the high stand-by current of the original circuit that would drain a standard battery in less than one year. I have reduced the hunger for energy of the uC by disabling the watchdog and using the "power down" mode (0.2 uA versus 7 uA). The SD card has been connected through a PMOS transistor and is activated on demand (50 uA vs 0 uA). The audio amp is shut down when not needed. All in all a negligible stand-by current of about 0.2 uA could be achieved. The batteries should reach their "shelf life" of usually 10 years, unless you ring the bell like crazy.
The schematics of the circuit is shown below followed by the technical explanation of the interesting parts.
DigiGong can play files in the uncompressed WAV (PCM) format, mono or stereo, 8 or 16 bits, up to 48 kHz sampling rate. The sound quality is noticeably better with 16 bits because of less noise. Check this site for more info and the original implementation.As shown in the video above, DigiGong plays different sounds depending on the number of button presses, press duration and input channel (door). In the current implementation you have to provide 12 WAV files if you want to make sure the bell responds to all possible ringing options. You need just 6 sounds if using only one door. If you don't want to prepare so many sounds, just copy one file and change the name accordingly.
I can recommend Audacity for editing and audio file conversion. Linux users can use the command line tool sox for the conversion to WAV from any other format. Please make sure, your WAV files are not 24 bit coded. This is not supported. The tool soxi allows to check the format quickly under Linux.
The naming scheme of the WAV files is
||*-presses: 1, 2, 3
|*--press duration: 0-short, 1-long
*---door: 0-A, 1-B
and translates to
|button presses||press duration||door A||door B|
Something worth mentioning is the button polling function "readbuttons()" in the source code package downloadable below. It is extremely robust to bouncing, reads two buttons simultaneously and returns the number of presses and press duration for each button. It allows complex user input while occupying just a single or double uC line. I used a similar principle in the SmaTrig project.
The audio amp in the circuit has several pin-compatible replacements:
LM4861, LM4864, LM4871, LM4889 and TS4990.
At 3V you will get an output power of roughly 250, 400 and 600 mW into a 16, 8 and 4 Ohm speaker respectively. Many more ICs exist for the purpose, but the modern ones are not offered in human-solderable packages (>=SOIC). BTW, the LM4861 and LM4871 I tested pop when waking up from standby. TS4990 is advertised with "near-zero pop and click" in the data sheet. This chip might be a better choice, but seems to be less popular compared to the TI types (ex Linear).
The older amps like the TDA7052 or LM386 need more than 4 V and will not operate from 2xAAA batteries.
The inputs are designed to be connected to 12 VAC or VDC directly. Two AC opto-couplers provide a galvanic separation and pull down two inputs in the AVR. You can use standard DC couplers if you use DC voltages of known polarity. If you want to use simple passive switches as inputs, bridge the couplers or wire the uC lines directly to the input clamps. Note that this solution might pick up noise with longer wires. Adding external pull-ups to the uC lines might be a good idea.
The AC inputs create the problem of zero-crossing spikes, similar to a bouncing switch or a chattering relay. Initially I added two caps to filter out the spikes and simplify software debouncing. Unfortunately the caps were in the MOSI and SCK lines of the ISP and programming didn't work anymore. Finally I solved the problem in software making the button reading routine robust. In the scope graph below you see the signal at the uC side of the coupler with an AC voltage applied to the IR emitters.
The DIP4 package of the coupler can be easily converted into SMD by bending or cutting the pins. You can use two single couplers or a double one. They are stackable.
I used two AA cells for prototyping, but designed the first board with the CR123A lithium cell. This cell known from compact cameras looked like the perfect choice because of it's long life, but turned out to "sag" a lot under load (high inner resistance). Practically, the uC couldn't read the SD card at higher volume settings and got confused. The SD card is designed to work at 3.3 V and the operation at 3 V is already at the limit.
Finally I changed the design to two AAA cells which have a much lower inner resistance of less than 0.5 Ohm. A comparison of the 2xAAA and the CR123A behaviour is shown below. The upper lines show the supply voltage going down with the load (lower line is CR123A). The wiggly signal in the middle is the voltage on one of the speaker terminals. It shows the music played.
The eagle layout of the single-sided PCB is available below. The PCB size is 5 x 5 cm (roughly 2 x 2 inch) and the traces 16 mil wide (0.4 mm). I recommend to tin the PCB for easier SMD soldering.
This is a list of components and possible replacement types.
|PDIP, SOIC, Segor, Reichelt, TME|
|SOIC, Segor.de, Reichelt.de, TME.eu|
PDIP, SOIC Segor, TME
SOIC, Segor, TME
SOIC, advertised with anti-pop circuit
|AC coupler, DIP4, Segor|
|SOT23, Ron=0.1 Ohm, Segor, Reichelt|
SOT23, Ron=0.1 Ohm
SOT23 higher Ron
SOT23 high Ron
|LED1||use bright LED for good low|
current performance, any color
|C1||330 uF||RM3.5, low ESR|
|C2, C5||1 uF||1206 X7R|
|C3||10 nF||1206 X7R|
|C4, C6||330 nF||1206 X7R|
|P1||47k||Piher PT6V, PT10V, Vishay T7YA|
|R1, R2||1k||1206, use 1k for 12 VAC inputs|
|R3||330R - 1k||controls LED brightness|
Wuerth SD 693063020911
|short SD card holder|
|batt||Keystone 82||AAA battery clip|
|J1+J2||MPT 0,5/4-2,54 PHOENIX||2.54 mm, 4 pole or 2x2 if stackable|
|J3||MPT 0,5/2-2,54 PHOENIX||2 pole 2.54 mm|
|ISP||2x3 pole 2.54 mm pin header|
|SPEAKER||4-8 Ohm||Read amp data sheet for more info|
Suppliers: TME.eu, segor.de, reichelt.de
The images below show my door bell at home. One of the DigiGong circuits has been integrated in a wooden housing and connected to trombone. The housing was one of the first things I have made with my new toy. The two cables for both doors are not connected here. They are threaded through a tiny hole in the enclosure.
The development of the project is depicted below. As always, the project started as a perf-board prototype. I prefer connector boards over the standard white "matrix" types.
This is DIY SD card slot
First circuit version with the CR123 lithium battery and the 12 VAC input signal dummy.
Bottom side of the homebrew single-sided PCB. The traces are 16 mil.
The source code and the eagle PCB layout can be downloaded here: digigong.zip
Disposable Email Temporary Email Temporary Email