ISN (International Social Networking Services - Interactive Apps and Websites)


All Our projects

MP3 Player (WTD020SD DFPlayer), Alarm and distance detector (HC-SR04 sensor) with Arduino


mp3 player - Alarm with Arduino Nano Schematic and source code


We can easily create an alarm or a MP3 player with Arduino Nano and some additional modules!
Objects used for this project:
1. mp3 player (WTD020SD or DFPlayer Mini)
2. distance detector (HC-SR04 sensor)
3. Arduino Nano
4. SD memory card
5. 9V battery
This project contains information necessary to mount an alarm, an mp3 player too simple, and remote sensing for around 4~5m.

 

Full source code:


#include <SoftwareSerial.h>
#include <SD.h>
#include <NewPing.h>


#define TRIGGER_PIN  12  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     11  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.

void setup () {
  Serial.begin(9600);
  pinMode(7,OUTPUT);
  mp3_set_serial (Serial);  //set Serial for DFPlayer-mini mp3 module 
  mp3_set_volume (15);
  //
  mp3_stop ();
}
void loop () {
  delay(50);                      // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  int distance = sonar.ping_cm(); // Send ping, get ping time in microseconds (uS).
  Serial.print("Ping: ");
  Serial.print(distance); // Convert ping time to distance in cm and print result (0 = outside set distance range)
  Serial.println("cm");
  if (distance < 35)
  {
    delay(distance*10);
    mp3_random_play ();
  }
   /*delay (1000);
  mp3_next();
 
   if(Serial.available()){
    Serial.println(Serial.read());
    switch(Serial.read()){
      case 'p': mp3_play (1); break;
      case 'n': mp3_next (); break;
      case 'b': mp3_prev (); break;
      case 's': mp3_get_state (); break;
      case 'v': mp3_get_volume(); break;
      default: break;
    }
    delay(500);
  }
  */
}
/*
   mp3_play ();   //start play
   mp3_play (5);  //play "mp3/0005.mp3"
   mp3_next ();   //play next 
   mp3_prev ();   //play previous
   mp3_set_volume (uint16_t volume);  //0~30
   mp3_set_EQ (); //0~5
   mp3_pause ();
   mp3_stop ();
   void mp3_get_state ();   //send get state command
   void mp3_get_volume (); 
   void mp3_get_u_sum (); 
   void mp3_get_tf_sum (); 
   void mp3_get_flash_sum (); 
   void mp3_get_tf_current (); 
   void mp3_get_u_current (); 
   void mp3_get_flash_current (); 
   void mp3_single_loop (boolean state);  //set single loop 
   void mp3_DAC (boolean state); 
   void mp3_random_play (); 
 */

 

By continuing to use this site, you agree to the use of cookies to personalize content and advertisements, to provide social media functionality, to analyze our traffic using Google services like Analytics and Adsense.

Google Adsense and its partners may use your data for advertising personalization and cookies may be used for personalized and non-personalized advertising. How does Google use my data?
Please use the following button to see the list of Google partners as well as all the details regarding cookies.
See detailsI Accept
These cookies are mandatory for the operation of isn-services.com, if you do not accept them please quit this site.
You have the right to refuse cookies and leave the site or to change the parameters.