The festival that takes place on October 31st every year is Halloween, also known as the Night of the Witches. It is a particularly popular festival in Anglo-Saxon countries such as the United States, Canada, Ireland and the United Kingdom, but has spread to many parts of the world in recent decades.
Its origins lie in pagan rituals and beliefs about the afterlife. The name comes from the expression “All Hallows’ Eve,” which means “All Hallows’ Eve.” Over time, this term was shortened to “Halloween,” but today it is celebrated primarily as a festival of fun. It is a festival associated with the supernatural, fear and fun, where costumes, illuminated pumpkins, candy and scary stories abound.
The festival is characterized by dressing up in costumes depicting supernatural beings (witches, vampires, ghosts, monsters) and it is customary for children to go from house to house asking for sweets with the slogan “Trick or Treat”. If they don't get any candy, they get to play a little prank.
Homes, schools and shops are decorated with spooky elements: cobwebs, skeletons, skulls, bats, ghosts and dim lights. For this year's decoration, we created a project with a skeleton that sways back and forth and, when someone approaches, stops, its eyes light up and it stands up, of course with sound effects to reinforce the impression.
The required materials are:
● 1 AZ-Nano V3 board with USB-C connector with Atmega328 CH340
● 1 Terminal adapter board with screw terminals, compatible with Nano V3
● 1 MB102 breadboard power supply adapter
● 1 Mini breadboard 400 PIN with 4 power rails for jumper cables
● Jumper cables 3 x 40 pieces, 20 cm, M2M / F2M / F2F
● 2 Red LED
● 2 330 ohm resistor
● 1 Mini MP3 player DFPlayer master module
● 1 1k ohm resistor
● 2 Piece DFPlayer Mini 3 Watt 8 Ohm Mini Speaker
● 1 PAM8403 digital mini audio amplifier 2x 3 watts
● Ultra Flexible Tinned Copper
● 3mm thick balsa wood and white wood glue
The required software is:
● Arduino IDE
● SPI.h library (included in the Arduino IDE)
● DFPlayer mini library from DFRobot (DFRobotDFPlayerMini.h)
● Servo.h library (Download from arduino.cc)
● 001.mp3
● 002.mp3
● Skeleton_the_Scythe.ino
Circuit and description of the modules used

Figure 1 – Electronic diagram

Figure 2 – Distribution of components
As can be seen from the circuit diagram, two servo motors are used, which are responsible for moving the project. The MG90S servo motor with metal gear is used to move the rocking chair, as this has to do most of the work as it is constantly in motion. The SG90 servo motor, which has plastic gears, was chosen to raise the skeleton as it is only activated when a presence is detected. The HC-SR04 ultrasonic sensor was used for this presence detection, as the distance of the people must be known in order to activate the skeleton. To illuminate the skeleton's eyes, two red LEDs were used, each of which must be connected to a 330 ohm resistor to adjust the supply voltage and not damage them. For the sound of the rocking chair and the skeleton, the DFPlayer MP3 mini module, the PAM8403 sound amplifier and two DFPlayer Mini 3 Watt 8 Ohm Mini speakers were used. The entire set is powered by the MB102 power supply, and the AZ-module is used as a microcontroller.Nano V3 with USB-C port used.
As mentioned earlier, this project uses an MP3 playback module and an amplifier to play the sounds. The connection pins of the two modules are as follows:

Image 3 – PAM8403

Image 4 – Mini MP3 player
For the audio files to play correctly, the first audio file saved to the microSD card must be named 001.mp3 and contain the sound of creaking wood. The audio file 002mp3 will then be saved. The MP3 playback module has the special feature that when you call up file 001, the first saved file is played and when you call up file 002.mp3, the second saved audio file is played.
Plans of the project figures
The project consists of three parts: a rocking chair, the framework and the base into which the electronic components are installed. Balsa wood was used because this material is light and has high strength. The rocking chair consists of four parts: the backrest, two side parts and the seat, all of which have a thickness of 6 millimeters. To achieve this thickness, two equal parts with a thickness of 3 mm were glued together with white glue. The dimensions of the parts of the rocking chair are as follows:

