Skip to main content
  1. dht22Dht22 sensor [humidity + Temp]
  2. three limit sw.
  3. one motor
  4. 16*2 lcd
  5. lamp [acting as heaters]

The main problem I faced is POINT 1 that I mentioned previously (I DON'T NEED TO LOSE THE TIME WHENdon't need to lose the time when I REBOOT THEreboot the LCD)

  1. dht22 sensor [humidity + Temp]
  2. three limit sw.
  3. one motor
  4. 16*2 lcd
  5. lamp [acting as heaters]

The main problem I faced is POINT 1 that I mentioned previously (I DON'T NEED TO LOSE THE TIME WHEN I REBOOT THE LCD)

  1. Dht22 sensor [humidity + Temp]
  2. three limit sw.
  3. one motor
  4. 16*2 lcd
  5. lamp [acting as heaters]

The main problem I faced is POINT 1 that I mentioned previously (I don't need to lose the time when I reboot the LCD)

Post Migrated Here from electronics.stackexchange.com (revisions)
Source Link
Zouhd
Zouhd

need help for saving the millis function when arduino was rebooted

I have two questions want to ask

  1. I'm using Arduino Uno with 16*2 LCD Blue ( also I have temp. sensor and two motors also 3 limit switches) ,, my code is working good, but sometimes my lcd stop printing the values of Temperature and time [print nothing i.e. print all the leds on] \\ then when I reboot it everything works good .... why this problem happened ?

  2. Is there any way to save the value of millis function when the arduino was rebooted ?

thanks for your help regards


My code is for an egg incubator , it consists of

  1. dht22 sensor [humidity + Temp]
  2. three limit sw.
  3. one motor
  4. 16*2 lcd
  5. lamp [acting as heaters]

As I said previously, millis function that I'm using is for controlling the motor movement every 3 hours and stop the movement after 18 days of working

The main problem I faced is POINT 1 that I mentioned previously (I DON'T NEED TO LOSE THE TIME WHEN I REBOOT THE LCD)

If any one can help by giving me a short code as an example who to deal with EEPROM or any other idea.

Here is my code

#include "DHT.h"  //includes lib for the temperature-humdity sensor
#include <LiquidCrystal.h> //lcd lib

#define DHTPIN 13 //pin that DHT is connected to 
#define DHTTYPE DHT22 //Sensor we are using

DHT dht(DHTPIN, DHTTYPE); //defines location for DHT

int sw1,sw2,sw3;
const int LM1=0;
const int LM2=1;
const int LM3=6;
const int LAMP=8;
const int CW=10;
const int CCW= 9;
const int Buzzer=7;
long previousMillis = 0;        // will store last time LED was updated
unsigned long RealTime = 0;  
float MOTORTime =0;// This is the real time that present on LCD now.
unsigned long MOTORSTOP = 0;// store the valve after 18 days of ranning ,, 

// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 10800000;           // interval at which to blink (milliseconds)(3 hours waiting)

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
 
  lcd.begin(16, 2);   // set up the LCD's number of rows and columns: [LCD that we have (Colomn,Row)]
  pinMode(LAMP,OUTPUT);
  pinMode(LM1,INPUT);
  pinMode(LM2,INPUT);
  pinMode(LM3,INPUT);
  pinMode(CW,OUTPUT);
  pinMode(CCW,OUTPUT);
  
 }
void loop() {
  sw3=digitalRead(LM3);
      unsigned long currentMillis = millis();
MOTORSTOP = currentMillis;
if (MOTORSTOP < 1555200000){ // 18 days
  float h = dht.readHumidity(); //defines the variable for humidity
  float t = dht.readTemperature(); //defines the variable for temperature
  // set the cursor to column 0, line 0
  lcd.setCursor(0,0);
  // print the humidity 
  lcd.print("H ");
  lcd.print(h);
  lcd.print("% ");
  //move line down
  lcd.setCursor(0,1);
  lcd.print("T ");
  lcd.print(t);
  lcd.print("C ");
  
  lcd.setCursor(10,0);
  lcd.print("MOTOR"); // to print motor working time

  
if (t==37.65)digitalWrite(LAMP,LOW);// Lamp OFF
else if (t>37.65)digitalWrite (LAMP,LOW); // Lamp OFF
else { digitalWrite(LAMP,HIGH);}// Lamp ON


  delay(2000); //wait two sec. before taking another reading.
  ///////////////stepper motor control and delay time 2.45 hours. 
 sw1= digitalRead(LM1);
  sw2= digitalRead(LM2);
  

  RealTime = currentMillis - previousMillis;
  MOTORTime=((RealTime/(1000))/60); //////////////////////////////////////////// 
  MOTORTime = 180 - MOTORTime;
  
  if (MOTORTime >= 1){
   lcd.setCursor(10,1);
  lcd.print(MOTORTime); }// this will print the ACTUAL Time Remaining on LCD
  else {
    lcd.setCursor(10,1);
   lcd.print("<1 MIN");}

  
  if(RealTime > interval) {
    // save the last time you blinked the LED 
    previousMillis = currentMillis;   

  if (sw1==LOW && sw2==HIGH){
    digitalWrite (CW,LOW);
    digitalWrite (CCW,LOW);
    do {
      digitalWrite(Buzzer,HIGH);
      digitalWrite (CW,HIGH);// change the direction of rotation (DOWN Movement)
      digitalWrite (CCW,LOW);
     
      sw2= digitalRead(LM2);}
      while(sw2==HIGH);}
      
      else if (sw1==HIGH && sw2==LOW){
        
      digitalWrite(CW,LOW);
      digitalWrite(CCW,LOW);
        
        do {
          digitalWrite(Buzzer,HIGH);
          digitalWrite(CW,LOW);// change the direction of rotation (UP Movement)
          digitalWrite(CCW,HIGH);
         
          sw1= digitalRead(LM1);}
          while(sw1 == HIGH);}}
}
//----------------------------------------------------------------------------------------------------------------------
else if (((MOTORSTOP/10800000)>= 144 )&& (LM3== LOW)&&(MOTORSTOP >= 1555200000)){
  digitalWrite (CW,LOW);
    digitalWrite (CCW,LOW);
    
   float h = dht.readHumidity(); //defines the variable for humidity
  float t = dht.readTemperature(); //defines the variable for temperature
  // set the cursor to column 0, line 0
  lcd.setCursor(0,0);
  // print the humidity 
  lcd.print("H ");
  lcd.print(h);
  lcd.print("% ");
  //move line down
  lcd.setCursor(0,1);
  lcd.print("T ");
  lcd.print(t);
  lcd.print("C ");
  
  lcd.setCursor(10,0);
  lcd.print("MOTOR"); // to print motor working time
  lcd.setCursor(10,1);
  lcd.print("OFF");
  
if (t==36.70)digitalWrite(LAMP,LOW);// Lamp OFF
else if (t>36.70)digitalWrite (LAMP,LOW); // Lamp OFF
else { digitalWrite(LAMP,HIGH);}// Lamp ON


  delay(2000); //wait two sec. before taking another reading.

}
}