So I built this:
This worked pretty well but lasted only about ten days. So I decided to make Shower Monitor 2.
Step 1: Design RTC
I didn’t like my first design as the batteries would only last about ten days, so I wanted a design that would last longer.
Technobabble: The reason batteries didn’t last long is that I had to keep power on the AtMega328 (Arduino) continuously to keep the software real time clock running. So I need to be able to put the AtMega328 to sleep or turn it off.
My friend sent me some of these RTC (Real Time Clock) modules:
These come with an RTC with battery backup and an EEPROM which is also helpful.
Problem: So I have a concern about these modules. Note that the battery is an LIR2032 which is a rechargeable battery. I suspect that it has a charging circuit. Well, I found a schematic and decided to draw my own (see picture). It does have a charging circuit and it would put an additional load on the 18650 battery.
Solution: So for this module, if you remove R5, D1, R4 and R6 and put a jumper across R6 and replace the battery with a CR2032, this will eliminate the battery charging. So that is what I did (see picture).
In this application, the CR2032 is supposed to last about ten years so I have no problem with that.
Warning: I was using an old library from AdaFruit for their datalogger called RTCLib. There was a sketch called DS1307.pde that would set the time. Now this worked fine the first time it was run but then it wouldn’t set the time. There is an updated version with an example that works better:
Download the zip, unzip it, rename it from rtclib-master to rtclib and copy it to your Arduino libraries directory.
TechnoSpeak I2C: Technically it should be I(squared) C or IIC which stands for Inter-Integrated Circuit. Basically it is a ‘standard’ serial interface requiring two signals SCL, SDA and ground. SDA is the data signal switching from 0V to 5V with the data going across in sequence (serially). Since there are only two levels and the speed isn’t determined, there is no way to determine where one bit of data ends and the next begins. That is where the SCL (clock) signal comes in. This tells the receiving device where one bit ends and the next begins.
One advantage to I2C is that several devices can be attached to the same two signals. In this case the DS1307 (RTC) and the 24C32 (EEPROM) are both attached to the SCL and SDA lines. In order to tell which device you are talking to each device type has a unique address.
The DS1307 address is 0x68. The 24C32 address is 0x50.
Arduino supports I2C with the ‘wire’ library.
By the way, what this means is that you can’t have more than one of the same device type on the same two lines. E.g., you can’t have two 24C32s.