Paul__B:
It is vastly more likely that your secret code is faulty.
Possible cause is using "String" variables.
I don't have String on my code though. All the texts show on LCD are int and float. Actually, I build a product of current sensors that read AC motor current and switch it off if the current go over the maximum motor can take. This sketch is for testing if all the components are work properly. I already test a lot of my previous products with this sketch and this is the first time that I get this issue.
I'll leave my code here and do some more experiment and see if I get anything new.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#include "EmonLib.h"
EnergyMonitor emon1;
EnergyMonitor emon2;
EnergyMonitor emon3;
int count;
int count2;
int BAuto = 8;
int BManual = 9;
int Bstart = 10;
int Bstop = 11;
int Bautostate;
int Bmanualstate;
int Bstopstate;
int Bstartstate;
float value1;
float value2;
float value3;
int relay1 = 5;
int relay2 = 6;
int relay3 = 7;
float CT = 80;
int relay_state;
boolean Auto_Mode;
boolean Manual_Mode;
void setup()
{
//Serial.begin(9600);
lcd.begin();
emon1.current(A0, CT);
emon2.current(A1, CT);
emon3.current(A2, CT);
pinMode(BAuto, INPUT);
pinMode(BManual, INPUT);
pinMode(Bstart, INPUT);
pinMode(Bstop, INPUT);
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
digitalWrite(relay1, LOW);
digitalWrite(relay2, LOW);
digitalWrite(relay3, LOW);
Auto_Mode = true;
}
void loop()
{
value1 = emon1.calcIrms(1480);
value2 = emon2.calcIrms(1480);
value3 = emon3.calcIrms(1480);
count2++;
Bstartstate = digitalRead(Bstart);
Bstopstate = digitalRead(Bstop);
Bautostate = digitalRead(BAuto);
Bmanualstate = digitalRead(BManual);
switch (Auto_Mode) {
case true :
relay_state = 0;
count++;
if (Bmanualstate == HIGH)delay(250),digitalWrite(relay1, LOW), digitalWrite(relay2, LOW), digitalWrite(relay3, LOW),Auto_Mode = false, Manual_Mode = true;
if (count > 5)count = 0;
if (count == 1)digitalWrite(relay1, HIGH), digitalWrite(relay2, HIGH), digitalWrite(relay3, HIGH);
if (count == 4)digitalWrite(relay1, LOW), digitalWrite(relay2, LOW), digitalWrite(relay3, LOW);
lcd.setCursor(7, 1);
lcd.print(count);
case false : break;
}
switch (Manual_Mode) {
case true :
count = 0;
if (Bautostate == HIGH)delay(250),digitalWrite(relay1, LOW), digitalWrite(relay2, LOW), digitalWrite(relay3, LOW),Manual_Mode = false, Auto_Mode = true;
if (Bstartstate == HIGH)digitalWrite(relay1, HIGH), digitalWrite(relay2, HIGH), digitalWrite(relay3, HIGH), relay_state = 1;
if (Bstopstate == HIGH)digitalWrite(relay1, LOW), digitalWrite(relay2, LOW), digitalWrite(relay3, LOW), relay_state = 0;
lcd.setCursor(7, 1);
lcd.print(relay_state);
case false : break;
}
lcd.setCursor(0, 0);
lcd.print(value1, 1);
lcd.setCursor(12, 0);
lcd.print(value2, 1);
lcd.setCursor(0, 1);
lcd.print(value3, 1);
lcd.setCursor(11, 1);
lcd.print(count2);
delay(250);
}
sometime it's even freeze just only 3 sec after resetting.