Picture 5 – Rocking chair
The skeleton figure consists of 9 parts: skull, back, pelvis, arms and legs.

Image 6 – Skeleton
The skull piece is 15 millimeters thick, so 5 pieces of wood need to be glued together. The first two parts consist only of the skull, the last three parts consist of the skull and a mast.
To mount the two red LEDs in the eyes of the skull, the eyes of the first four parts of the skull were hollowed out and in the fifth part (the back one) holes were drilled to bring out the connectors of the LEDs as they are inserted into the eye sockets.

Image 7 – Skull and eyes in the skull
The skull and back are attached to a pole that serves to raise the skeleton of the chair. The arms are connected by a piece of wire that runs through the mast, and these are attached to another vertical wire that is attached to the base of the skeleton and causes the arms to rotate, giving the impression that they are being raised when the skeleton is raised. The servo motor is installed at the base of the skeleton ensemble to drive the mast and lift the skeleton.

Figure 8 – Detailed view of the arm movement mechanism

Figure 9 – Servo motor for lifting the skeleton
The skeleton's legs were glued to the base on which the skeleton rests. The last two details of the skeleton are the cloak and the scythe. The cape is divided into three parts: the hood, the sleeves and the cape itself. To make the hood, the upper part must be glued or sewn and then glued to the upper part of the cape. To make the sleeves, you need to make two rectangles, fold them and glue them on one side. The sleeves need to be glued to the cape or to the skeleton's arms as needed. In this project they were glued to the arms. The cape has been cut at the back to better show off the skeleton. And finally, the scythe has a thickness of 3mm.

Picture 10 – Put on the cloak and scythe
The basis of the construction is a box that houses the electronic components and the servo motor that drives the rocking chair. This servo motor drives the structure, which has two wires at either end that run through the top of the box and are attached to the back of the rocking chair runners. In this way we allow the movement of the rocking chair.

Image 11 – Box details

Figure 12 – Dimensions of the box

Picture 13 – Assembly completed

Picture 14 – Assembly completed

