Arduino stops working after couple of days

Hello all,

I’m facing a strange issue with my Arduino UNO board and I can’t figure out the root cause.
I have wireless RF (433mhz) transmitter connected to the Arduino board which is sending out values obtained by analogRead() function from A0 pin. Arduino is also blinking with it’s onboard led, so that it is visible that the program is running.
Everything is working completely fine and I can see the correct values on the receiver side. The problem is that the Arduino with transmitter stops working after some time (usually after couple of days). It basically stops sending values and the onboard diode just stops blinking (it does not emitting the light at all). The only fix is to push the reset button on the board or pull out/insert the power cable.

Here is the code:

#include <RH_ASK.h>
#include <SPI.h>

RH_ASK driver;

void setup()
{
  pinMode(LED_BUILTIN, OUTPUT);
  driver.init();
}

void loop()
{
  digitalWrite(LED_BUILTIN, HIGH);
  delay(1000);
  uint16_t data = analogRead(A0);
  driver.send((uint8_t *)&data, sizeof(data));
  digitalWrite(LED_BUILTIN, LOW);
  delay(1000);
}

What do you think might be an issue here?

I have heard of that issue before. I think that to fix it some people make it auto reset itself every few days.

My guess would be a ‘memory leak’, maybe in the driver.send() function. If it allocates any memory and does not free it, it will eventually fill all of memory and the sketch will crash. There are examples of how to display remaining free memory. If you send the value to Serial Monitor you could see if the number was going down.

@cl3arsky, your post was moved to a more appropriate section of the forum.

Could You grab pen and paper and make a drawing of the wiring of all power, +5, +3.3 etc?

Try adding a freeMemory method to your sketch and print it out each loop to see what is happening to the heap memory

#ifdef __arm__
// should use uinstd.h to define sbrk but Due causes a conflict
extern "C" char* sbrk(int incr);
#else  // __ARM__
extern char *__brkval;
#endif  // __arm__

int freeMemory() {
  char top;
#ifdef __arm__
  return &top - reinterpret_cast<char*>(sbrk(0));
#elif defined(CORE_TEENSY) || (ARDUINO > 103 && ARDUINO != 151)
  return &top - __brkval;
#else  // __arm__
  return __brkval ? &top - __brkval : &top - __malloc_heap_start;
#endif  // __arm__
}

Then in the loop() add

 Serial.print(" FreeMemory:"); Serial.println(freeMemory());

Hello @drmpf @johnwasser
Thanks for the answers. I added freeMemory method to my sketch and I see this output:

FreeMemory:2265
FreeMemory:2265
FreeMemory:2265
FreeMemory:2265
FreeMemory:2265
FreeMemory:2265
FreeMemory:2265

So the number is still the same every iteration. Does it mean, there is no memory leak?

#include <RH_ASK.h>
#include <SPI.h>

#ifdef __arm__
// should use uinstd.h to define sbrk but Due causes a conflict
extern "C" char* sbrk(int incr);
#else  // __ARM__
extern char *__brkval;
#endif  // __arm__

int freeMemory() {
  char top;
#ifdef __arm__
  return &top - reinterpret_cast<char*>(sbrk(0));
#elif defined(CORE_TEENSY) || (ARDUINO > 103 && ARDUINO != 151)
  return &top - __brkval;
#else  // __arm__
  return __brkval ? &top - __brkval : &top - __malloc_heap_start;
#endif  // __arm__
}

RH_ASK driver;

void setup()
{
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(9600);
  driver.init();
}

void loop()
{
  digitalWrite(LED_BUILTIN, HIGH);
  delay(1000);
  uint16_t data = analogRead(A0);
  driver.send((uint8_t *)&data, sizeof(data));
  digitalWrite(LED_BUILTIN, LOW);
  delay(1000);
  Serial.print(" FreeMemory:"); Serial.println(freeMemory());
}

Maybe. You should run that version for a day to be sure.

Also try adding 47uF to 100uF capacitor directly across the SD Vcc/GND pins, the SD draws a lot of current is spikes. Also check there are pullup resistors on the signal pins.
Once the SD locks up you have to power cycle to restore it.
This is what I used to solve problems in one of my projects
sdpullups

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