Project on a PCB doesn't work. Bad layout?

Hey guys :slight_smile: 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 :slight_smile: !

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 :slight_smile:

Show us a good schematic of your circuit.
Show us a good image of your ā€˜actual’ wiring.
Give links to components.

Edit
Some Pro Mini offerings have missing connections to header pins.

Check yours to confirm all header pins go where they should on the Atmega chip.

I am sorry... Here is a a sketch :

What do you mean by actual wiring?
components :
DFPlayer - plays MP3 files
The other components are "normal" resistors, buttons, diode and leds.

I soldered two Arduinos to it and it didn't work both times. I also checked before and all the pins are working fine. I highly suspect that the problem is on the driving of the MOSFET.

Having a quick look at your circuit, Where are the smoothing capacitors like 10Uf and 100n's for decoupling ?

I tried to connect a capacitor in parallel to the player on my breadboard but it made more problems then help so I removed it from the PCB. I tried now to connect a 1000µF in parallel to the DFPlayer and it's still not working...

Which side of the board is the metal tab of the mosfet? Looks like it should be towards the outside edge, not inboard side.

General comments:

No capacitors required. The pro mini provides what is required.

Of all the free pins to use, why did you select tx0, pin 1 for the potentiometer? Now there is no possibility of serial port.

Just comment on your GND traces. It is poor practice to have traces on the top connecting grounds that form loops like ā€œtopGNDā€ which was totally unnecessary. That will come back to bite you in many circuits with ac currents like switch mode power supplies.

By metal tab you mean the upper part right? if we say that the MOSFET looks like h, then the board looks like that :
BorderofTheBoard h rest of the board (resistors ets)
I hope I understood you currectle and I hope my answer is somehow understandable

I selected Tx pin because the only alternbative was pin 13 and I didn't want to use it because then I had to remove its led and after almost ruining an arduino by a mistake I try to de-solder only what I must ahahahah. I don't need a serial communication in my project so that's not really a problem.

What's the alternative for the ground trace from the top? what is the right way to do it?

Thank you for your help :slight_smile:

Something's weird.

Trace pin 11 of the Pro Mini: it goes to a 1K resistor, then to the cathode of the diode and from the anode to the RX pin of the DF player. Your hand-drawn schematic shows it going to the anode of the diode first, then the resistor and then to the DF player.

At the very least it looks like your diode footprint is backwards (which is probably blocking serial transmission from the Pro Mini to the DF player.) Try reversing the diode population and see if anything changes.

Your description of the mosfet is correct.

You could have eliminated the top trace by tying the two gnd connections to the bottom ground plane using the thermal isolation pads you used on the other gnd connections. That would have been a lower impedance than the skinny single trace on the top layer.

You can always use analog input pins A0 through A5 as digital I/O. On boards where A6 and A7 exist, they are analog input only.

Why does A1go to Vcc ?

Hi,
Can you post a couple of pictures of your assembled PCB please?

Did you breadboard your project and get it working before committing to a PCB?

What is the part number of the P-CH MOSFET?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

Blackfin

Trace pin 11 of the Pro Mini: it goes to a 1K resistor, then to the cathode of the diode and from the anode to the RX pin of the DF player. Your hand-drawn schematic shows it going to the anode of the diode first, then the resistor and then to the DF player.

Yeah, their order is different on the printed PCB and the sketch I drew. Does the order make any difference? if yeah, why? after all there's no load between them. My argument is that if I connect two resistors in series, say 1K and 330 Ohm, it doesn't matter which one is on top (if there's no load in parallel with one of them). Is it different in the case of a diode?

At the very least it looks like your diode footprint is backwards (which is probably blocking serial transmission from the Pro Mini to the DF player.) Try reversing the diode population and see if anything changes.

There is a communication between them, the buttons are working when I connect Vcc of the player to + with a wire (which skips the MOSFET).

hammy

Why does A1go to Vcc ?

To measure the voltage on the batteries and keep track on it.

TomGeorge

Did you breadboard your project and get it working before committing to a PCB?

Yes, I checked every pin and it worked pretty well

What is the part number of the P-CH MOSFET?

On the MOSFET itself? it says 1M20AA

I know the soldering looks bad, I am still learning it. Everything seems connected though, according to my eyes at least. I tried it on two different boards, on the second one I soldered only the important part. I also didn't cut the end of wires which makes it look messy, sorry for that.
I didn't solder the lights in the first board, just put them inside the holes. I also didn't soldered the battery. While powering it I connected it through wires and clips (and saw that it worked because the power led of the Arduino was on).
https://www.docdroid.net/kuAfQBu/pics-pdf

WattsThat

You could have eliminated the top trace by tying the two gnd connections to the bottom ground plane using the thermal isolation pads you used on the other gnd connections. That would have been a lower impedance than the skinny single trace on the top layer.

The TopGND hole is connected to the ground fill. So actually yeah, the red route is definitely superfluous. I didn't think of it while making the PCB.

You can always use analog input pins A0 through A5 as digital I/O. On boards where A6 and A7 exist, they are analog input only.

I didn't know that. I will use them in the future. Thank you for the info :slight_smile:

Thank you all so much, I appreciate your help a lot :slight_smile:

The order of diode-resistor or resistor-diode is not important. However, the orientation of the diode is important.

My point what the diode in your layout is not oriented the same as it is in your schematic.

I am sorry, I somehow totally misread your message. I connected it on the PCB exactly like I connected it on the breadboard. It worked there well and save me around 3mA. I made a mistake in the wiring I drew. It is connected as the PCB shows. Sorry for that.

I tried now to be sure and soldered a wire in parallel to the diode but it still didn't play when I pressed the button :frowning:

OK, so looking at the Pro Mini, pin 11 is "RXI" and is connected to PD0(RXD) of the '328.

You have that connected to the RX pin of the the DF Player which is also serial input.

So you have serial input connected to serial input.

As a test: De-populate the two 1K resistors and diode. Cross connect as shown with the green and violet lines:

If this works, you'll need to sort your diode out yourself.

Thank you so much :slight_smile: but I'm almost 100% sure that it's not the problem because I connected it just like that since I started to play with the player and it always worked. Also the wiring on the datasheets points for such a wiring

Please don’t host pictures on an external site. That site tried to push crap VPN software onto my iPad. Very bad :poop: behavior for a website.

So, I couldn’t see your photos.

What site? Imgur? If so, first I've heard of that.

Don't you communicate with the DF Player using Serial?

No need for that connection. Just use the "secret voltmeter" trick. Do remember to calibrate as the internal reference has a 10% tolerance.

You have nothing soldered to the Battery terminals. How are you powering this? I don't seen any other place for power to get onto the board.