Image 15 – Skeleton of the scythe
Description of how the project works and sketch
The working of the circuit is simple as can be seen from the circuit. The HC-SR04 ultrasonic sensor is used to send signals with a duration of 10 microseconds and a waiting time between pulses of 5 microseconds. When a signal is bounced back from a person or object, the sensor detects the received signal and the microcontroller calculates the time the signal took between being sent and received. Since the speed of sound in air is known, the distance to the object or person can be determined. As long as the distance is greater than or equal to 40 centimeters, the rocking chair moves by the action of the MG90S servo motor and an MP3 file with a creaking wooden sound is played thanks to the combination of the DFPlayer Master Module mini MP3 player, the PAM8403 mini digital audio amplifier and the DFPlayer Mini 3 Watt 8 Ohm mini speaker reproduced. If an object or person is detected less than 40 centimeters away, the rocking chair will stop in its middle position and the sound will stop. After 1.5 seconds, the red LEDs in the skeleton's eyes light up and after 2 seconds, the skeleton's laughter is played and the skeleton quickly gets up from the chair thanks to the SG90 servo motor.
After the functionality has been explained, the sketch is now analyzed. The first thing to do in each sketch is to implement the necessary libraries in the global variable definition section so that the modules we use can be used. The three added libraries are required to use the Mini MP3 Player DFPlayer module and the servo motors. Since the required communication between the MP3 module and the microcontroller must be serial communication, this is done with the library SoftwareSerial.h Enables the function that allows the microcontroller to enable any digital pin for serial communication. With the library DFRobotDFPlayerMini.h The functions required to use the module are activated. The last library to be added is <servo.h>. This library contains the configuration and methods required to change the position of the servo motors.
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>
#include <Servo.h>
In this project, the ultrasonic sensor without library is used. It is shown that the distance to objects or people can be found with a simple mathematical operation, which is why the library is not added.
After the required libraries are added, an object must be implemented for each module or component that requires it. Therefore, to use the MP3 playback module, the object mySoftwareSerial from the library <SoftwareSerial be implemented. h>to tell the microcontroller the digital pins to use for the module's serial communication. In this project, digital pin 10 of microcontroller is used to receive data from mini MP3 player module and digital pin 11 is used to send data to mini MP3 player module. To use the module's control methods and commands, such as: B. adjust the volume or start playing an MP3 file, the object myDFPlayer from the library <DFRobotDFPlayerMini.h> created.
SoftwareSerial mySoftwareSerial(10, 11);
DFRobotDFPlayerMini myDFPlayer;
In order to be able to use the servo motors, an object from the library must be created for each servo motor servo.h be instantiated. As you can see, the names of the objects for using each servo motor are very descriptive and easy to understand. In addition, the variable pos defined. This variable is of type int is used in the loops that are defined for the movement of the rocking chair servo motor.
Servo servo_chair;
Servo servo_skeleton;
int pos;
The following four lines define the variables used with the SR-HC04 ultrasonic sensor. The first two are the variables with the names of the pins, trigPin (signal transmitter) and echoPin (signal receiver) of the ultrasonic sensor, and as a value they contain the numbers of the ports of the microcontroller to which they are connected, namely to pins 6 and 5. In the variable ultrasonic_time_measurement The value of the time required for the sensor to detect the signal reflected from a person after it has been emitted is stored in the variable distance The value of the distance is saved, which is calculated based on the detected time.
int trigPin = 6;
int echoPin = 5;
long ultrasonic_time_measurement;
long distance;
The last variable to be created is the variable led_eyes with the value 7. This variable is used to tell the microcontroller that the red LEDs of the skeleton's eyes are connected to its digital port.
int led_eyes = 7;
After the libraries have been implemented, the objects of the modules have been created and the necessary variables have been created, the initial configuration of the modules and components of the project must be defined. This is done in the method set up(). First of all, in this method, the MP3 module is initialized and its communication with the microcontroller is established mySoftwareSerial. begin(9600), where 9600 is the data transfer speed in baud. We also initialize communication with the Serial Monitor via Serial.begin (115200) at a speed of 115200 baud (the speed must be selected at the bottom right of the Serial Monitor when the console is opened) to display the MP3 module initialization status or error messages.
mySoftwareSerial.begin(9600);
Serial.begin(115200);
The next thing to check in the code is the initialization of the MP3 module. This is done using a conditional statement if used. In the instruction if The code inside the curly braces will be executed if the condition of its parameter is true. In this case checks whether the MP3 module has not been initialized for some reason. The negated initialization was with the symbol ! written. This symbol is used as a negation method so that if the module is not initialized, the condition is true and the code inside the curly brackets is executed and the serial console reports to check the connections and microSD card insertion. If the MP3 playback module is initialized correctly, the condition is not met and the code described above will not be executed. The method set up () continued to run via the serial console with the line Serial.println(F("Correct DFPlayer initialization.")) to report that the MP3 playback module has been initialized correctly.
if (!myDFPlayer.begin(mySoftwareSerial)) {
Serial.println(F("Error initializing mp3 module:"));
Serial.println(F("1. Please check the connections!"));
Serial.println(F("2. Please insert the microSD memory!"));
while(true){
delay(0);
}
}
Serial.println(F("Correct DFPlayer initialization."));
For the initial configuration of the servo motors, the port of the microcontroller to which the signal line of the servo motor is connected must first be connected servo.attach can be defined, as well as the value of the position of the servo motor in degrees in the initial state servo. write in case the microcontroller is powered on or reset. The servo motor of the rocking chair is stated to be with servo_chair connected to port 9 of the microcontroller. attach(9) and the starting position is 90 degrees, which with servo_chair is specified. write(90). For the servo motor of the skeleton, the connector of the microcontroller it was connected to is 8, what with the line servo_skeleton is specified. attach(8) and the starting position of the skeleton is sitting. For this position the servo motor must be set to 90 degrees, which means servo_skeleton.write(90) is specified.
servo_chair.attach(9);
servo_chair.write(90);
servo_skeleton.attach(8);
servo_skeleton.write(90);
For the initial configuration of the red LEDs of the skeleton eyes, the port of the microcontroller to which the LEDs are connected must first be configured as an output port so that it supplies voltage when the status changes. This is done with the line of code pinMode (led_eyes, OUTPUT). When the skeleton is sitting, its eyes must not light up, so this port must not supply any voltage. This is done by reducing the signal level it delivers at that time to a low level, i.e. h. is set to 0 VDC. The line that sets its output to a low level is digitalWrite (led_eyes, LOW) .
pinMode (led_eyes, OUTPUT);
digitalWrite (led_eyes, LOW);
In the last two lines of the method set up() The ports of the microcontroller to which the pins of the ultrasonic sensor are connected are configured. The port of the microcontroller to which the pin TRIG of the ultrasound module is connected pinMode (trigPin, OUTPUT) configured as an output because the microcontroller uses this pin to control the emission of the ultrasonic signal. The port of the microcontroller to which the pin ECHO of the ultrasound module is connected pinMode (echo_Pin, INPUT) configured because the microcontroller uses this port to receive the signal previously sent by the ultrasound module, which is reflected back by people or objects.
pinMode (trigPin, OUTPUT);
pinMode (echoPin, INPUT);
The initial conditions of all modules and components of the project have already been configured, now all that remains is the method loop() be programmed so that the entire system carries out the desired movements. The first line is a call to the method measure_distance(). In this method, the ultrasonic sensor is controlled and the calculations are performed to find the distance between an object or person and the ultrasonic sensor.
measure_distance();
When this method is called, ultrasonic signals are sent and the calculation is made based on the time it took for the signal to bounce back. To calculate the distance between an object and the sensor, all you need to do is measure the time between sending and receiving a signal. The sequence is as follows: First, the pin trigPin of the sensor is set to the “low” state for 5 milliseconds. After this time, the state of the same pin trigPin set to “high” for 10 milliseconds so that the sensor sends out the signal. After this time has elapsed, the state of this pin is set to “low” again to stop sending signals.
Once this is done, the function calculates pulseIn(echoPin, HIGH) the time since the signal was sent by the pin trigPin has passed until the pin echoPin of the sensor receives the reflected signal. Now we know the time in microseconds that the signal took from transmission to reception. This information is very important and is included in the variable ultrasonic_time_measurement saved. To find the distance, all you have to do is perform a mathematical operation. Since the speed of sound in air at 20 degrees Celsius is 343 m/s, this speed must be converted into cm/µs. The value is calculated using the following formula:

