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)
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?
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.)
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?
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;
}
}
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!
After reading info on the Arduino website about analog and digital, I thought it was analog. Maybe I don’t understand it properly.
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.
I have not, it was late and did not feel like soldiering.
Light effects. I have edited FastLED code before, so I know some things about it.
Everything in “MyStuff” I wrote myself. The rest is from FastLED and DFPlayer.
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.