Time counter with seconds, minutes, hours displayed on LCD screen

Hey everyone!

I seem to spend way too many hours at my desk each day so I wanted a way to count how many hours I spend at my desk in a year, just out of curiosity. My plan is to have a button when I sit down which continues the count and another button which pauses the count when I get up, therefore its only counting time when I am at my desk. I would also like an LCD screen which shows the seconds, minutes and hours as its counting, although i'd like to be able to turn this LCD on and off with a toggle switch.

So the difficult things i'm coming across is counting the time in hours, minutes and seconds as well as how to store the count variable when the Arduino is off. I've also never used a LCD display before although I conveniently own a 128x128 pixel colour LCD display by Duinotech.

If I was to take the project further, eventually I would like to make the screen show how many hours I've been at my desk total, during the year, during the week and that day. So the LCD would have four separate timers counting up.

Thanks Eddy

Sounds like you're going to need a Real Time Clock. The most commonly used types with Arduino are ds1307 and ds3231. These come on small modules with a button cell for power backup. Normally I would recommend the more accurate ds3231, but in your case the ds1307 will be accurate enough, and has the advantage of a small amount of memory which is also backed up by the button cell, which could be used to store your total times.

If this were for myself to use, I would always be forgetting to press the button when I arrived or left the desk. So I would use a small PIR sensor to detect movement in order to measure the desk time.

Seat cushion sensor.

To keep track of time: use UNIX time (as you get from the now() function of TimeLib). It’s the time in seconds since 1/1/1970. Makes calculations much easier. TimeLib comes with various functions to convert time into year/month/day/hour/second, for both the total time and intervals.

And a kind of seat sensor indeed. An FSR or some kind of pressure sensor that detects when you sit down. You’re bound to forget to press the button sometimes.

For long term storage between power cycles, use EEPROM.

Thanks heaps everyone. I think the pressure sensor is a good idea. I have written a base code which uses EEPROM and works fine. I will need to add an LCD, pressure sensor and some other stuff to the project and then make everything happen.

Remember to write only to EEPROM when the pressure comes or goes. You have "only" 100,000 writes per cell. So writing every second or more will wear it out quite quickly.