I am having a problem with my Arduino freezing after a small amount of time. I'm using an RTC DS1307 breakout to keep track of the time and display the time on an LCD. It displays hours, minutes and seconds (updated every second).

Then I have 25V which is supplied by a transformer and connected to a set of LEDs through a CAT4101 constant-current sink LED driver. The Arduino board is powered by a 2amp USB transformer.

At a set time, the timer should set off the process to dim the lights.

Everything is working well if I set the lights to dim within a few minutes. However, if I leave the board on for more than 10-15 minutes then everything seems to freeze (i.e. the time on the LCD stops being updated and stays stuck at the moment it froze).

I originally thought it could have been something to do with my code. But I then skimmed everything down to the bare essential and just uploaded the code necessary to update the time on the LCD. And even in this case it freezes.

The only way I managed to avoid things freezing was to disconnect the CAT4101 pin 1 from Arduino's PWM and disconnect pin 2 from Arduino's 5V.

What could be causing this issue?


pin 1 = connected to Arduino PWM
pin 2 = connected to +5v
pin 3 = connected to ground 
pin 4 = connected to ground with 2kOhm resistor
pin 5 = connected to LED cathode


Code below (I have stripped down the code by removing any additional functions and leaving only the bare code which is leading the application to crash).

#include <Wire.h>
#include <RTClib.h>
#include <LiquidCrystal.h>

RTC_DS1307 rtc;
DateTime now;
LiquidCrystal lcd(7, 8, 9, 10, 11 , 12);

void setup() { 

 if (!rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(__DATE__, __TIME__)); // time = hh:mm:ss format, e.g. 06:01:01


void loop() { 
  now = rtc.now();

void updateDisplay(){
 int h = now.hour(); // Get the hours right now and store them in an integer called h
 int m = now.minute(); // Get the minutes right now and store them in an integer called m
 int s = now.second(); // Get the seconds right now and store them in an integer called s

 lcd.setCursor(0, 0); // Set the cursor at the column zero, upper row...
 lcd.print(" The time is: "); // ...with spaces to clear characters from setting alarm.
 lcd.setCursor(4, 1); // Move the cursor to column four, lower row
 if (h<10){   // Add a zero, if necessary, as above
 lcd.print(h);   // Display the current hour
 lcd.setCursor(6, 1); // Move to the next column
 lcd.print(":");  // And print the colon
 lcd.setCursor(7, 1); // Move to the next column
 if (m<10){   // Add a zero, if necessary, as above
 lcd.print(m);   // Display the current minute
 lcd.setCursor(9, 1); // Move to the next column
 lcd.print(":");  // And print the colon
 lcd.setCursor(10, 1); // Move to the next column
 if (s<10){   // Add a zero, if necessary, as above
 lcd.print(s);   // Display the current second

enter image description here

  • 2
    In my opinion it is a small bug in the code. I can start saying random line numbers or.. You can put the CODE!!! – frarugi87 Dec 1 '15 at 12:01
  • @Martin have you tried powered the CAT4101 with external source and not arduino? Try that and also place a capacitor in Vin as present in schematics of datasheet – brtiberio Dec 1 '15 at 12:10
  • Yes, code please, and LCD model number. – slash-dev Dec 1 '15 at 15:00
  • 2
    Personally I'd avoid running it without delays. Just put a 50-100 ms delay between runs, or use the millis() function if you want to avoid the rest of the program to stop. Then I'd update just the fields on the LCD that I need, not all of them every time. So compare the h, m and s variables to the one you stored in memory and update them only if they differ. This will reduce the traffic on the lcd lines and reduce the possibility of a malfunction. And please, h, m and s will never be greater than 255, so PLEASE use byte, not int – frarugi87 Dec 2 '15 at 9:37
  • 1
    There is a problem with the library or the combination of the library and the Arduino system code. I have been running many tests now with only 1 line of text. After a few hours, I experience the same problem with a (20x4) display. I use different Arduino Mega's and displays so a defect in my hardware can be excluded. I also use 2 different power supplies 1 Is a lab supply hence the power supply can also be excluded. Using delay or millis() to slow down the refresh rated does not solve the problem (or may be part of it). If i find the solution i will post it here. – JOHI Oct 21 '17 at 17:15

I would add a delay(100); to the bottom of your loop()

I'm betting even odds that solves it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.