Muhammad_Munir
Published © GPL3+

Arduino Play audio (Good morning and Good night)

Arduino Play audio (Good morning and Good night)

BeginnerFull instructions provided176
Arduino Play audio (Good morning and Good night)

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Df Player Mini
×1
SD Card
×1
LDR
×1
1k Resistor
×1
10k Resistor
×1
Jumper Wires
×1
3 Watt Speaker
×1
Breadboard (generic)
Breadboard (generic)
×1

Story

Read more

Code

Code

Arduino
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"

// Use pins 2 and 3 to communicate with DFPlayer Mini
static const uint8_t PIN_MP3_TX = 2; // Connects to module's RX
static const uint8_t PIN_MP3_RX = 3; // Connects to module's TX
SoftwareSerial softwareSerial(PIN_MP3_RX, PIN_MP3_TX);

const int LDR = A0;
int input_val = 0;
int x = 0;
int y = 0;

// Create the Player object
DFRobotDFPlayerMini player;

void setup() {


  // Init USB serial port for debugging
  Serial.begin(9600);
  // Init serial port for DFPlayer Mini
  softwareSerial.begin(9600);

  // Start communication with DFPlayer Mini
  if (player.begin(softwareSerial)) {
    Serial.println("OK");

    // Set volume to maximum (0 to 30).
    player.volume(30);

  } else {
    Serial.println("Connecting to DFPlayer Mini failed!");
  }
}

void loop() {
  input_val = analogRead(LDR);

  delay(1000);

  if ((input_val < 100) && (x == 0))
  {
    player.play(2);
    x = 1;
    y = 0;
    Serial.print("Good night ");
  }

  else if ((input_val > 100) && (y == 0))
  {
    player.play(1);
    y = 1;
    x = 0;
    Serial.print("Good morning ");
  }


}

Credits

Muhammad_Munir
79 projects • 56 followers
I am Arduino programmer, also expertise in ESP32 and 8266 wifi modules.

Comments