LCD Timer

I would also like some code or links to examples on how to make a timer with hours, minutes, seconds (12:34:56), that starts when you push a button, that is displayed on an LCD, or via the serial terminal (I presume both will be the same).

(Once again) I have the Arduino LCD examples working well. I have a momentary button on Digital Input 10.

I think the maximum I would like to time is about ten hours.

It is to time the time is takes for a sensor to fall to a certain value.


Below is an idea - however, it is not very accurate. I will try to use the data from the internal counter using the millis() command next.

The example below reads two sensors, and displays their value and time since start up on the LCD. I would like to have a button which starts the timer however.

#include <LiquidCrystal.h>
int sensor1Pin = 0;
int sensor1Value = 0;
int sensor2Pin = 1;
int sensor2Value = 0;
int milliseconds = 0;
int seconds = 0;
int minutes = 0;
int hours = 0;

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

void setup() {
lcd.begin(16, 2);

void loop() {
sensor1Value = analogRead(sensor1Pin);
float pinFloat = sensor1Value * 30.0 / 1023.0;
lcd.setCursor(0, 0);
lcd.setCursor(5, 0);

sensor2Value = analogRead(sensor2Pin);
float pin2Float = sensor2Value * 30.0 / 1023.0;
lcd.setCursor(10, 0);
lcd.setCursor(15, 0);

milliseconds = milliseconds + 1;
seconds = milliseconds/150;
minutes = seconds/60;
hours = minutes/60;
lcd.setCursor(0, 1);

I will post my results again soon.

The loop() function adds 1 to milliseconds on every pass. The accuracy of this clock depends on loop taking exactly 1 millisecond to execute. That is not a reasonable assumption.

The Arduino comes with a function, millis() that keeps track of time accurately (within the limits of the crystal, at least). You should consider using it.