This is my first post on the forum. But I have a problem where the Arduino Mega restarted after approximately 2 hours after started it. And before It, It starts not doing simple functions as comparing values of an RFID tag and what is stored in the sd card.
Only 1 LCD, 1 RFID module, 1 Temperature module, 1 RTC module and 1 SD card module are connected to it. I've already tried different ways of feeding: through the jack pin, through the usb itself and even externally through the arduino's 5V pins. In this project, I don't have any kind of relay. I don't know what else to do to solve this problem.
The function Millis is used to Turn Off an LED connected to an IC 595 after 50 minutes, 100 minutes, 150 minutes ... This depends on what the value of the variable "sala" is set to.
I don't know if it is a memory problem or a code problem. Because I'm only usind 32% of the dynamic memory of the Arduino.
Here is the part of the code where the Arduino is running most of the time in a loop:
```
void tempo(){
if ((millis() - millisala48) < ((sala48-48)*3000000)){
}else{
sala48 = 0;
}
if ((millis() - millisala49) < ((sala49-48)*3000000)){
}else{
sala49 = 0;
}
if ((millis() - millisala50) < ((sala50-48)*3000000)){
}else{
sala50 = 0;
}
if ((millis() - millisala51) < ((sala51-48)*3000000)){
}else{
sala51 = 0;
}
if ((millis() - millisala52) < ((sala52-48)*3000000)){
}else{
sala52 = 0;
}
if ((millis() - millisala53) < ((sala53-48)*3000000)){
}else{
sala53 = 0;
}
if ((millis() - millisala54) < ((sala54-48)*3000000)){
}else{
sala54 = 0;
}
if ((millis() - millisala55) < ((sala55-48)*3000000)){
}else{
sala55 = 0;
}
if ((millis() - millisala56) < ((sala56-48)*3000000)){
}else{
sala56 = 0;
}
if ((millis() - millisala57) < ((sala57-48)*3000000)){
}else{
sala57 = 0;
}
mensageminicial();
}
void mensageminicial(){
if ( ! mfrc522.PICC_IsNewCardPresent())
{
lcd.clear();
lcd.setCursor(1, 0);
lcd.print("Hora: ");
lcd.print(rtc.now().hour());
lcd.print(":");
lcd.setCursor (10,0);
lcd.print(rtc.now().minute());
lcd.print(":");
lcd.print(rtc.now().second());
lcd.setCursor(0, 2);
lcd.print("Data: ");
lcd.print(rtc.now().day());
lcd.print("/");
lcd.print(rtc.now().month());
lcd.print("/");
lcd.print(rtc.now().year());
delay(3000);
if ( ! mfrc522.PICC_IsNewCardPresent())
{
lcd.clear();
lcd.print("Temp.: ");
lcd.print(bmp.readTemperature());
lcd.println(" *C ");
delay(3000);
if ( ! mfrc522.PICC_IsNewCardPresent())
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Pressao:");
lcd.print(bmp.readPressure());
lcd.println(" Pa");
lcd.setCursor(0,1);
lcd.print("Altitude:");
lcd.print(bmp.readAltitude());
lcd.println("m");
delay(3000);
if ( ! mfrc522.PICC_IsNewCardPresent())
{
lcd.clear();
lcd.setCursor(1, 0);
lcd.print("Insira a TAG");
}else{
tag();
}
}else{
tag();
}
}else{
tag();
}
}else{
tag();
}
if (sala48 < 1){
mega1.shiftWrite(1, HIGH);
mega1.shiftWrite(2, LOW);
}else{
mega1.shiftWrite(1, LOW);
mega1.shiftWrite(2, HIGH);
}
if (sala49 < 1){
mega1.shiftWrite(3, HIGH);
mega1.shiftWrite(4, LOW);
}else{
mega1.shiftWrite(3, LOW);
mega1.shiftWrite(4, HIGH);
}
if (sala50 < 1){
mega1.shiftWrite(5, HIGH);
mega1.shiftWrite(6, LOW);
}else{
mega1.shiftWrite(5, LOW);
mega1.shiftWrite(6, HIGH);
}
if (sala51 < 1){
mega1.shiftWrite(7, HIGH);
mega1.shiftWrite(8, LOW);
}else{
mega1.shiftWrite(7, LOW);
mega1.shiftWrite(8, HIGH);
}
if (sala52 < 1){
mega1.shiftWrite(9, HIGH);
mega1.shiftWrite(10, LOW);
}else{
mega1.shiftWrite(9, LOW);
mega1.shiftWrite(10, HIGH);
}
if (sala53 < 1){
mega1.shiftWrite(11, HIGH);
mega1.shiftWrite(12, LOW);
}else{
mega1.shiftWrite(11, LOW);
mega1.shiftWrite(12, HIGH);
}
if (sala54 < 1){
mega1.shiftWrite(13, HIGH);
mega1.shiftWrite(14, LOW);
}else{
mega1.shiftWrite(13, LOW);
mega1.shiftWrite(14, HIGH);
}
if (sala55 < 1){
mega1.shiftWrite(15, HIGH);
mega1.shiftWrite(16, LOW);
}else{
mega1.shiftWrite(15, LOW);
mega1.shiftWrite(16, HIGH);
}
if (sala56 < 1){
mega1.shiftWrite(17, HIGH);
mega1.shiftWrite(18, LOW);
}else{
mega1.shiftWrite(17, LOW);
mega1.shiftWrite(18, HIGH);
}
if (sala57 < 1){
mega1.shiftWrite(19, HIGH);
mega1.shiftWrite(20, LOW);
}else{
mega1.shiftWrite(19, LOW);
mega1.shiftWrite(20, HIGH);
}
delay (3000);
tempo();
}
