Halloween trick or treat automata with Voice Recognition module

This time I didn’t miss the deadline for unveiling a Halloween project.  In this case, voice recognition, dfplayer mini and a servo motor are used to create a trick or treat automata.


Gravity Voice Recognition Module



Gravity Voice Recognition module is a small device by DFRobot that can be used to add voice recognition to any Arduino, ESP and Raspberry Pi project. Some interesting features of this module are:


. It works off line

. It comes with pre-trained commands

. It can learn new commands 

. It can be easily trained 

. Once it has been trained, a simple I2C or UART connection will give you the IDs of the commands


What can you do with this module? You can add it to any interface instead of wiring buttons and coding bouncing. 





When the button is pressed the device will start listening for “trick or threat” voice command.

After this point, the device will ask new questions and it will wait for answers. Some music and servo movements will be added to increase the dramatic effect.





1 Arduino Nano
1 Voice recognition module
1 DfPlayer Mini
1 4ohm speaker
1 SG90 Servo
1 Led button

Animated figure


This figure was made with clay. There is a SG90 servo inside. The head is a separate part to ensure movement.


Speech, sounds and movement



For the speech mp3 I have used https://elevenlabs.io/ Then I used Audacity to lower the voice pitch.


The audio files should be placed into the microSD  


The code to play mp3 is:


void playSound(int myId){ 






Movement is easily obtained by sending angles to the servo motor.

void right(){



Teaching commands to the module


The voice recognition module should be trained for new commands, since Yes/No, Trick or treat, etc are not included by default.

Power up the module with 5v and say: “Hello robot” Then say “Learning command word” Now follow the instructions and repeat 3 times the following words: 






Trick or treat


They will get assigned IDs from 5 to 9 and we will use those IDs from the code.


Note: if you have uploaded the .ino code please consider that mute mode has been enabled. You can disable with:




Forcing wake up word


The Voice Recognition module, by default requires a wake up phrase like “Hello, robot” 

By giving that command through the code with 




The device will be at command mode with the front blue light turned on.




Connect DFPlayer Mini TX and RX to Arduino Nano pins 10 and 11. DFPlayer Mini GND and VCC to the external 5v Power.  DFPlayer Mini SPK+ and SPK- to Speaker pins.


Connect the servo motor signal to pin 12. Servo motor GND and VCC to external 5v Power


Connect Led Button to pin 7 and GND.


Connect Voice module to A4 and A5. GND and VCC to external 5v Power.

3d Parts



If you want to use the same 3d printed box I did use, download all 3d parts from https://cults3d.com/en/3d-model/game/halloween-voice-recognition-trick-or-treat and print with PLA



Other projects


Interested in other projects using DFRobot parts? 


Unihiker TR808 Drum Machine 

Yrigoyen ChatGPT reading news

mmWave radar alarm 


Follow me on Instagram 

All Rights