I'm working with this code to automate a small door on a timer using a DS1307 RTC; I have set the RTC time using the SetTime Example within the DS1307 RTC Examples and it returns the correct time when checked with ReadTest Example. However, when I load my program onto the Arduino, any Serial.print data returns 00:00:00 1/1/1970 as though the rtc is not responsive. I'm a super green beginner and borrowed this code from somewhere else and modified it to work with my RTC, but is there something obvious I'm missing? The functions for the Button Open and Close work fine, only the timer sections wont work.
I'm having mixed feelings about the sketch. I mean, the sketch seems to be a mix between the Adafruit RTClib and the TimeLib DS1307RTC library with ReadTest.ino example.
These two are the most common RTC libraries for a long time, but there are other options.
Some newer boards have a RTC build in the processor, and there are official Arduino time libraries for those.
When you show a sketch on this forum, please use code tags. Put the sketch between lines with three backslash-single-quotes or use the </> button.
Don't you have to call a function to fetch the time from the RTC chip before you have the values to use? Look at the examples for the RTC library you are using.
Alright, new code below; NOW I get proper timing when the arduino is plugged in via USB, but once unplugged and running on independent 5V power I have the same issue as before. I can't use the buttons now though unless plugged in, but if the relay is switched on (and its indicator light is on) when unplugged it will remain on until plugged back in outside of the conditions of the else if statement. Battery voltage is above 5V
Your sketch won't check the button unless you get a successful read of the RTC. You just have to figure out why the RTC stops working when you disconnect from USB.
external 5V supply is 3A 15W stepped down from a 12V battery; I've tried disconnecting the RTC and using just the relay which works but I can't get the RTC to control w/o being connected to the computer. It's only a 4 relay chip with a 10 A max on the switch side.
Scan2021-11-01_124658.pdf (504.9 KB)
forgive my drafting skills, but this is what my setup looks like independent of the USB connection
Edit: FWIW, I've now tried connecting both the 5V power from the transformer AND a wall outlet USB/120V connector at the same time and THIS works without connection to the computer. Definitely an amperage issue. Using a 5V breadboard power supply (with a 9V 700mA AC/DC convertor) connected directly to the relay doesn't supply enough power to run the relay, which makes even less sense to me.
Looks like you are connecting a 5V supply to the power input jack. You are supposed to use at least 7V on that jack.
The power input jack has a protection diode that will drop the voltage by about 0.6V to 4.4V. Your 4.4V then goes into the 5V regulator which needs over 6V in to get regulated 5V out. I suspect your "+5V" pin is somewhere under 4V.
To use an external 5V supply, connect it to GND and +5V, bypassing the internal 5V regulator.
This was the issue, I gave up on my battery power and just have it powered by a 9V AC/DC convertor for now. Either way, code works. Thanks for your help!