element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Vertical Farming
  • Challenges & Projects
  • Design Challenges
  • Vertical Farming
  • More
  • Cancel
Vertical Farming
Blog Automated Green House Blog:9.2 - Updated uptime counter LCD
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: m.ratcliffe
  • Date Created: 15 Oct 2015 2:36 PM Date Created
  • Views 500 views
  • Likes 1 like
  • Comments 0 comments
  • adapted_greenhouse
  • ardexpert
Related
Recommended

Automated Green House Blog:9.2 - Updated uptime counter LCD

m.ratcliffe
m.ratcliffe
15 Oct 2015

Nothing Very Interesting here, more for newbies learning about interfacing hardware.

 

This code will work on uno and mega, it will display the Uptime on the LCD sheild like the one in the image below:

 

image

 

 

 

Header 1

 

 

/* This Script is the bare bones needed to Keep a Uptime counter that will survive the 50 day timer rollover

This will not give a uptime of great accuracy over long periods, but it will let you see if your arduino has reset

if you want better accuracy, pull the Unix time from the IOT, External RTC or GPS module

Also Reconnecting the serial com's will reset the arduino. So this is mainly useful for a LCD screen

 

 

Michael Ratcliffe  Mike@MichaelRatcliffe.com

  

    This program is free software: you can redistribute it and/or modify

    it under the terms of the GNU General Public License as published by

    the Free Software Foundation, either version 3 of the License, or

    (at your option) any later version.

 

 

    This program is distributed in the hope that it will be useful,

    but WITHOUT ANY WARRANTY; without even the implied warranty of

    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

    GNU General Public License for more details.

 

 

    You should have received a copy of the GNU General Public License

    along with this program.  If not, see <http://www.gnu.org/licenses/>.

 

 

  

*/

#include <LiquidCrystal.h> //Standard LCD Lbrary

 

//************************** Just Some basic Definitions used for the Up Time LOgger ************//

long Day=0;

int Hour =0;

int Minute=0;

int Second=0;

int HighMillis=0;

int Rollover=0;

 

 

//**** Setting up LCD ************//

// select the pins used on the LCD panel

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

 

 

// define some values used by the panel and buttons

int lcd_key     = 0;

int adc_key_in  = 0;

int button =0;

#define btnRIGHT  1

#define btnUP     2

#define btnDOWN   3

#define btnLEFT   4

#define btnSELECT 5

#define btnNONE   6

 

 

int Screen =1;

 

 

 

 

 

 

 

 

 

 

 

//************** Setup routine - Runs once at power up **************************//

void setup(){

Serial.begin(9600); // starting Serial Com's

 

 

 

 

//Doing A Quick Start UP Splash Screen

lcd.begin(16, 2);              // start the library

lcd.setCursor(0,0);

delay(1000);

lcd.print("Arduino UpTime");

lcd.setCursor(0,1);

delay(1000);

lcd.print("Mike Ratcliffe");

lcd.setCursor(0,1);

delay(1000);

lcd.setCursor(0,1);

lcd.print("Free Software   ");

delay(1000);

lcd.setCursor(0,1);

lcd.print("Mike Ratcliffe");

delay(1000);

lcd.setCursor(0,1);

lcd.print("Free Software   ");

delay(3000);

//Clearing LCD SCREEN

lcd.setCursor(0,0);

lcd.print("                                   ");

lcd.setCursor(0,1);

delay(1000);

lcd.print("                                    ");

 

 

 

};

 

 

//****** Main Loop - Put your Code Here ********************//

void loop(){

 

uptime(); //Runs the uptime script located below the main loop and reenters the main loop

print_Uptime_Serial();

print_Uptime_LCD();

delay(50);

};

 

 

 

 

 

 

//************************ Uptime Code - Makes a count of the total up time since last start ****************//

 

 

void uptime(){

//** Making Note of an expected rollover *****// 

if(millis()>=3000000000){

HighMillis=1;

 

 

}

//** Making note of actual rollover **//

if(millis()<=100000&&HighMillis==1){

Rollover++;

HighMillis=0;

}

 

 

long secsUp = millis()/1000;

 

 

Second = secsUp%60;

 

 

Minute = (secsUp/60)%60;

 

 

Hour = (secsUp/(60*60))%24;

 

 

Day = (Rollover*50)+(secsUp/(60*60*24));  //First portion takes care of a rollover [around 50 days]

                     

};

 

 

//******************* Prints the uptime to serial window **********************//

void print_Uptime_Serial(){

 

  Serial.print(F("Uptime: ")); // The "F" Portion saves your SRam Space

  Serial.print(Day);

  Serial.print(F("  Days  "));

  Serial.print(Hour);

  Serial.print(F("  Hours  "));

  Serial.print(Minute);

  Serial.print(F("  Minutes  "));

  Serial.print(Second);

  Serial.println(F("  Seconds"));

};

 

 

 

 

//******************* Prints the uptime to serial window **********************//

void print_Uptime_LCD(){

   lcd.setCursor(0,0);

                      lcd.print("Uptime Counter:              ");

                   

                      lcd.setCursor(0,1);

                      lcd.print("                                     ");//Clearing LCD

                      lcd.setCursor(0,1);

                      lcd.print(Day);

                      lcd.setCursor(3,1);

                      lcd.print("Day");

                      lcd.setCursor(8,1);

                      lcd.print(Hour);

                      lcd.setCursor(10,1);

                      lcd.print(":");

                      lcd.setCursor(11,1);

                      lcd.print(Minute);

                      lcd.setCursor(13,1);

                      lcd.print(":");

                      lcd.setCursor(14,1);

                      lcd.print(Second);

 

};

 

 

Leave it running for a day or so against a good clock to see what people mean about drift. Put it somewhere warm or cold to see how this effects the stability of the timer.

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube