Runs fine connected to PC, resets standalone

hi, beginner here and in a hurry... have this project with pir sensors that trigger an mp3 dfplyer that makes a statue 'talk'

code is pretty simple, so is the hardware, can share of course, got one working on a protoboard, both on pc and standalone... but the one I soldered when running standalone starts a loop, like it runs the setup function again

I had to desolder and soldered again the dfplayer, maybe there's some problem there? it's not too clean... tried 7.5v on vin and 5v on usb, neither worked

I need to have 5 of these working, those are nano clones, thanks for reading and for any advice..!

Welcome to the forum

Please share the details of your project including code, details of the hardware used and a schematic. A picture of a hand drawn circuit is good enough

sure, the arduinos are nano clones, some of them worked fine, for other group had to upload code as 'Duemilanove' or it would fail... but again, it seems to work when connected to pc

#include <DFPlayerMini_Fast.h>
#if !defined(UBRR1H)
#include "SoftwareSerial.h"
SoftwareSerial mySerial(10, 11); //RX, TX
#endif

DFPlayerMini_Fast myMP3;

int pirPin = 3;              //PIR
int ledPin = 13;             //led
int volumen = 25;            //rango de 0 a 30

// SETUP ////////

void setup() {
  Serial.begin(9600);
  pinMode(pirPin, INPUT);
  pinMode(ledPin, OUTPUT);

  // resetear 505 ??????????
  digitalWrite(pirPin, LOW);

#if !defined(UBRR1H)
  mySerial.begin(9600);
  myMP3.begin(mySerial);
#else
  Serial.begin(9600);
  myMP3.begin(Serial1);
#endif

  // ajustar volumen
  //  Serial.println("");
  //  Serial.println("Ajustar volumen");
  myMP3.volume(volumen);

  // calibrado PIR por 30 segundos / enciende LED 10 veces
  //  Serial.println("calibrado PIR 30 segundos");
  for (int i = 10; i > 0; i--) {
    //    Serial.println( i );
    digitalWrite(ledPin, HIGH);
    delay(500);
    digitalWrite(ledPin, LOW);
    delay(2500);
  }

  //  Serial.println("listo...");
  // resetear 505 ??????????
  digitalWrite(pirPin, LOW);

}

// LOOP ////////

void loop() {

  // movimiento detectado ////////
  if (digitalRead(pirPin) == HIGH) {

    // encender led
    digitalWrite(ledPin, HIGH);
    //    Serial.println("---------- movimiento..!");

    // reproducir SIGUIENTE audio
    delay(500);
    myMP3.playNext();
    delay(2500);

    // mientras suena el audio: función isPlaying()
    while (myMP3.isPlaying()) {
      delay(5000);
    }

    // apagar led
    digitalWrite(ledPin, LOW);

  }
}

here's an image of setup: https://ibb.co/JtsZD16

thanks for looking at it

What is the purpose of this? If it's to prevent retriggers on the PIR you can do that in hardware on the PIR itself I think. Seems to me the use of all those delays in your code could cause some issues.

hi hallowed, I simplified the code here, removed comments and a pote check -not using it now-

and was using millis and while instead of delays... it makes a little click when checking if audio is done, so I check every 5 seconds, that's the delay you point at... audio files are over a minute

also I got one on a protobard that works ok


edit: I wonder, maybe something to do with serial communication code? I cleared all print lines and comments I think... what could cause the reseting when standalone? maybe I'll solder again all ground connections, what cable do you use for this, 0.25mm is fine? just trying to learn a bit

Anything, really. I don't personally like anything thinner than 22AWG due to breakage but you might be fine. Test the connections with your multimeter. I still don't see the point of that delay in the while() loop. It's going to continually check if the condition is true anyway until it isn't then exit the loop. Adding the delay just pauses everything the Arduino is doing for, in this case, 5 seconds, repeatedly.

ok, thanks hallowed

seems like the function generates a little click noise, it's audible if I do the checking all time... there's a busy pin I could use but would need to wire it... also don't need to be precise with timings, can wait some extra seconds

edit: btw I was using: while (millis() < tiempo + 5000) {} instead of the delay()

Have you just tried playing a file or two in a test sketch to narrow the problem down?

well, it's working now..! wonder how stable it will be then, I just reuploded the same code I think, what's strange with these clones is that you need to declare them as Duemilanove

thanks for your time anyway!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.