This is a project that you can easily adapt to different occasions. It is a doorbell. It can be used, for example, to welcome Christmas visitors by decorating the outside of the box with Christmas elements, the sound files are changed and a Santa Claus appears. In this case we will be adapted for Halloween.
With the creepy doorbell we want to create a little tension when the bell button is pressed. We will reproduce noises, an eye will appear on a round TFT screen and a friendly bat with bright red eyes will appear when the doors open while music runs in the background. Children in the house could help with the construction. As with any of our projects, this is a general idea that should serve the inspiration. You have all the freedom to change it and adapt it for your purpose.
Let's start with our new project.
Required hardware and materials
- 1 Microcontroller board AZ-ATMEGA328
- Jumper Wire cable 3 x 40 pcs. 20 cm m2M / F2M / F2F
- 1 Micro-service MG90S
- 1 Mini Breadboard 400 PIN with 4 power rails for jumper cables
- 1 Ky-004 key module
- 1 GC9A01 1.28 inch round LCD-TFT display
- 1 Mini-MP3 player DFPlayer Master module
- 1 DFPlayer Mini 3 Watt 8 Ohm Mini loudspeakers
- 2 Red LEDs 3mm diameter
- 2 330 ohm resistors
- 1 1K OHM resistance
- 1 MB102 Breadboard Power Suppler power supply
- 3 mm thick balsa wood and white wood glue
Required software
- Arduino IDE
- Dfplayer Mini Library from Dfrobot (Dfrobotdfplayermini.h)
- Servo Library (Arduino Servo.h)
- Spi Library (Spi.H, included in Arduino IDE)
- Adafruit GFX Library (Arduino Adafruit_gfx.h)
- Adafruit GC9A01A Library (Arduino Adafruit_gc9a01a.h)
- Software series library (Softwareerial.H)
- dorbell_sketch.ino
- Sound files 001.mp3, 002.mp3, 003.mp3 and 004.mp3
Circuit and description of the modules used
To interact with the doorbell, we have to Ky-004 button module press. First we the sound file 001.mp3 from Mini MP3 Player DFPlayer Master module played.
We have to use a 1K ohm resistance on the MP3 Player module to adapt the tension in the communication management.
Then in the round screen GC9A01 1.28-inch Round LCD TFT A eye drawn and the sound file 002.mp3 played. Then a third sound file 003.mp3 is played and the two small doors are carried out by the drive of the MG90S Servomotors Open, which moves the support of the figure and this in turn performs the movements of the doors. When the figure comes out, your eye will be with the help of the two Red LEDs (to which we connected two resistances of 330 ohm) red in red and the sound file 004.mp3 is reproduced. When this last MP3 file ends your reproduction, the sound file 003.mp3 is reproduced again, the servomotor is restarted, the figure is laying down and the door closes. Then we switch off the red LEDs. The modules and components described above are with the AZ-ATMEGA328 board Microcontroller controlled. The entire set is with the MB102 Breadboard Power Supply supplied. In addition to the 5 VDC, it offers a 3.3 VDC output that is required to supply the TFT screen. All other components use the 5VDC. The doorbell is played until the bell button is pressed again
Assembly
I used 3 mm thick balsa wood for the components and built a simple box. The assembly of the mechanism for opening the two small doors and leaving the figure is a little more difficult because we only use a single servo motor for the movements.
A pole was attached to the servo engine to get a greater scope for movement. To connect the bar to the figure of the figure, I used a clip to be used to connect papers. I just had to bend them straight and lead them through the holes. To press and close the doors, I also used brackets in the same way. I have installed a bar on every door that is connected to the figure's mechanism. In this way, the servomotor changes its position and with the help of the bar of the feed to the mechanism of the figure. This in turn is also transferred to the doors with the help of the two poles. These doors are attached with hinges. The figure's mechanism pushes the doors with every forward movement and when the backward movement attracts it.
The rear part of the figure is a wedge that has to fit into the slot. This leads and improve the retreat movement of the mechanism. This is probably the part that requires the most patience, since the necessary adjustments for the correct functioning have to be made.
I added the drawings and dimensions of the parts. With balsa wood, the components for a prototype can be cut quickly and adapted. You can also use a 3D printer or other materials.
Description of the sketch
In order to use the modules in an Arduino project, the necessary libraries must always be implemented in the section to definition the global variables (at the beginning of the sketch). In this project, we have to install the libraries for serial communication with the modules, for the use of the TFT screen, for the use of the MP3 module and the servomotor library. Some of these libraries must be added to the Arduino IDE. Either manually, or about the library manager. Search for the name of the library there.
The first library that needs to be added is "Spi.H", it enables communication with devices at the SPI interface. The next library is "Adafruit_gfx.h". It is the main graphics library for displays and will provide us with the necessary methods for drawing primitive graphics (points, lines, circles, etc.). The third library is "Adafruit_gc9a01a.h". It offers the necessary configuration and support for the GC9A01A display driver to be used. With the library
#include "Spi.H". #include "Adafruit_gfx.h". #include "Adafruit_gc9a01a.h". #include <Software.h> #include <Dfrobotdfplayermini.h> #include <Servo.h>
The next two lines of the sketch are the definitions of two total number variables that are later used to implement an object of the TFT screen.
#define tft_screen_dc 7 #define tft_screen_cs 10
An object is then instantiated for each module or component. So the object must be used to use the MP3 player module mysoftware From the library
Software mysoftware(5, 6); Dfrobotdfplayermini mydfplayer;
For the GC9A01A display this will TFT object the library "Adafruit_gc9a01a.h" implemented, whereby The microcontroller must be communicated to which pins the TFT display lines are connected to. The pins DC and CS are the pins 7 and 10, which have been declared as variables at the top.
Adafruit_gc9a01a TFT(tft_screen_cs, tft_screen_dc);
To use the servo engine, the object becomes Servo with the name servo_door the library <Servo.H> implemented.
Servo servo_door;
No object is required for the bell button, since the module is simply a switch and only the condition of its signal line from high levels is changed to low level. Therefore, the variable Ring_Button created with the value 4. It is the digital pin to which the signal line of the switch is connected and the variable ring_call, to save the condition of the signal, either high level with 5 VDC or low level with 0 VDC. These two variables are used later.
intimately Ring_Button = 4; intimately ring_call;
Finally the variable bat_eyes created with the value 2. Behind it is the PIN 2 of the microcontroller, to which the LEDs of the eyes of the figure are connected.
intimately bat_eyes = 2;
If other pins are to be used, they only have to be changed in this first section, since later we only use the variables within the sketch. In this way we avoid many mistakes because we do not have to check the entire code.
After the libraries implemented, created the objects of the modules and the necessary variables have been created, the initial configuration of the modules and the condition of the components must be defined, which in the method set up() happens. The first thing that is done in this method is the initialization of the MP3 module and its communication with the microcontroller with MySoftwareerial.begin (9600), 9600 is the data transfer speed in Baud, communication with the serial monitor is also with Serial.begin (115200) Initialized at a speed of 115200 Baud (we have to select the speed in the lower right part of the screen of the serial monitor when we open it), here the messages of the initialization status or errors of the MP3 module will appear.
mysoftware.Begin(9600); Serial.Begin(115200);
The next thing that has to be defined in the code is to check the initialization of the MP3 module, for which a conditional IF statement is used. In the IF statement the code is carried out within the curly brackets if the condition of the parameter is true. This condition checked whether the MP3 module was not correctly initialized for any reason. The initialization condition was negated by the symbol at the beginning ! was written. This symbol is used as a negation. So if the module is not initialized, the condition is true and the code is carried out to inform the serial console that the connections and the insertion of the microSD card should be checked in the module. If the MP3 player module is correctly initialized, the condition is not met and the code explained above is not executed. The set up()-Methods continue to be carried out to the serial console with the line Serial.println (f ("correct dfplayer initialization.")) to inform that the MP3 player module was correctly initialized.
IF (!mydfplayer.Begin(mysoftware)) { Serial.print(F("Error Initializing MP3 Module:")); Serial.print(F("1. Please check the connections!")); Serial.print(F("2. Please insert the microsd memory!")); while(true){ delay(0); } } Serial.print(F("Correct dfplayer initialization."));
If the initialization of the MP3 module is correct, the round TFT screen will then be initialized. First with the code Serial.println ("GC9A01A initialization.") The serial monitor informs that the initialization of the screen begins. Then becomes tft.begin () executed. This is the initialization method of the screen itself, a timeout of 3 seconds is with Delay (3000) programmed for its correct initialization and finally with the method of the TFT object FillScreen (gc9a01a_black) The screen configured so that all pixels are black.
Serial.print("GC9A01A initialization."); TFT.Begin(); delay(3000); TFT.Fillscreen(Gc9a01a_black);
For the initial configuration of the servo engine, must first servo_door.attach (3) The digital PIN 3 of the microcontroller can be determined to which the signal line of the servo motor was connected. With the code line servo_door.write (1) If the initial position of the servo motor is determined in degrees so that the doors remain closed when the summer is initialized. This value is a guideline and must be adjusted when installing the servo engine that moves the bat so that the bat works properly and the doors can be opened and closed.
servo_door.Attach(3); servo_door.write(1);
For the initial configuration of the LEDs, i.e. the eyes of the figure, must first be configured as an output, this is with Pinmode (bat_eyes, output) made. If the bat is in the box, your eyes should not shine, so this PIN should not deliver tension. This is done by the status of the pin with DigitalWrite (bat_eyes, low) is placed on low level, i.e. with 0 VDC.
pin mode (bat_eyes, OUTPUT); digital (bat_eyes, Low);
In order to complete the start of the doorbell project, with Pinmode (Ring_Button, input) Configured the digital PIN 4 of the microcontroller as an input. It is recognized that the condition of the signal changes when the button is pressed and the associated action is carried out, which later in the method Loop () follows.
pin mode (Ring_Button, Input);
The implementation of the Loop ()-Method that runs continuously and “waits” that the bell button will be pressed and then perform the right actions.
The method considers reading out the bell at the bell key using the digital read(Ring_Button), whereby it should be noted that this measured value can have a high level (unnoticed button) or a low level (pressed button). It is in the variable ring_call saved that was created in the variable definition block.
ring_call = digital read(Ring_Button);
One follows one IF-Else instructionsto with if (ring_call == high) to check whether the variable is high. This means that the button was not pressed. This part is empty, so nothing is carried out and Loop () is continued.
IF (ring_call == HIGH) { // action when the push button is not pressed } Else { .. .. .. .. .. .. .. .. .. .. .. .. }
(It is also possible to write this IF statement without Else branch by just asking if Ring_Call == Low is.)
If the button has been operated, the value of the variable low and thus the Else statement And thus executed their content. Then the volume of the sound reproduction mydfplayer.volume (15) set to a value of 15 (max. 30). Then the file 001.mp3 is with mydfplayer.play (001) Played, which must be saved on the microSD card inserted in the MP3 player module and reproduces the sound of a bell. Then with Delay (11000) A break of 11 seconds inserted so that the file is played completely before the next line of the sketch is executed.
mydfplayer.volume(15); mydfplayer.play(001); delay(11000);
A call to the method follows show_eye (), to display an eye on the round TFT screen. If this method call is made with tft.fillCircle (120, 120, 120, gc9a01a_white) A circle drawn with the eyeball in white color. To draw a circle on the screen, the values of the parameters must tft.fillCircle (value center X-axis, value center circuit y-axis, radius of the circle, color of the circle) be called up. In order to position the center of the circle, the cursor must be placed on the X axis and 120 on the Y-axis at pixel 120, the third value is the radius of the circle in pixels (120) and the last value is the color of the Pixel (Gc9a01a_white). The round screen of the GC9A01A has a resolution of 240 x 240 pixels, so that the center of the circle will be located exactly in the middle of the screen. The next instruction, tft.fillCircle (120, 120, 63, gc9a01a_black), draw a black circle with the same reference point as the center and a radius of 63 pixels. The following instruction tft.fillCircle (120, 120, 58, gc9a01a_yellow), draws the iris in yellow color, the value of the center of the circle is the same and the radius a little smaller than that of the previous circle, so that when drawing the yellow circle there is a black dividing line between the eyeball and the iris. The next call draws the pupil in black color using a circle with the same value of the circular center and a radius of 20. The last circle to be drawn will be a small white circle in the upper right area of the pupil. In this case, the value of the circular center is different.
After the eye has been drawn, red veins are still in the form of lines with the instructions tft.drawline (x axis start, y axis start, x axis end, y axis end, color) implemented. The last line of the show_eye ()-Method is Yield (). With this instruction, the graphics previously implemented are displayed, leaving the method and returning to the line, which directly on the call of the show_eye ()-Method follows, i.e., follows half a second break Delay (500). The Yield ()-Instructions are used within processes that need "enough" time for the execution.
After the timeout of half a second, the sound file 002.mp3 is played. For this purpose, the volume of the sound reproduction mydfplayer.volume (15) set to a value of 15. Then the sound file with the name 002.mp3 mydfplayer.play (002), (this file and all sound files must be saved on the microSD card inserted in the MP3 player module) and the sound "I see you" played. Then with Delay (6000) A break of 6 seconds inserted so that the sound file is played completely before the next line of the sketch is executed.
mydfplayer.volume(15); mydfplayer.play(002); delay(6000);
After playing the previous sound file, the doors should open, the sound of the movement of an old door with the sound file 003.mp3 should be reproduced and the bat moved out. For this, the volume of the sound reproduction is also included mydfplayer.volume (15) set to 15 and the sound file 003.mp3 with mydfplayer.play (003) played with the sound of the movement of the door, a break of 1 second is with Delay (1000) made. The position of the servomotor will change by the position value in grade (45) with servo_door.write (45) is changed. When the axis of the servo motor turns, it will move the wooden stick forward, which is connected to the bat bracket. Since this bracket is connected to the doors, they will open in turn and the bat will move forward until it leaves the box.
mydfplayer.volume(15); mydfplayer.play(003); delay(1000); servo_door.write(45);
As soon as the bat is out of the box, the red LEDs have to shine. To do this, the condition of the digital pin to which the LEDs are connected must be changed to high.
digital (bat_eyes, HIGH);
If the bat has been completely extended, a short song that is saved as a sound file 004.mp3 is played for a few seconds. First the volume of the sound reproduction is included mydfplayer.volume (20) on 20, then the file 004.mp3 mydfplayer.play (004) played, after that is with Delay (6000) A break of 6 seconds inserted so that the sound file is played completely before the next line of the sketch is executed.
mydfplayer.volume(20); mydfplayer.play(004); delay(6000);
When the song is over, the bat will disappear again in the box and the doors will close. In order to carry out these actions, the volume of the reproduction is back to 15 with mydfplayer.volume (15) set. Then the file with name 003.mp3 mydfplayer.play (003) reproduced. This is the sound of the movement of an old door again. A break of 1 second is with Delay (1000) Inserted and with the line servo_door.write (1) the servo engine brought into its initial position. The figure hikes into the box and the doors close.
mydfplayer.volume(15); mydfplayer.play(003); delay(1000); servo_door.write(1);
Then the LEDs of the bat eyes are switched off:
digital (bat_eyes, Low);
Now the image of the eye is removed on the round TFT screen. To do this, all pixels are with tft.fillScreen (gc9a01a_black) placed on black. The last line of the code is that Yield ()-Instruction. The execution of the Loop () Now start from the front and “wait” again that the bell button is operated.
TFT.Fillscreen(Gc9a01a_black); yield();
With this project, the bell could already provide scary. You can also convert and redesign it for other occasions.
(If you cannot see the videos, please check the cookie settings of your browser)
We wish you happy Halloween.
Here again the links to the past Halloween contributions:
- Halloween 2023 - The monster in the box
- Halloween 2022 - the candy guardian
- Scary, Spooky Halloween 2022
- The eyes of the pumpkin - Halloween comes suddenly
- Halloween pumpkin 2.0
- Skull: Halloween 2020
- Halloween 2019 - The pumpkin awakens again
2 comentarios
Andreas Wolter
@Thomas: die Audiodateien werden in der loop() im else-Zweig nacheinander abgespielt:
001
002
003
004
003
testen Sie doch bitte mal auf dem Computer, ob die MP3 auch den korrekten Inhalten haben und eventuell umbenennen.
Ansonsten könnten sie die Nummern im Quellcode so vertauschen, dass die Reihenfolge wieder passt.
Grüße,
Andreas Wolter
AZ-Delivery Blog
thomas
Ich habe das Projekt wie im Blog beschrieben, aufgebaut und die doorbell_sketch.ino verwendet. Leider werden die Audiodateien in falscher Reihenfolge abgespielt, die Delay-Zeiten scheinen zu stimmen. Wo könnte der Fehler liegen? Ansonsten ein nettes Projekt für mich als Anfänger.