Formula 1 – Conversion from m/s to cm/µs
On the other hand, the time measured by the sensor is the time it takes for the signal to travel to the object and return, so the actual time required to reach the object or person is half the measured time. It should be noted that these are microseconds. So if the time required and the speed of sound in centimeters per microsecond are known, the following formula can be used to calculate the distance.

Formula 2 – Distance CalculationThe result is the distance to the object in centimeters. This distance is in the variable distance saved to them in conditional blocks if to use. These blocks are executed depending on the value of the variable. This distance is also determined by the Serial Monitor displayed when the microcontroller is connected to the Arduino IDE.
void measure_distance() {
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
ultrasonic_time_measurement = pulseIn(echoPin, HIGH);
distance = (ultrasonic_time_measurement/2)*0.0343;
Serial.print(distance);
Serial.print(" cm");
Serial.println();
}
Once the distance to the object has been calculated, you return to the line of code that responded to the method call measure_distance() follows.
If you look at the sketch you will notice that two simple conditional blocks if have been programmed. These two blocks carry out the different actions that the components perform depending on the value that the person detected by the sensor has and that in the variable distance is stored. If the person is at least 40 cm away, the skeleton remains seated, the eye LEDs are turned off and the rocking chair moves. However, if the distance to the person is less than 40 cm, the rocking chair stops, the LEDs of the eyes light up and the skeleton gets up from the chair. The following explains the execution of the conditional blocks.
The first condition if is executed if the variable distance has a value of at least 40 centimeters. The following functions are carried out: First, the volume of the sound playback is adjusted myDFPlayer.volume(15) set to a value of 15 out of 30, then the file with the name 001.mp3 is included myDFPlayer. play(001) played. This file must be stored on the microSD card inserted into the MP3 playback module and reproduces the sound of creaking wood. The line digitalWrite (led_eyes, LOW) of the code sets the pin of the microcontroller to which the LEDs of the skeleton's eyes are connected to a low level (without voltage), which turns them off and causes the skeleton's servo motor to move to a 90 degree position and remain seated.
Two loops were used to move the rocking chair for programmed with counters. The first loop for starts with a servo motor position value of 60 degrees and must position itself up to 115 degrees, increasing by 1 degree every 18 microseconds. This way the movement is continuous. The second loop for forces the servo motor to perform the reverse movement: from 115 degrees it must be lowered to 60 degrees, decreasing 1 degree every 18 microseconds.
if (distance >= 40) {
myDFPlayer.volume(15);
myDFPlayer.play(002);
digitalWrite (led_eyes, LOW);
servo_skeleton.write(90);
for (pos = 60; pos <= 115; pos += 1) {
servo_chair.write(pos);
delay(18);
}
for (pos = 115; pos >= 60; pos -= 1) {
servo_chair.write(pos);
delay(18);
}
for (pos = 115; pos >= 60; pos -= 1) {
servo_chair.write(pos);
delay(18);
}
}
The second condition if is executed if the variable distance has a value of less than 40 cm. In this case, the following functions are performed: First, the position of the servo motor of the rocking chair is set to 90 degrees, which keeps it in the center, and the function myDFPlayer. pause()to pause the currently playing audio file (remember that was the sound of creaking wood with 001.mp3), and there will be a 1.5 second pause with the line delay(1500) inserted.
After the pause, the LEDs of the skeleton's eyes light up due to the execution of the line digitalWrite (led_eyes, HIGH) is called because this line causes the port of the microcontroller to which the LEDs of the skeleton's eyes are connected to go high and now have 5 VDC. Another pause follows, but this time of 2 seconds.
Now all that's missing is the movement of the skeleton and the sound of laughter. First, the playback of the sound is programmed because the microcontroller needs to prepare the audio file for playback, which results in a slight delay in playback. The volume of the sound playback is also used myDFPlayer. volume(15) and with myDFPlayer. play(002) The file named 002.mp3 will be played to reproduce a spooky laugh. This file must also be saved on the microSD card inserted into the MP3 playback module. With the line of code servo_skeleton. write(70) the skeleton will get up from the chair while the audio file is playing. With delay(5000) There will be a pause of 5 seconds so that the file can be played completely.
if (distance < 40) {
servo_chair.write(90);
myDFPlayer.pause();
delay(1000);
digitalWrite (led_eyes, HIGH);
delay(2000);
myDFPlayer.volume(15);
myDFPlayer.play(001);
servo_skeleton.write(70);
delay(5000);
}
Vid 1 – Project Operation
We hope you enjoy this year's Halloween project and wish you a spooky and entertaining evening. Thank you.
1 comment
Michael
Absolut cooles Projekt und sehr schön realisiert.
Da macht die Bastlei wirklich Spaß.