5V on/off control DFPlayer

Hi,

I have a toy fridge. When you open the door audio plays. I want to play custom sounds using a DFRobot.

I have 5V and GND to supply power to DFRobot and Arduino. Also there is a third wire that provides +/- 5V as long as the door open. When the door closes the voltage drops to 0V.

Is there a way to use an Arduino and this ‘door open’ 5V to send a next track signal to the DFRobot?

(As long as the door stays open it should only play 1 track. If you close the door it’s okay if the track continues until it’s finished)

Any help is much appreciated. Thanks!

Regards,

Mark

Do you mean the the voltage varies between -5V and +5V?
Is it possible that it is the voltage from the fridge speaker?

Hi Jim,

Thanks for replying. It’s either 4,73V door open or 0V door closed.

(I think the current board just plays the preprogrammed sounds in order when it gets power. The sounds also cuts off when the door is closed.)

You can connect the third wire to any Arduino pin through a 1K resistor but you will also need to connect the Arduino GND to the GND of the circuit that controls the voltage on the thire wire.
Is the fridge powered by a battery or maybe a 5V plugin adaptor?

It’s connected to an adapter. GND is available (It has to be the same as for permanent 5V. Since there is no other option available in this part.)

I have reasonable soldiering skills and I have plenty of resistors, so I can do that.

However I’m hoping to get help with the code for the controlling the DFRobot :slight_smile:

There are plenty of people on the forum that are experts with the DFplayer, I'm not one of them.
Wait a little and I'm sure someone will come along.

Change your title to DFPlayer instead of DFRobot

If you to go the DF Robot Player wiki on their site, you'll see how to control it without even needing an arduino.

Here's an example I made: https://youtube.com/shorts/BVaXQ3jNslQ?feature=share

Hi, thanks for your reply. I’ve looked at it, but maybe I’m just not clever enough to figure out how to control it.

If I power the DFPlayer using the 5V from the door, will it be possible to play the next track or will it just play the first track over and over? Also it will lose power when I close the door and stop the audio.

If somehow I were to wire the door to I/O 1 in I/O mode for next track. It would probably count as a long press for volume control.

Any help solving this would be greatly appreciated. Thanks!

(Edit: I don’t want to make any modifications to the outside of the fridge. The is no option for mechanical switches.)

Yes, that should be a simple Arduino project, although hardly needs an MCU if all you want is as you described, with no likelihood of further changes.

What type of Arduino board and what code do you have so far??

Thanks for sharing.

Hi Terry,

Thank you for your reply. I have an Arduino Nano board. I’m sorry to say I don’t have any code. I’m a bit of a noob. I can make small changes to existing code (like changing the color of LED’s), but that’s about it. I don’t know where to start.

Edit: Maybe in the future I’ll want to be able to control some LED’s. ?With a counter to keep track of how many times the door has been opened. So I can link light effects to a certain audio track? But first I would like to get audio working.

OK, understood. We like to avoid simply writing code from scratch. It's not good for learning, either by the OP or others browsing. So I suggest you get to the stage where you have your Uno up and running and, say, lighting an LED (could be just its built-in LED on pin 13), whenever the door is open, and switching it off when the door is closed. Show us your code for that and a schematic of the wiring. Hand-drawn is OK. Obviously you will need a permanent 5V supply.

I take it you have the DFR Player module and know how to wire it up? But you don't want to use the I/O mode (no Uno) ?

The DFPlayer is on the way. I understand the basics. Wiring it up without an uno is an option, but don’t see how. I’ll post again soon to show my progress.

By the way I could light up a led with just a led and a resistor, but I guess that would be cheating? :crazy_face:

Most of what you need to know is here, including example code.

I did my best writing a code. I hope I didn't make stupid mistakes since I'm not very experienced. Anyway, this is what I came up with. I think there may be some stuff from DFPlayer that can be removed. I hope I can keep the code clean and simple.

//FastLED stuff
#include "FastLED.h"
#define NUM_LEDS 2
#define PIN 3
RGB leds[NUM_LEDS];

//DFPlayer stuff
#include "Arduino.h"
#include "DFRobotDFPlayerMini.h"

