Hey guys
I just got my PCB and soldered it but unfortunately it doesn't work... The project contains a MOSFET which high side switch a DFPlayer. It seems to work when I kick start the DFPlayer by connecting it to + through a wire (and passing the MOSFET) so I suppose the problem is on the layout and specifically with the MOSFET. Can you please check if I did something bad here ? I will appreciate your help a lot. Thank you very much
!
The project is made out of two PCBs which are connected with each other through wires. The second PCB has the lights, buttons, volume etc and is working pretty well so I didn't add a picture of it. The holes for those wires are on the right side and on the top left (where it says poti). The diode is there to prevent phantom powering. As a MOSFET I am using the P-Channel NDP6020P which is a logic one. It worked when it was connected on a breadboard
The code is very long. I removed all the part with the light, volume etc. I also changed the code a bit to keep on consistency but generally speaking it's the same
#include <Battery.h>
#include <DFPlayerMini_Fast.h>
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "LowPower.h"
DFPlayerMini_Fast myDFPlayer;
const int wakeUpPin = 2;
const int transistorPin = 8 ;
SoftwareSerial mySoftwareSerial(10, 11); // RX, TX 11 Resistor
boolean sleeping = true ;
int randomNumber ;
//start
void playRandom (int randomNumber) {
myDFPlayer.playFolder(1, randomNumber); //Play file
green() ;
}
}
void goToSleep () {
sleeping = true ;
digitalWrite (transistorPin, HIGH);
attachInterrupt(0, wakeUp, LOW);
}
void wakeUp()
{
sleeping = false ;
}
void setup()
{
mySoftwareSerial.begin(9600);
myDFPlayer.begin (mySoftwareSerial) ;
pinMode(wakeUpPin, INPUT);
digitalWrite (wakeUpPin, HIGH) ;
pinMode (transistorPin, OUTPUT) ;
digitalWrite (transistorPin, HIGH);
}
void loop()
{
if (sleeping == true) {
attachInterrupt(0, wakeUp, LOW);
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
detachInterrupt(0);
}
// wake up & start
if (!digitalRead (wakeUpPin)) {
delay (50) ;
if (!digitalRead (wakeUpPin)) {
digitalWrite (transistorPin, LOW);
randomNumber = random (1, 3) ;
playRandom(randomNumber) ;
}
}
// the arduino will go to sleep after te file is ended. I removed it because it's long
if ( // if file ended ) {
goToSleep () ;
}
this is the full code :
#include <Battery.h>
#include <DFPlayerMini_Fast.h>
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "LowPower.h"
DFPlayerMini_Fast myDFPlayer;
const int poti = 1;
const int wakeUpPin = 2;
const int buttonStop = 3 ;
const int batteryLed = 4 ;
const int redLightPin = 5 ;
const int greenLightPin = 6;
const int blueLightPin = 7 ;
const int transistorPin = 8 ;
const int busy = 9 ;
SoftwareSerial mySoftwareSerial(10, 11); // RX, TX 11 Resistor
const int folderPin = 12 ;
const int volumePin = A0 ;
const int voltagePin = A1 ;
Battery battery(3600, 5100, voltagePin);
boolean sleeping = true ;
boolean countingDown = false ;
boolean fileStopped ;
boolean fileEnded ;
int randomNumber ;
boolean playShort ;
int numberFilesLongFolder ;
int numberFilesShortFolder ;
static unsigned long timer ;
float voltage ;
int volume ;
int volumeOld ;
//start
void playRandom (int folder, int randomNumber) {
myDFPlayer.playFolder(folder, randomNumber); //Play file
green() ;
}
//switch folder from short file -> long file or long -> short
boolean readShortLong () {
if (digitalRead (folderPin)) {
return true ;
}
else {
return false ;
}
}
void goToSleep () {
timer = millis () ;
sleeping = true ;
fileEnded = false ;
fileStopped = false ;
countingDown = false ;
digitalWrite (batteryLed, LOW);
digitalWrite (poti, LOW);
digitalWrite (transistorPin, HIGH);
attachInterrupt(0, wakeUp, LOW);
}
//lights
void green () {
digitalWrite (greenLightPin, HIGH);
delay (100) ;
digitalWrite (greenLightPin, LOW);
}
void yellow () {
analogWrite(greenLightPin, 30);
analogWrite(redLightPin, 255);
delay (100) ;
analogWrite (redLightPin, 0);
analogWrite (greenLightPin, 0);
}
void blue () {
digitalWrite (blueLightPin, HIGH);
delay (100) ;
digitalWrite (blueLightPin, LOW);
}
void red () {
digitalWrite (redLightPin, HIGH);
delay (100) ;
digitalWrite (redLightPin, LOW);
}
void wakeUp()
{
sleeping = false ;
}
void setup()
{
Serial.begin (4800 ) ;
myDFPlayer.begin (mySoftwareSerial) ;
pinMode(wakeUpPin, INPUT);
digitalWrite (wakeUpPin, HIGH) ;
pinMode (buttonStop, INPUT) ;
digitalWrite (buttonStop, HIGH);
pinMode (folderPin, INPUT) ;
digitalWrite (folderPin, HIGH);
pinMode (batteryLed, OUTPUT) ;
digitalWrite (batteryLed, LOW);
pinMode (poti, OUTPUT) ;
digitalWrite (poti, LOW);
pinMode (transistorPin, OUTPUT) ;
digitalWrite (transistorPin, HIGH);
pinMode (redLightPin, OUTPUT) ;
pinMode (greenLightPin, OUTPUT) ;
pinMode (blueLightPin, OUTPUT) ;
pinMode (busy, INPUT) ;
pinMode (volumePin, INPUT) ;
volume = map (analogRead (volumePin), 20, 1000, 0, 30) ;
myDFPlayer.volume (volume) ;
battery.begin(5000, 1.0, &sigmoidal);
}
void loop()
{
if (sleeping == true) {
attachInterrupt(0, wakeUp, LOW);
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
detachInterrupt(0);
}
// wake up & start
if (!digitalRead (wakeUpPin)) {
delay (50) ;
if (!digitalRead (wakeUpPin)) {
digitalWrite (transistorPin, LOW);
digitalWrite (poti, HIGH);
delay (50) ;
numberFilesLongFolder = myDFPlayer.numTracksInFolder(1) + 1 ;
numberFilesShortFolder = myDFPlayer.numTracksInFolder(2) + 1 ;
myDFPlayer.volume (map (analogRead (volumePin), 20, 1000, 30, 0)) ;
timerLed = 0 ;
if (readShortLong ()) {
randomNumber = random (1, numberFilesShortFolder ) ;
playRandom(2, randomNumber) ;
}
else {
randomNumber = random (1, numberFilesLongFolder ) ;
playRandom(1, randomNumber);
}
delay (200) ;
}
}
//Pause & continue
//Pause
if (!digitalRead(buttonStop) && !digitalRead (busy) ) {
delay (50) ;
if (!digitalRead(buttonStop) && !digitalRead (busy) ) {
myDFPlayer.pause();
fileStopped = true ;
countingDown = false ;
yellow () ;
delay (200) ;
}
}
//Continue
if (!digitalRead(buttonStop) && digitalRead (busy) ) {
delay (50) ;
if (!digitalRead(buttonStop) && digitalRead (busy) ) {
if (fileStopped) {
myDFPlayer.resume();
timer = millis () ;
fileStopped = false ;
green () ;
delay (200) ;
}
}
}
volumeOld = map (analogRead (volumePin), 20, 1000, 30, 0) ;
if (volumeOld != volume) {
volume = volumeOld ;
myDFPlayer.volume (volume) ;
}
if (battery.voltage () < 3000) {
digitalWrite (batteryLed, HIGH) ;
}
else {
digitalWrite (batteryLed, LOW) ;
}
//making the arduino go to sleep when the file ends / stopped for a while
if (digitalRead (busy) && !fileStopped) {
fileEnded = true ;
}
if (digitalRead (busy) && fileEnded ) {
if (!countingDown) {
timer = millis () ;
countingDown = true ;
}
}
if (digitalRead (busy) && fileStopped ) {
if (!countingDown) {
timer = millis () ;
countingDown = true ;
}
}
//go to sleep
if (fileStopped && millis () - timer > 180000) {
goToSleep () ;
}
else if (fileEnded && millis () - timer > 5000) {
goToSleep () ;
}
}
Thank you all so much ![]()


