A weird problem. Arduino not working after few hours

I m recently doing a project of a lighting system. Which the leds will on and off with a 15 minutes interval at mid night, and turn on or off according to the surrounding light intensity in the rest of time.

The arduino works fine for the first 3-4 hours, then it stop working until I replug the power supply of arduino. (I use a dc power supply to provide 12v to vin pin as power source of arduino).This problem is also exist when the power source of arduino is pc usb port.

The logic flow of my code :

  1. While 0000 - 0800, the leds on and off in 15 minutes interval
  2. For the rest of the time, the leds turn off when the light intensity below 100 lx, else the leds turn on.
  3. Besides there is a timer1 interrupt initialize with 1s to serial print the timestring in order to check if the time is right.

Hardware list:
10w Led x 2 (vf=7-10V, I=900-1000mA)

TIP122 NPN transistor x 2 (as switch)

BH1750FVI (light intensity sensor)
the referrence code: http://zhongbest.com/2016/08/31/光强度传感器/

Ds3231 (real time clock)
The libraby i use: DS3231 - Rinky-Dink Electronics

The schematic is attached below.

I tired so many way to solve this problem, and the problem still exist. I m not sure what can I do now, any sugguestion or information are appreciated. Thanks for help.

I see your code is a model of perfection and utterly blameless. Why not post it then - just as an inspiration to others.

Nick_Pyner:
I see your code is a model of perfection and utterly blameless. Why not post it then - just as an inspiration to others.

Thanks for remind, here is my code.

I m now trying to use different supply to power my arduino, and the arduino is freeze after running for 30mins to 90 mins. Power arduino through usb cable run longer than power it through vin pin with 12V. And it works fine until I replug it.

I m not sure wt is the problem, is there any suggestion? Thank you for reply.

lighting.ino (2.24 KB)

A good quality power supply is essential for cheap electronics parts.

Try using a good 5V regulated power supply with more than enough amps for your project. Smoothing capacitors may also help. Could power problems from the electricity supply company be an issue?

As another aside, shouldn't 12V be put into raw and not vin? Just wondering.....

V-in is sometimes called raw. It's the input of the onboard voltage regulator.

Some Arduinos can handle 12volt (without sensors on the 5volt or 3.3volt pin) better than others. 12volt is borderline for the 5volt regulator. It might get hot over time, and shut down. The Arduino will restart (if you're lucky).

Tell us whiich Arduino (and supply) you have, so we can give better advice. Leo..