Integrating the PIR Sensor and DFPlayer
Now that everything is assembled, it’s time to upload the main code into the Arduino Nano. This code integrates the PIR sensor, servo motors, and the DFPlayer MP3 module. The idea is simple: when the PIR sensor detects motion, the servos will move to open the eyelids and make the eyes move while the DFPlayer plays a sound.
Key Components of the Code:
• The PIR sensor triggers when it detects motion.
• The DFPlayer plays a sound file stored on an SD card.
• The servos control the eye and eyelid movement.
DFPlayer Mini and Speaker Setup
The DFPlayer Mini is a simple, low-cost MP3 player that can play audio files stored on a microSD card. In this project, it will play a sound file when motion is detected by the PIR sensor.
• Connect the RX pin of the DFPlayer to Digital 11 and the TX pin to Digital 10 on the Arduino Nano.
• Attach a speaker to the SPK+ and SPK- pins of the DFPlayer for sound output.
PIR Motion Sensor Connection
• The PIR sensor will detect motion and trigger the servo movements and audio playback.
• Connect the PIR sensor’s output pin to Digital 7 of the Arduino Nano.
Use a 9V external power supply for the circuit to ensure stable performance. Once the wiring and coding are complete, it’s time to test your project.
• Upload the code to your Arduino Nano.
• Ensure the PIR sensor is placed in a location where it can easily detect motion.
• When the PIR sensor detects movement, the servos controlling the eyelids should open, and the DFPlayer should play the pre-loaded sound file.
• The servos will then make the eyes move in a coordinated sequence.
Code Overview: The main code utilizes the DFPlayer library to control audio playback while coordinating with the PIR sensor's output. When motion is detected, the code triggers the servos to move the eyes and simultaneously starts the audio file. This synchronization enhances the effect, making the animatronic eyes appear more lifelike and engaging. The code efficiently handles various scenarios, ensuring seamless transitions between eye movements and sound playback.
Note: The attached file “1.mp3” contains the sound “I see you” used in the project. Simply upload the audio file to the SD card (SD card format must be FAT32)