Connecting a df player with an ultrasonic sensor

I am trying to connect a df player with an ultrasonic sensor so that once a hand is put near, a song plays from the df player. I've already connected the components properly and put the micro sd card(16GB) with the music in the df player.

I am using an Arduino UNO.

I used the files from this website:

#include <SoftwareSerial.h>
#include <DFPlayer_Mini_Mp3.h>
//√ ¿Ω∆ƒ ºæº≠ «…º≥¡§
int trigPin = 9;
int echoPin = 8;
 
void setup () {
    Serial.begin (9600);
    mp3_set_serial (Serial);     // DFPlayer-mini mp3 module Ω√∏ÆæÛ ºº∆√
    delay(1);                     // ∫º∑˝¿ª Setup «œ±‚ ¿ß«— delay
    mp3_set_volume (30);          // ∫º∑˝ 0~30
 
    //√ ¿Ω∆ƒ ºæº≠ «…º≥¡§
    pinMode(trigPin, OUTPUT);
    pinMode(echoPin, INPUT);
}
void loop () {
  float duration, distance;
  digitalWrite(trigPin, HIGH);
  delay(10);
  digitalWrite(trigPin, LOW);
 
  // ¿Âæ÷π∞∞˙¿« ∞≈∏Æ∞˪Í
  duration = pulseIn(echoPin, HIGH);
  distance = ((float)(340 * duration) / 10000) / 2;
  delay(100);
  if(distance < 50) //¿Âæ÷π∞¿Ã 50cm ¿Ã≥ª¿œ∂ß
  {
    mp3_play(99); //æ»≥Á«œººø‰... mp3 (0099.mp3) ∆ƒ¿œ «√∑π¿Ã
    delay(7000);
  }
}

Then there is another folder with a bunch of codes; I attached it as well.

I am not sure of what I should do after pasting this code. I simply tried adding a zip file with the files attached below, but it shows this error message:

Arduino: 1.8.13 (Mac OS X), Board: "Arduino Uno"

Sketch uses 3342 bytes (10%) of program storage space. Maximum is 32256 bytes.
Global variables use 200 bytes (9%) of dynamic memory, leaving 1848 bytes for local variables. Maximum is 2048 bytes.
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00
Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.
java.util.zip.ZipException: error in opening zip file
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.(ZipFile.java:225)
at java.util.zip.ZipFile.(ZipFile.java:155)
at java.util.zip.ZipFile.(ZipFile.java:169)
at processing.app.tools.ZipDeflater.(ZipDeflater.java:26)
at processing.app.Base.handleAddLibrary(Base.java:2413)
at processing.app.Base$6.actionPerformed(Base.java:1124)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.AbstractButton.doClick(AbstractButton.java:376)
at com.apple.laf.ScreenMenuItem.actionPerformed(ScreenMenuItem.java:125)
at java.awt.MenuItem.processActionEvent(MenuItem.java:669)
at java.awt.MenuItem.processEvent(MenuItem.java:628)
at java.awt.MenuComponent.dispatchEventImpl(MenuComponent.java:357)
at java.awt.MenuComponent.dispatchEvent(MenuComponent.java:345)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:763)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:84)
at java.awt.EventQueue$4.run(EventQueue.java:733)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:730)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
error in opening zip file

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Please help me :cry:

DFPlayer_Mini_Mp3.cpp (5.66 KB)

DFPlayer_Mini_Mp3.h (4.86 KB)

keywords.txt (1.05 KB)

license.txt (7.47 KB)

  digitalWrite(trigPin, HIGH);
  delay(10);
  digitalWrite(trigPin, LOW);

The delay is way too long. Remove it or change it to something more reasonable, like delayMicroseconds(10);

Try disconnecting pins 0 and 1 from the MP3 player during loading.

Better still, as suggested by the #include, use SoftwareSerial to control the MP3 player, and leave pins 0 and 1 for what they do best.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.