Day change sensor without extra hardware

the problem this project solves:
I never know if I took my medicine daily. Phone apps tend not to work because I can take the medicine and not log it, or log it and not take it.

Project idea:
a box/dock that my pill bottle sits on (3d printed so the bottle fits snuggly). It will have two photoresistors.
one directly under the bottle, and the other as an ambient sensor for debouncing the state of the bottle (present or not).

it will also have two LEDs, one red for indicating that I have not picked up the bottle that day. The green one indicating I did pick up the bottle that day.

a button that will allow me to manually toggle the state for the day, in case I need to manually do that.

Project problem:
This will ve a tiny box, I want to use an Arduino Nano or a mini.

How cant I sense a day change without extra hardware? the precision does not really matter as long as it can consistently figure that a day has passed.

my thoughts:
if I use the photoresistors it would be a little inconsistent because I could turn on the light in my room, etc. Unless I do some really fancy programming this would not work.

I can use the RTC in the IC or get an external RTC. the real-time will have to be inputted to the system. This would require me to at least include some sort of time input peripherals, like a screen, and buttons or a Bluetooth module and an app.

The goal here is to be able to detect day change (overnight) with a minimal amount of physical space and complexity. More of a plug and play system, without much configuration.

Thanks in advance

Use an RTC. You don't need a screen and buttons to set the time, just upload a time setting sketch once. Then once the time is set, upload the pill sketch. If you put a fresh 2032 battery in the RTC, it will keep the time for at least 5 years.

The easiest way to keep track of time is with [u]millis()[/u].

millis() starts counting the milliseconds when the processor is powered-up or reset so it's just a matter of subtracting the start-time from the current time. ...That's the simply millisecond-time, not the time-of-day.

There are 86,400 seconds in a day so that's 86,400,000 milliseconds in a day. It seems like a big number but with a type unsigned long you can count up to about 50 days.

You'll have to figure-out the overflow/rollover, which happens after about 50 days. I'm sure there are standard ways to deal with that. Or, you can reset the processor every time you open the box.

The Arduino's oscillator isn't super-accurate so it doesn't make a great time-of-day clock. But, you're re-setting the timer every day (if you take your meds on time) so errors won't accumulate. And, if you figure-out that you're 5 minutes slow every day (or something like that) you can make a correction factor in your software.

I wouldn't recommend omitting the RTC, because it will keep the time if there is a power outage. But the above idea could be used to set the clock. Just have one switch button, when you apply power to the device, if the switch is engaged, it will set the time to midnight (it doesn't have to actually be midnight, though)... after that, every 24 hours it will also read midnight and you can use that for your alert.

ESP8266
Internet time
Simple web display.
IR sensor to show if vial removed.
Mini display to show hours since last taken.
Bonus to flash if past due

aarg:
Use an RTC. You don't need a screen and buttons to set the time, just upload a time setting sketch once. Then once the time is set, upload the pill sketch. If you put a fresh 2032 battery in the RTC, it will keep the time for at least 5 years.

not a bad idea, combine both codes, then setup via serial. no extra hardware aside from the rtc

ignaciochg:
not a bad idea, combine both codes, then setup via serial. no extra hardware aside from the rtc

Yes, that is what I do with all my clocks. I have a monitor program that runs on the serial port. It allows me to set and check the date and time, change 12/24 hour time and so on...

If you are comfortable with combining with (or adding) serial functionality to your program, it is an excellent method. In your case it's even easier because you only need to set the hours and minutes, and you can use local time (here you give up automatic DST adjustment unless you want to go the whole mile and use Epoch times).

It does save you the trouble of uploading a time setting sketch in the event that you have to change the battery, or you have some kind of RTC failure.