Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Muhammad_Munir
Published © GPL3+

How to Play Different Audios Using a Keypad

How to Play Different Audios Using a Keypad

BeginnerFull instructions provided1 hour61
How to Play Different Audios Using a Keypad

Things used in this project

Hardware components

Arduino UNO
×1
Df player mini
×1
Keypad 4x3
×1
SD Card
×1
Jumper wires
×1
Speaker
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Diagram

Code

Code

Arduino
#include <Keypad.h>
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>

// Define keypad layout
const byte ROWS = 4; // Four rows
const byte COLS = 3; // Three columns
char keys[ROWS][COLS] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};


byte rowPins[ROWS] = {8, 7, 6, 5};    // Connect to the row pins of the keypad
byte colPins[COLS] = {4, 3, 2};       // Connect to the column pins of the keypad

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

SoftwareSerial mySerial(10, 11);        // RX, TX for DFPlayer Mini
DFRobotDFPlayerMini myDFPlayer;

void setup() {
  Serial.begin(9600);
  mySerial.begin(9600);                 // Set serial baud rate for DFPlayer Mini


  if (!myDFPlayer.begin(mySerial)) {    // Check if DFPlayer Mini is connected
    Serial.println("Unable to begin DFPlayer Mini.");
    while (true);
  }
  myDFPlayer.setTimeOut(500);
  myDFPlayer.volume(30);                // Set volume to 20 (0-30 range)
}

void loop() {
  char key = keypad.getKey(); // Read the key

  if (key) {
    Serial.print("Key Pressed: ");
    Serial.println(key);

    if (key == '1') {
      myDFPlayer.playFolder(1, 1);
    }
    else if (key == '2') {
      myDFPlayer.playFolder(1, 2);
    }
    else if (key == '3') {
      myDFPlayer.playFolder(1, 3);
    }
    else if (key == '4') {
      myDFPlayer.playFolder(1, 4);
    }
    else if (key == '5') {
      myDFPlayer.playFolder(1, 5);
    }
    else if (key == '6') {
      myDFPlayer.playFolder(1, 6);
    }
    else if (key == '7') {
      myDFPlayer.playFolder(1, 7);
    }
    else if (key == '8') {
      myDFPlayer.playFolder(1, 8);
    }
    else if (key == '9') {
      myDFPlayer.playFolder(1, 9);
    }

  }
}

Credits

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

Comments

Please log in or sign up to comment.