#if (defined(ARDUINO_AVR_UNO) || defined(ESP8266))   // Using a soft serial port
#include <SoftwareSerial.h>
SoftwareSerial softSerial(/*rx =*/10, /*tx =*/11);
#define FPSerial softSerial
#else
#define FPSerial Serial1
#endif

DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);

//My stuff
int DoorPin = A7;
int Voltage = 0;
int DoorCount = 0;
int DoorReset = 2;
int VoltageTrigger = 0;
int PlayOnce = 0;
int DoorOpen = 0;


void setup() {
//FastLed stuff
FastLED.addLeds<WS2812B, PIN, RGB>(leds, NUM_LEDS);
 
//DFPlayer stuff
#if (defined ESP32)
  FPSerial.begin(9600, SERIAL_8N1, /*rx =*/D3, /*tx =*/D2);
#else
  FPSerial.begin(9600);
#endif

  Serial.begin(115200);

  Serial.println();
  Serial.println(F("DFRobot DFPlayer Mini Demo"));
  Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));

  if (!myDFPlayer.begin(FPSerial, /*isACK = */true, /*doReset = */true)) {  //Use serial to communicate with mp3.
    Serial.println(F("Unable to begin:"));
    Serial.println(F("1.Please recheck the connection!"));
    Serial.println(F("2.Please insert the SD card!"));
    while(true){
      delay(0); // Code to compatible with ESP8266 watch dog.
    }
  }
  Serial.println(F("DFPlayer Mini online."));

  myDFPlayer.volume(10);  //Set volume value. From 0 to 30
 // myDFPlayer.play(1);  //Play the first mp3 // I don't think I want this...

//My stuff
  pinMode(DoorPin, INPUT);
}

void loop() {
  Voltage = analogRead(DoorPin);
    if (Voltage != VoltageTrigger && DoorOpen == 0) {
      DoorCount++;
      DoorOpen = 1;
      }
    if (Voltage != VoltageTrigger && PlayOnce == 0) {
      PlayOnce = 1;
      }
    if (DoorCount == DoorReset) {
      DoorCount = 0;
      }
    if (Voltage == VoltageTrigger) {
      DoorOpen = 0;
    }

// Audio & LED
    if (DoorCount == 0 && DoorOpen == 1 && PlayOnce == 1) {
  myDFPlayer.playFolder(1, 1);
  leds[0] = RGB::Red;
  PlayOnce = 0;
  }

    if (DoorCount == 1 && DoorOpen == 1 && PlayOnce == 1) {
  myDFPlayer.playFolder(1, 2);
  leds[0] = RGB::Green;
  PlayOnce = 0;
  }
}

Reading your post late tonight on iPhone. I’ll study properly tomorrow, but some hasty comments:

  1. Why treating voltage as analog? I understood it was either 5V or 0V, i.e digital?
  2. Logic seems surprisingly complicated!
  3. I assume you have not yet compiled, uploaded and run this yet?
  4. Why complicate at this stage by using an LED striplight, rather than a simple LED as I suggested?
  5. Is the code yours or if not what was the source?
1 Like

That is just HOW you gain experience! Write a few lines of code and compile and test. Add more lines and compile and test. Repeat and fix the errors and pretty soon you will have a completed program and have experienced learning at the same time!

1 Like

Hi Terry,

  1. After reading info on the Arduino website about analog and digital, I thought it was analog. Maybe I don’t understand it properly.
  2. Maybe it is (?)… I was thinking about what would happen if you keep the door open and 5V stays on. It would need to play only once (So check for door being held open, the audio being played and the door being closed). Also decided to add a counter to keep track of the audio files, so I combine with light effects.
  3. I have not, it was late and did not feel like soldiering.
  4. Light effects. I have edited FastLED code before, so I know some things about it.
  5. Everything in “MyStuff” I wrote myself. The rest is from FastLED and DFPlayer.

Thanks for helping!

It will play the first track over and over, because if it loses power it will forget which track was played last.

So you cannot power the DFplayer with this 5V wire. You need to give it a more permanent power supply and use the 5V wire only as a signal. I also think it may be possible without an Arduino.

1 Like

Yes, I know now. We have 5V permanent. 5V door goes to a input pin from Arduino only.

Also chose to go with Arduino for more functions for controlling leds.