Thanks for the interesting video Ralph, I actually use these RTCs with all my IoT sensors around my house but it did take some time to get a fully working & stable device for my needs, i.e.extremely low power use. Without posting my schematics the basics of my system are as follows: Sensors are powered via 2 x 18650 cells in parallel for capacity not voltage which go to a ultra low Microchip 3.3v LDO The output of the LDO is connected to a P- Channel MOSFET & the gate of the MOSFET is connected to the INT/SQW pin of the RTC (DS3231) (all this time, my ESP8266 & even the RTC itself has no power, the RTC purely running on CR2032 backup) When an alarm is activated, the gate of the MOSFET is pulled low which then sends the regulated 3.3v around the circuit. ESP8266 is powered on, takes a reading and sends this reading to the main unit located elsewhere via ESPNow, ( the main unit is connected to a permanent supply & connects to the internet to upload the reading), sets a new alarm for the RTC and then shuts down to wait for the next wake up call. The MOSFET gate is then sent high once again & all powere is removed from the circuit. RTC is now running on battery backup again. There are a number of caveats though that mean some modifying of the DS3231. The 472 resistor pack located above SDA & SCL pins on the RTC have to be removed & make sure that there are SDA & SCL pullup resistors on the board being used, good thread here: forum.arduino.cc/index.php?topic=537675.0 For super low power removal of the LED on the DS3231 is also a great idea. Plus a necessity for anyone who uses these RTCs is to remove/disable the inbuilt charging circuit. These RTCs come ready to accept an LIR2032 rechargeable battery, most people find these inadequate and fit a regular CR2032 non-rechargeable battery in the holder. The problem is that there is a charging circuit on the unit, not a good mix with a non-rechargeable battery installed. For simplicity I just removed the 200ohm resistor on my RTC, some people removed the whole circuit though. More details here: thecavepearlproject.org/2014/05/21/using-a-cheap-3-ds3231-rtc-at24c32-eeprom-from-ebay/ Cheers..,
Very interesting. I also got the P-channel MOSFET of a Si4599 to go LOW via the SQW/INT pin of the DS3231, and the current required was in the order of 3µA. I'm guessing that when you clear the alarm the open-drain MOSFET on the DS3231 goes high again which is enough to turn the P-channel MOSFET off again? Neat. Thanks also for all the other current saving techniques, every µA counts!
There is one interesting thing about these DS3231 modules. They are trying to charge the CR2032 battery! I can't remember where I found the schematics of this module and noticed this couple of years ago, so I can't give a link. But you need to remove one 200 ohm resistor right next to the SCL pin on the 4 pin connector side. It is between the MELF diode and the SCL pin. Both the diode and the resistor are in on this very wrong charging circuit, so you can remove either or both. This may also be the reason of higher than expected current draw.
I even have one with a rechargeable battery still in it. Dead as a dodo now of course. I will check whether the charging circuit is still included on mine and remove the resistor/diode. Good information, thanks for posting.
I spent 2 months in lockdown messing with this stuff trying to build a temperture/humidity data logger with a mini pro, got current consumpion down to around 3mA when sleeping which is still very high. alot of help from thecavepearlproject.org/2014/05/21/using-a-cheap-3-ds3231-rtc-at24c32-eeprom-from-ebay/ Desoldering the led and charging resistor and the vcc leg of the 3231 chip make a massive difference but you need to power the leg from an arduino pin when reading and recording data And Nick Gammon site was also very helpful gammon.com.au/forum/?id=12106 He claims less than 7 micro amps for his logger
@@Ed19601 check this site for reasons not to use the charging circuit on these boards thecavepearlproject.org/2014/05/21/using-a-cheap-3-ds3231-rtc-at24c32-eeprom-from-ebay/
Excellent video! I did a breadboard/bare bones project like this, and ran into the RTC eating too much current during sleep. My solution was to power the DS3231 from a pin on the microcontroller. Before going into deep sleep, I set the pin low, then set it as an input without pull-up. I think I got to around 40 microamps. The DS will still trigger the low alarm signal, so having the Int pin with internal pull-up is necessary. Runs for around 16 months on 3 AAA batteries I think.
Nice work! 16 months on 3 AAA batteries is pretty good. I tried powering it from an Arduino pin but got strange results and I was pushed for time. Nice to hear it can be done by you Andrew. Thanks for the post.
@@RalphBacon You're welcome! One thought: Did you remove the charging circuit from your board? The diode/resistor pair near the auxilliary SCL connector form a (really bad) charger from Vcc direct to the battery. (From memory, the boards are meant to have a rechargeable 2032 but usually have a CR2032, but in any case the charger is inadequate/dangerous depending on Vcc) I'm wondering if that would pull down the GPIO pin's output too much? Out of interest(?) my proto board also had a tiny OLED display for setting the clock and some other parameters for my project (environmental air sampler), so I used the same trick for that with a GPIO pin to power it during setup. You've got to love this stuff!
@@ighost_1337 should be able to. It was a work project, so I'll check if anything needs stripped before sharing. Drop me a message in a few days if I don't respond again! Cheers.
I live in rural Michigan. I wish I could find any electronics locally. Everything I get comes from Aliexpress. :P Thanks for the awesome tutorials. I've learned so much since I found your channel recently. Thanks Ralph!!!
Glad to help! Note that Amazon also sell some stuff (yes, source from the Far East, too) which might be an option for you. And you have the "big boys" such as Digikey, Mouser and so on.
Ditch the 1307s, Nick. I have some still and will never use them, they lose seconds per day and are not temperature compensated (so they get more inaccurate the hotter it is, during the summer, for example). Sad but true.
I used a similar idea to save power when using a venerable PIC 16F84A to make something similar to the "who got in first" device used on quiz shows. The B port would be set up to trigger an interrupt on a button press, then the Sleep instruction executed to put the processor into a low-power state. An interrupt would wake up the processor and the interrupt routine would simply return, allowing the rest of the program to continue (check for which button triggered the interrupt, light up a LED to show which button was pressed and make a sound by bit-bashing a port, then go back to sleep until a reset is received).
@@RalphBacon They're fun to play with. my next project was making an 8-pin PIC produce a single-bit "white noise" output by internally simulating a 32-bit ripple counter with XOR feedback, effectively making a pseudo-random number generator. My latest project has been programming an Arduino Nano to drive a 32x8 Neopixel display with static text and a colour-changing border. It's all fun, until it comes time to put a box around it... sigh.
Been looking at making a birthday clock using a DS1307, promini and 16x2 lcd and came across your video as I was looking for more info on the use of structs. In some ways seems simple enough but it can get rather deep rather quickly and hence loss of understanding. So a list of names and the day and month of the birthday and then display something like "happy birthday johnny" ...other times just display the time etc. I guess or "no birthdays today". I'll keep at it.....cheers Jeff
Don't use a DS1307, Jorgo, they are notoriously inaccurate. A DS3231 is much, much better. The way to approach a project like this is to split it up into logical sections. Get each section working without worrying about whether the time is 4 pixels too far to the right! So, I would: 1) Get the LCD working. Display HELLO WORLD on it. That proves your I2C is working too assuming you are using one with the extremely useful "I2C backpack" which I covered in a recent 'Bacon Bytes' video. 2) Read the date/time from the DS3231 (Getting the date/time INTO the DS3231 is another task). Display it on the (working) LCD. Ignore the fact that it's the wrong time and date. You will need a TIMER TASK to run a function every minute to update the time. 3) Find out how you set the date/time on an DS3231. It's best to do this in a SEPARATE sketch otherwise you run the risk of overwriting the real date/time with some past date/time in your code. Don't ask me how I know this! 4) Decide how you will store the birthday info. On an SD card? Whilst you _can_ hold such info in EEPROM, that is more difficult initially. Updating an SD card is easy on your PC/Mac and then just read it in the sketch. It would take me probably a few days to do all this so that I had a working prototype. It might take you considerably longer. The best advice that I can offer is to do the tasks one by one and get it WORKING well enough before moving on. And watch my video #BB9 about organising your code, you will thank me! Good luck!
@@RalphBacon Hi Ralph...thanks...covered up to point 3 and will take a look at your link. Had been looking at storing [10] birthday names with day and month in progmem in a struct but how to retrieve is yet to come. I guess a "for loop" to check the now time and compare. Anyhow, onwards and thanks for the link. Cheers Jeff
Observation: the pull-up resistors are not only applied to I2C's SCL and SDA, but to SQW. The DS3231 chip supplies SQW on an open drain, but the board with its pull-up resistors connects SQW to the board's Vcc, and Vcc is connected (amongst other things) via the LED to ground. That means that when the RTC is running on its button battery (no power on I2C), volts (from an external source) applied to SQW are attempting to power the LED and other bits of the board, and current is draining from the external source even while the alarm has not yet fired. Which rots my socks.
If you have a power-critical application, a simple ultra low power timer like the TI TPL5010 would be a good way to go. You could power down the RTC just before going into deep sleep, and the timer would draw 35-50 nA until it wakes up the MCU. You'd be limited to sleep times of 2 hours (for this timer anyway), but most applications need to wake up more often anyway. And if you need to wait until a specific time of day, you can set it to wake periodically, wake up the RTC, check the time, and go back to sleep if the time isn't met. With sleep intervals of more than a few minutes, you'd still gain a lot of battery life.
I think, when the DS3231 is powered from external source (5V of Arduino) and the vcc is higher than the coin cell voltage, the coin cell is being charged from that external power source, hence the higher consumption. I think I read it in the data sheet.
You are correct, Milen. The charging circuit is present and will attempt to charge a non-chargeable battery (eg CR2032) if fitted! One of my DS3231s actually has a rechargeable battery still fitted. I must remove the charging circuit resistor to avoid any unpleasant surprises with that coin cell. Thanks for posting, good to hear from you.
Been watching you for a few years now and I like the way you over-explain everything. It really helps people get what you mean. I love yer new shop for doing yer vids. Did you need a permit for that? I made a greenhouse and Melanie " Low Vision Life"thinks I needed a permit for that. Wadda ya think?
It's nice you are still with me on my Arduinite journey, Drex! My "new" workshop (now two years+ old) did not need a permit as it is less than the permitted 2.5m high (when near a boundary, ie fence) and is classed as a "shed". I could have had it bigger (if I had more room next to my house) and still not need a permit. The rules have relaxed in the last few years.
Hi Ralph great video again. I do a lot of deep sleep projects for farm sensors running on AA batteries so always interested in new ideas. I think if you are serious about deep sleep performance you will need to use the DS3231 IC rather than the module, only turn on the pull ups when you need to reset the Alarm. Then you could use the alarm to power on rather than wake up the uC. Although it sounds silly waking every 8 seconds its actually hard to beat for consumption the power lost is less than normal battery losses for time and requires an oscilloscope to detect it has even happened. I have sensors waking every 30 mins to sample and send long distance via nRF24 and lasting 18mths +...
Absolutely, Andrew. I do believe I originally mentioned this only to cut it out - using a module is within the grasp of most Arduinites, soldering a 16-pin SMD (of which only half the pins do anything) is a soldering iron too far! Yes, the power consumption thing would have to be measured very accurately to determine whether this method was better than waking up every 8 seconds. But your empirical evidence makes it sound that the WDT method still has merit (and no extra hardware required). It's a pity no Chinese manufacturer has made an Arduino clone with a DS3231 built in.
@@RalphBacon that sounds like a challenge, perhaps i should make one. First i will do ther theoretical math based on the data sheet. To see if it has any chance of being better at power consumption. Thanks again n for the great video
Or do what others have suggested here: desolder the EEPROM chip, remove the battery charging circuit resistor (and diode too if you want), power the VCC to the DS3231 from the Arduino GPIO pin. Job done. I'll try all this soon. You first!
@@RalphBacon FYI using CurrentRanger and Oscilloscope i can see that it takes 16.3ms for each 8sec wake up which is 3min 1sec perday 18hr per year. For my 10ma project thats less than 10% of 3 AA batteries in a year. The lowest standby for ds3231 will use~50%. So no chance of being better.
You are not up to date on LiIon batteries, the 18650 is up to 3400mAh and 2000mAh is not very common. I have been testing LiIon batteries the last 8 years, this table shows brand and capacity and links to a review of each cell: lygte-info.dk/info/batteryIndex.html
That's both useful and an eye-opener for me. the last 18650 batteries I bought were in 2018, 6 x Samsung 2500mAh for the princely sum of £22. Things do change quickly in the battery world these days.
Great video as always. Have you calculated how much power it would take to just use the watchdog timer, wake up every 8 seconds, increment a counter, check for 10,800, and go back to sleep. If you did not need "real" time, it might take less power then running the I2C lines.
I haven't but Andrew Toogood (comment below) has Real Life experience of using the WDT and thinks it the way to go. They switch on so fast and go back to sleep again that he needs an oscilloscope just to prove they work up! I can't argue with that!
Warning !!!!!!!!!!! The module (DS3231) is delivered with a CR2032. This is a lithium battery. That would be no problem if the module did not have an armed charging circuit. During operation, the input voltage of the module is on the battery, and this can also be 5 V. The charging circuit can be removed by removing the diode (red) or the 201 above or by interrupting the line.
@@RalphBacon What do you make of MAXIM's statement on the DS3231 datasheet "The device is UL recognized to ensure against reverse charging when used with a primary lithium battery." Is there evidence of problems, rather than a theoretical concern? (I sound like Dr. Fauci.)
Another good video thanks, the ds3231 module along with a EEPROM has a diode and resistor from 5v to the battery adding a sleep drain along with the I2C resistors. Working days and weeks ahead is a pain unless have UNIX time a count of seconds and decode void to convert back to time format ts. The time library does this ? Graham
The Time library (or something very similar) does this, Graham, as I use UNIX time in the HomeAlone project so it will be an #include in that code. Whoever is interested, that code (2,000 lines of it) is in my GitHub. Yes, others have mentioned the charging circuit (which I had forgotten about, even though one of my DS3231 actually has a rechargeable battery in it).
Good stuff here! Given that you mention that I2C is only good for distances of ~1 meter or so, what would you use to go further? I saw mention in one comment about "stuff all around the house", what would you use for something like that?
WiFi is the obvious thing to connect stuff around the house, roy, although if you really wanted a wired connection then RS485 is robust (I even did a video on it, #106). You can get extenders for various protocols too, that all run on CAT5/6 cable, which convert the signal from one protocol to another and back again. That way you can run I2C over hundreds of meters (see learn.sparkfun.com/tutorials/qwiic-differential-i2c-bus-extender-pca9615-hookup-guide/all ). WiFi (if you have decent enough signal) is the "cleanest" method though.
Thanks for these well presented and clear videos. I'm teaching myself simple electronics and find certain Arduino projects really helpful. I plan to use this RTC video on one of my tasks, but only need a "wake up" at the same time each day. In this case do I still need to "set next alarm" each time the sleep pin goes low.
I don't think the alarm is held over to the next cycle (unlike your bedside alarm clock) so you need to set it each time. Pretty sure, but best check the datasheet or just try it out!
@@RalphBacon Yes I will. Thanks for the quick response. I am still having problems getting it to repeat for the first time. I'll get there, and let you know. It's just that you said somewhere in the video that the DS3231 held the data permanently and I assumed that once the hour/min/sec was set it was there until the battery ran out. I still need to work out what I am doing wrong. It works fine on day one, but seems to stall after that.
Grand video. A couple of thoughts to save current. As the DS3231 has a backup battery would powering the DS3231 from an arduino pin then allow you to cut the supply in the go to sleep sequence [I dont know if that affects the alarm out pin]. Second idea, would wire.end() de-energise the I2C just ahead of sleep, then wire.begin() on wake up?
Best to keep the DS3231 on its own 3v battery - it will last for at least a year. And, yes, it needs the power to function (ie create the alarm, of course). does Wire.begin/end control the power or just start the protocol?
Yes. The Arduino is in Deep Sleep (suspended, effectively) but will be woken by a LOW signal on the chosen GPIO pin because your code told it (attachinterrupt etc).
I made a box to remind the boss to take her medication at breakfast every morning using theDS3231. Great chip. Remove the resistor array to kill the EEPROM (big blob of solder took the whole thing off!) and cut power track. Using Lidl AAs, it’s still going strong 16 months later (so is she!). It flashes a LED every 3 seconds until she stops it. This battery calculator is much better for this type of project oregonembedded.com/batterycalc.htm. And you can power the DS from an Arduino pin and switch it off before sleeping. Interrupt still drops on alarm!
I wish I had found that battery calculator page! Yes, I guess removing the EEPROM and the battery charger circuit would do wonders for the current consumption. I will have to modify my one to do this and re-measure. Now, I tried powering the DS3231 VCC from an Arduino GPIO pin but got weird behaviour so I didn't mention it during the video. I'm glad you said it works OK so I will retry that. Great information, thank you.
@@RalphBacon Thought I'd report back. I tried this on the ESP32 and it works like a charm. I used the esp_sleep_enable_ext0_wakeup function For even more power saving, would it not work to try and use a Si4599 as part of a power latch circuit? I recently watched your other video on power latches, and it seems that a N channel and P channel mosfet can be used, is this not what the Si4599 provides?
Report back: I tried it out and it works great. The Si4599 is a small chip and cheap, this works really well as a power latch. Thanks Ralph, I wouldn't have known about it without your videos
Please pardon the intrusion for jumping on this thread but I'm quickly approaching the end of my reason and am no closer to a solution. I have watched ALL of your low/save power Arduino videos but I don't have the knowledge to use the info effectively. I am trying to build the most efficient battery powered circuit that will illuminate a LED when movement is sensed by a PIR. This will only happen during 'night' hours meaning start at 4pm in winter & 9pm in summer. My idea is that it would power off at say 12am and then repeat 24hrs later. I acknowledge thast the change from winter to summer time will be manual. My proposed solution is ... Use Arduino to programme a RTC with actual time together with relevant start and finish alarms. @ Alarm 1 the RTC (running 100% on internal battery) will send a signal to the gate of a BJT. In response the BJT will switch power to a PIR. When the powered up PIR senses movement it will send a signal to a 2nd BJT. This second BJT will switch power to the LED for as long as movenment is sensed. When movement stops there will be no signal from PIR to 2nd BJT thus cutting off power to LED. Process continues until Alarm 2 when the RTC will stop sending a signal to the first BJT. No power will flow until the Alarm 1 is triggered the next day. Is this possible? Am I thinking about it the wrong way? Can an RTC alarm be used as described to stop a singal being sent to the first BJT? I love the comment (from another project)... "It's impossible to over-engineer hobby projects" 😂 Again I do apologise for the hijacking but desperate people do desperate things at desperate times.
I feel your frustration but, as always, there is a technical solution, just maybe not the one your were expecting! Whether you can _directly_ power an LED (I'm assuming a proof-of-concept 5mm LED?) from the PIR, rather than use a microcontroller, I cannot say as I've never done it. Using a BJT might work, but again it's not a path I have trod before. Sounds plausible. You can certainly use an RTC (DS3231) to switch on (and off) something like an Arduino ATMega328p chip (not the board, like an UNO, as that consumes far too much current). As the RTC is independently powered, usually by a 2032 button battery) it won't cause your main power source to become depleted. The PIR needs powering too and from what I recall they are not so low-power friendly. Usually, you would have to either power continuously or *use a solar cell* during the day to charge a Li-Ion battery for use overnight. The PIR needs to be active during all the night hours so current consumption becomes a factor. The advantage of a rechargeable circuit is that Arduino chip can also be powered from it, albeit only when the PIR detect a movement, sends a signal to the Arduino to wake it up from Deep Sleep, light LED for as long as it gets the PIR signal, and then go back to Deep Sleep (the ATMega328p only needs < 1μA when in Deep Sleep). TL;DR my take on this would be to use a solar/rechargeable solution, with a standard Light Dependent Resistor (LDR) that determines when the circuit as a whole should run. Thus, no need for an RTC at all. There are millions of light-level switch circuits out there on the Internet (basically a comparator circuit). This LDR circuit could then trigger and power an ATMega328p chip with minimalist circuitry just like my demo. It would be in Deep Sleep for 99% of its life but would wake up when triggered by the PIR's output. That would then control the LED whilst it was getting the trigger (and could extend the light's duration, just like your security light). A BJT might be all you need at this stage, no μC at all! Whilst using discrete components as you suggest _might_ be possible, it's not the way I'd do it. Whilst you mull over some possibilities I'll try and see whether I can devise an analog circuit with a DS3231 and PIR to do what you initially proposed.
@@RalphBacon Thank you, Ralph, for taking the time to consider my post and reply. I have sucessfully driven a LED via a BJT (2N2222) from both PIR #1 & PIR#2. I haven't yet tried this on P1R#3 - see below. Are you saying that an RTC (DS3231) via a second alarm can effectively stop sending the signal from the first alarm? If so, this is very encouraging. It is my intention to power both PIR and LED from the same battery. To date I have looked at three PIRs... PIR #1 is an HC-SR501 which uses 65mA. However this model can be set up to continue sending a signal while it senses movement. PIR#2 is an AM312 which is marketed as Low Power. In my experience this is very low power & does not have the option to set a delay. P1R#3 is a RCWL-0516 which uses microwaves and is very low power. It generates a 3.3v output but no control over the delay time. This particular project is not solar friendly. I am trying to draw attention to a sign when a person enters a corridor. The corridor has windows and the sign is obvious during daylight. However, it is easy to miss under artifical lighting. While access to the project is fine unfortunately there is no convenient source of AC power. I think I'd be able to complete the project using a bare bones Arduino (and I probably will for practice) but at this stage I am trying to design the simpliest solution I can think of.
So having scribbled out a diagram or two, it quickly became apparent that doing this with analog/discrete components without some sort of microcontroller was becoming far too complex. Then I had the thought to consider how my garden ornaments lit up at night; most were solar powered (charging during daylight hours) but we also have one, battery controlled PIR light that works very effectively. It's a commercial device, cheap and there are unmpteen variations on the format and design, but all fall within your brief of a battery-powered device that lights up something when movement is detected during the hours of darkness. Here's a link to what I have, but as I say there are many of this format: amzn.to/3vzqgdd There is one downside to this particular device (and, come to think of it, many of this type): they are easily detachable (mostly magnetic) because they need regular recharging via a USB port or need new batteries now and again. Great for the home user, maybe not so great for a public place with light-fingered visitors? You may need a different format device or some way of securing it (which might include placing it high enough so that it cannot be reached without a ladder, for example). I hope this "blue-sky", "out-of-the-box," "pushing the envelope" thinking may help you in coming up with a solution that is cheap and easy to install! Sometimes the easiest solution if one that has already been thought of and manufactured.
Thanks again for your time and recommendation. I assume the PIR becomes live when ambient light is low i.e. when it gets dark. I'm trying for a situation where the PIR becomes active within defined on/off times. My original goal was to design the simplest project possible but it looks like I will need to include an AtMega328 chip to achieve that. Thanks again
Is it possible to power on arduino with this alarm clock? I mean, when using mosfets to completely shut down the arduino, then start it with an alarm from the DS3231
If you combined this with my Auto On/Off circuitry (or variant) you could do it: #173 ruclips.net/video/S2y1oAVmxdA/видео.html A better way would be to build your own Arduino UNO with a bare chip (only requires about 5 components) then put it into Deep Sleep which consumes just 0.2μA. Wake upon external trigger.
How do you program the chip, do you put it back in a UNO upload the sketch then pull the chip and put it in the little test mule you built? Or do you have to play around with one of those finicky FTDI things?
When I design a circuit I allow for the ICSP connections (so the SPI pins, basically) and use a standard programmer (or an Arduino-as-ISP) to program them. Once you have used an FTDI (USB-to-Serial device) a bit, you'll find them a lot less finicky I assure you!
In this video I'm probably using the Eclipse (Sloeber) but that's now dead in the water. I recommend the new Arduino IDE 2.0, now available as Release Candidate 5 (so very, very nearly done). Get it here: www.arduino.cc/en/software#experimental-software
At 3:42 you say, referring to setting an alarm time "you can have days weeks MONTHS hours minutes seconds" but neither alarm1 nor alarm2 allow for MONTH. Maybe in a short month you could specify a day of month of 31 and not alarm at the end of the current month (I haven't tried that), but there is no alarm register that will accommodate a month number (or year number, for that matter).
You are right, the granularity stops with days. Which is a shame really, because if you wanted an annual or bi-monthly reminder it can't be done (easily).
@@RalphBacon Thirty days hath September / April, June and November / All the rest have thirty-one / Except February which hath but twenty-eight days clear / or twenty-nine in each leap year. :) Calculating a leap year: Divide the year by four. If it does not divide evenly, it's not a leap year, otherwise go to the next step. Divide the year by one hundred. If it does not divide evenly, it's a leap year, otherwise go to the next step. Divide the year by four hundred. If it does not divide evenly, it's not a leap year, otherwise it is a leap year. Yes, it's complicated. The complexity is because the Earth's orbit around the Sun isn't an exact number of days. It's _almost_ 365 and a quarter days, but not quite, which is why a leap year has to be skipped every so often.
Hi Ralph, old one i know but I get conflicting info and thought you might know. I'm changing from a DS1307 to a DS3231 RTC and one aspect is, some say a rechargable LiR2032 is required rather than, like you use here, a CR2032. Most also say no need to change anything with the includes etc. as this ds3231 will work the same. Any comments? Used wire.h and RTClib.h and RTC_1307 rtc;....also have a 1602 i2c lcd on library hd44780.h as I'm told this is a far better library for the display. Reason for the change is due to the time drift on the ds1307.......would like to keep it as is but cannot find a simple way to correct it from time to time externally(up down buttons)
The DS1307 should be withdrawn, it is very inaccurate. Hence the DS3231 which is super accurate. You do NOT need a rechargeable battery but some boards do include a charging resistor on the DS3231 modules which should be removed if you are using a standard CR2032 battery. If you don't remove it I'm not sure any bad things happen; the voltage will simply be used instead of the battery, I guess... (if your house burns down do not blame me, though 😲) I haven't used library hd44780.h as the one I use does everything I need, but no harm in trying it out!
Great video, perfect and detailed explanation. And it works .... unit you do something more in the "I am awake" state. Adding DHT11 reading, Writing to an SDcard, a Delay(2000) and .... everything stops with me. Any ideas?
When you say "stops", what do you mean? You need to put in several Serial.println statements so you know at what point the code got to before not getting any further. Are you sure you used the exact code of my demo (including the "don't go to sleep again until I tell you" line)?
Now it works OK. My code here: github.com/mitjad123/IOTarduino/blob/main/DHT11-SDcard-DS3231, fritzing: www.dropbox.com/s/5yowvr9a5iqoxns/Schematic_arduino%20pro%20mini%20ds3231%20dht11_2021-01-27.pdf?dl=0
I did try this sketch but it seems that the wakePin is changing state constantly, meaning goes to sleep and wakes up in milliseconds ! any idea why ? i used the same rtc module with an Arduino Uno.
If the wake pin is suppose to go LOW to wake the device, ensure you have either defined it as an INPUT PULLUP or have attached a 10K resistor from it to VCC.
Enjoyed your video, but I have a slightly different problem that I think you can help with. I am trying to wake up a ESP8266 12-E NodeMCU with the DS3232 Alarm and haven't been able to make it happen. I have not been able to find a wiring diagram that works. My sketch sets the alarm(s) and they fire as directed, but I have not been able to wire the SQW pin to the ESP8266 RST pin and make the wakeup/reset work. I think I have tried every combination of transistors/resistors/etc. but nothing seems to work. My aim is to use ESP.deepsleep(0), but can't get the alarm to reset even when the ESP8266 is awake. Your help would be appreciated. John B.
Such a long time ago, John... my brain is foggy. I covered Deep Sleep for the ESP8266 in video #118 (ruclips.net/video/NgPwPKXCLFY/видео.html ) and I seem to remember that the RST pin had to be held LOW for a minimum period; I'm not sure the SQW output is LOW long enough but you could prove this pretty quickly I'm sure with a 555 monostable getting its wake up from the DS3231 which then provides a much longer pulse for the ESP8266. If you just short the RST to GND does the ESP8266 wake up OK?
@@RalphBacon Thanks for your reply. Yes it does wake up (restart) when connected to GND. I don't do much EE type stuff but I can tell you what I see. When I measure the SQW output I get 3.5v and same for RST. When SQW alarm fires SQW drops to 0v and after the alarm it goes back to 3.5v. It is a very short pulse. If I connect the SQW to the RST it locks up the processor until I disconnect the wire. I've never used the 555 monostable and only know what I have learned on the web over the last two minutes. Do you have a video explaining it? Thanks again, John B.
I haven't done such a video (other than my 555 watchdog) but if you email me (my email is in the About tab of my channel - but not from a phone) I'll send you the best book on 555 timer chips that you can peruse.
What I do not understand that sleep current consumption in this video is not verified with multimeter. I'm watching this with pretty much the same setup and Arduino Pro Mini 3.3V (basically Atmega chip, efficient, but weak voltage regulator unable to provide high current for SD card for example, reset button, oscillator, few capacitors and resistors and nothing else), trying to resolve issues which either do not exist in your setup (due to code differences or I omitted something). But first mistake I can see is that battery charging circuit is not disabled which may add few milliamps extra to overall power consumption at 5V because battery is being charged (regardless CR2032 is not rechargeable). Other problem is that in this exact setup, RTC circuit consumes roughly 90uA and Arduino 60uA with ADC disabled. I'm not sure why Arduino consumes so much. When I tried to remove VCC from RTC powering it from pin, it switches to battery, but also interrupt goes to low at this moment so falling edge is not detected or interrupt is triggered briefly after arduino enters the sleep. Another problem is that BOD has to be disabled within few instructions before entering sleep, but with power consumption being 150uA in my setup, I don't bother to save maybe 10uA. Weirdly I checked The Cave Pearl project which mentions that 90uA as well, but it also mentions that RTC can be powered via digital pin, without mentioning interrupt. I can try to set BBSQW bit on, it's undocumented what effect it has in interrupt mode.
A bare-bones Arduino ATMega328P chip will use just 0.2μA in Deep Sleep. Of course, achieving that depends on disconnecting just about every other bit of the circuit, normally done by a P-MOSFET (so the Arduino brings the gate of the MOSFET low and thus powers the rest of the system). Using any kind of "dev board" is a no-go unless it has been specifically designed for low power use. For example, ThingPulse do a low power version (15μA) of the ESP32 (called ePulse Feather) which is about as good as you can get with that chip. There's probably a low-power version for the Arduino too.
You need to add a line at the top of your sketch to include that libraty: #include "name of library here.h" and that should do the trick. Make sure the library is in your library folder!
@@RalphBacon i use Arduino IDE, i use exactly the code you use and it says that error. I try to find that library, I also write it at the top of my code still error
Where have you put the library? It should be in the libraries folder, which is normally a sub-folder in your sketches folder. Just to test it out, you could put the library files (not the folder) in the same folder as your sketch but it will be a bit messy!
The way you could do this is to set the alarm (programmatically) to 18:00h. On wake-up the Wemos does its stuff then sets the alarm for 18:15. Wash, rinse, repeat until 7h30 at which point it sets the next alarm for 18h. Remember that "wake up" in this context means a fresh reboot - you will have to restore any values you need in the setup( ) routine.
@@RalphBacon I was able to hammer it together, thank you. The ESP8266 needs a quick LOW pulse to its RESET pin in order to wake up from deep sleep, however, the pulse coming from SQW on the DS3231 stays LOW after the alarm is triggered until your clear the alarm flag and set a new alarm. Therefore, to convert this constant LOW into a quick LOW pulse, I used the "esp8266 dtr reset circuit" found online. As soon as the ESP8266 gets this pulse, it resets and immediately sets a new alarm, and SQW is HIGH again. I used the library by Rodan like you showed. Thank you again.
Hi, thanks for a very nice and very helpful deep sleep videos. I had difficulties using watch dog and thinking about using RTC instead. In the end i got everything working but questions arose. Why? I get it that from a person perspective waking up every 8 sec can be tedious but Arduino can not complain unless its programmed to. I havent cought it in the video(s), but is there some reason why should i be using RTC as a interrupt source instead of WDT worth that increased consumption? I understand that these tradeoffs depends the most on the project but are there some generall pros and cons for battery projects? Second question is just theoretical idea that iam not able to try because i dont have DS3231 in hands. Is it possible to disable I2C before sleep and enable again to save power?
The main advantage of using an external RTC to wake up a processor is that you can schedule (complex) timetables to do so. Eg, every 43 minutes, or twice a day or... you get the picture. You can, of course, wake up the microcontroller every 8 seconds using the RTC but the Arduino will have no idea of what time of day it is. The clock is not accurate enough to used as a RTC. So if you want something to fire up at 7am each day using the RTC is not going to be very reliable. Using an external RTC will give you that accuracy. Regarding putting I2C to sleep, if we're talking ATMega328P (Arduino UNO) you can put just about every part of the processor to sleep independently. For example, you can put the Analog part of the device to sleep, the Brown Out detection and the Serial UART. Sometimes you need to do this in a particular order, or within a certain number of clock cycles but it can be done. Nick Gammon has a lot about this on his website, you can read up on it here: www.gammon.com.au/power
@@RalphBacon Thanks a lot for a prompt answer and tip for a really interesting blog. Even though according to your explaination, it doesnt make much sense to using RTC for just periodical waking up, (f.e. every 15 mins) if i dont really care what time is it, i think i buy one to explore more. Thanks again for inspiration. Rabit hole here i come...
Under which stone do you come from ;) You can get 3400mAh and they are really 3400mAh tested it myself (Warning buy the good ones with proof from buyers)
I live in a cave, Albert. I don't get out much. Only Benny to visit me. And Dougle. So I am well behind the times as Henrik Jensen (comment below) has indicated with a very useful chart indeed. lygte-info.dk/info/batteryIndex.html
How to set the clock to 8MHZ IN ARDUINO IDE?? Because in Arduino ide default clock is 16mhz. Please give me suggestion, so that I can run an atmega328 without a crystal and program it using Arduino ide
I want to know if there is a RTC with a programmable register that tells the RTC how many ticks of the crystal to one second? The reason.. I want to make a RTC run a 24 hour day on Mars time... 1 Mars day = 24h 37m Earth time I want to do it in such a way, that I set it only one time using NTP,, then let it keep Mars time on it's own from that time going forward...
So you want a Mars RTC? I've never heard of anything that keeps anything other than Earth time, but you could program a simple Arduino (UNO/Nano) to keep Mars time instead. The downside of using any kind of electronics is that you will be hard pushed to run it on a battery like the DS3231 (pretty accurate). You _could_ put it to sleep for a second, wake up, do the necessary calculations and put it back to sleep again to enable running off a battery but an Arduino will still take several milliamps for the short period it is running. You mention using NTP to set the time (initially). That requires Internet access. If you don't need to run it on a battery then one of the small, newer ESP32 devices do this all automatically (for Earth Time) but you could easily run a simple routine to convert to Mars Time. The ESP32 gets the time from NTP periodically to ensure there is no drift as every microcontroller I've ever tried is not accurate enough for a clock. I'm wondering if a DS3231 that has been correctly set initially could be used with an ATTINY processor of some sort so it can run on a battery for months if not years...? Finally, if I were a Martian I would not say that my day is 24h and 37min (ie based on Earth time). It would just be 24 hours (or whatever the Martians agreed) and each "second" would be a longer-than-Earth second and so on. Now that could be programmed just by counting 'ticks' in a microcontroller (milliseconds) and then translating that to Mars seconds, minutes and hours. Just a thought.
@RalphBacon I want to thank you for responding to my crazy question. The NASA Mars Rover team runs on Mars time, so they know when the window to transmit to the Rover is open.. (Rover being on the Earth side of Mars) So in my scenario, if the Mars Rover had a spotting scope pointed straight up. Every time Earth passed the center field of view, would be noon.. (I know real Mars noon is based on the sun..not Earth) but I want a clock that would tell me when the Mars Rover was on the Earth facing side of Mars.. (6AM to 6PM Mars time) If I had to look it up every day, then there would be no point to using a RTC at all... My RTC is the Ds1307.. It has an error of 7 seconds a day, which means I would have to NTP 7 times a day to keep it accurate to the second.. I was hoping there was a RTC that I could tweak the tick counter to compensate for tolerance errors in the crystal... If it is fast by 7 seconds a day. How many ticks do I need to adjust by so it is accurate to 1 millisecond a day??? Do you know of any RTCs that have a tick count register to adjust how many ticks equals one second? Then I make a 24 hour Mars day = (24h 37m 22.5s Earth time) The only problem this would not fix is a Mars year is over 600 days but I would at least have the Mars 24 hour day worked out... I hope you could do a video on making a Mars clock to solve this problem.. One that you only need to set one time a year or better...
I'm afraid I don't know of a variable/programmable RTC, but the DS1307 is very poor at keeping time, which is why I mentioned the much more accurate DS3231. A daily NTP update is all you need, at most, perhaps even once a week is good enough. If you don't need to run on a battery (like the RTC does) then you can easily program your own Mars clock, ideally with a huge LED display so you don't miss a critical time (like the ones NASA uses when a meteor is about to impact Earth). Using an ESP32, it auto-updates from an NTP. Although you mention "Mars Time", you know how many seconds in a Mars Hour, Day etc so by using a standard RTC DS3231, you can just count the Earth seconds and create your own Mars clock.
@@RalphBacon My thought was to proportionally stretch the 24 hour RTC day, so it takes 24h 37m 22.5s to complete (or whatever the actual calculated Mars day is).... The problem with using (Earth time RTC) is knowing how many days expired since it was set.... Is it possible to edit the RTC library to stretch a 24 hour day? I would be glad to use another RTC... I was looking at the data sheet for the RV-3028-C7 (RV-3028-C7_App-Manual.pdf) and it looks like it has (calibration registers) to adjust Aging compensation with user programmable EEPROM Offset value (Factory Calibrated value may be changed by the user) but I don't know if I could add as much as 37m to a day.. My thought on making the RTC keep the time, is if I set it, I could put it away for a month or two and when I get it out, it is still on Mars time.. Anyway, thank you so much for your ideas.. I would love to see if such a thing is possible..
I was thinking more in terms of counting the seconds from a DS3231 (probably using an interrupt) via the 1Hz output pin, and then in the Arduino program incrementing the user-controlled secs/mins/hours/days etc according to Mars rules. That way, you have full control over all aspects of Mars time.
Hey LJ . No , I think Ralph did that as setting as output first will set the pin to high . Set as low first and it will start low . The way you are thinking will send a high pulse before going low . Ralph did explain this in a video , only I cant remember which one ... Maybe Ralph can remember or explain a little better ... :)
Karen is correct. By setting the HIGH/LOW first avoid any microsecond blip as the set the pin to OUTPUT and then digitalWrite it LOW. Nick Gammon (no relation) taught me this so who am I to argue?
Hi Ralph Bacon I have been following your video with great interest regarding “# 192 Wakey, wakey! Let the DS3231 RTC wake up your Arduino-easy! ” I can not program, but I can use your sketch for some practical use, and not just flashing LEDs. I have a sketch that runs on ESP32 and which is an Internet clock that is updated every minute, along with Temp. and Humidity from DHT 22, all of which are shown on an E-Paper display. Since I do not see or use the Internet clock at night, it was best that it is in Deep Sleep, as it is powered by a battery, thereby saving power. I could imagine that ESP32 Wakeup, for example, time 0800 and, and goes into Deep Sleep at 2300, and it can do that every day. I do not have the ability to combine the 2 sketches into one sketch as I do not have enough knowledge of programming, so could you help me with that? How do I combine Setup from the 2 sketches in one sketch, and the same in Loop, so that it can be used for something practical. With best regards Georg
Have we not had this conversation already, Geog? I'm sure I replied. Perhaps I just forgot to press SUBMIT? Anyway, to combine the sketches is fairly straightforward. Copy each line of code from the simplest sketch into the more complex one. Don't repeat stuff and make sure it works as you go by compiling and uploading. I've just done the exact same exercise copying my TFT Screen code into my Internet Radio code, testing as I went. A couple of hiccups (forgot an #include library) but other than that all sweet.
Very sorry, it's too time-consuming to add an actual schematic but I've added a new file describing how to connect the DS3231 to the Arduino. I'm sure it will help you. github.com/RalphBacon/192-DS3231-Wake-Up-Arduino
The ESP8266 does things a different way, when waking from Deep Sleep. It just "reboots" and there is a flag that the developer can read to detect it is, in fact, rebooting from so-called Deep Sleep rather than just being switched on at the plug. The only way it can "remember" values is by writing them to the RTC's RAM area before it goes to sleep. But it doesn't resume execution from the next statement in the sketch, it just starts the sketch from the very start. Not so great. But the DS3231 could trigger the reboot, I guess. Watch video #116 (ruclips.net/video/NgPwPKXCLFY/видео.html ) to see if that gives you the answer.
Thanks for the interesting video Ralph, I actually use these RTCs with all my IoT sensors around my house but it did take some time to get a fully working & stable device for my needs, i.e.extremely low power use.
Without posting my schematics the basics of my system are as follows:
Sensors are powered via 2 x 18650 cells in parallel for capacity not voltage which go to a ultra low Microchip 3.3v LDO
The output of the LDO is connected to a P- Channel MOSFET & the gate of the MOSFET is connected to the INT/SQW pin of the RTC (DS3231)
(all this time, my ESP8266 & even the RTC itself has no power, the RTC purely running on CR2032 backup)
When an alarm is activated, the gate of the MOSFET is pulled low which then sends the regulated 3.3v around the circuit.
ESP8266 is powered on, takes a reading and sends this reading to the main unit located elsewhere via ESPNow, ( the main unit is connected to a permanent supply & connects to the internet to upload the reading), sets a new alarm for the RTC and then shuts down to wait for the next wake up call. The MOSFET gate is then sent high once again & all powere is removed from the circuit.
RTC is now running on battery backup again.
There are a number of caveats though that mean some modifying of the DS3231.
The 472 resistor pack located above SDA & SCL pins on the RTC have to be removed & make sure that there are SDA & SCL pullup resistors on the board being used, good thread here:
forum.arduino.cc/index.php?topic=537675.0
For super low power removal of the LED on the DS3231 is also a great idea.
Plus a necessity for anyone who uses these RTCs is to remove/disable the inbuilt charging circuit.
These RTCs come ready to accept an LIR2032 rechargeable battery, most people find these inadequate and fit a regular CR2032 non-rechargeable battery in the holder. The problem is that there is a charging circuit on the unit, not a good mix with a non-rechargeable battery installed.
For simplicity I just removed the 200ohm resistor on my RTC, some people removed the whole circuit though.
More details here:
thecavepearlproject.org/2014/05/21/using-a-cheap-3-ds3231-rtc-at24c32-eeprom-from-ebay/
Cheers..,
Very interesting. I also got the P-channel MOSFET of a Si4599 to go LOW via the SQW/INT pin of the DS3231, and the current required was in the order of 3µA. I'm guessing that when you clear the alarm the open-drain MOSFET on the DS3231 goes high again which is enough to turn the P-channel MOSFET off again? Neat. Thanks also for all the other current saving techniques, every µA counts!
Very clear and informative as always! Thanks Ralph.
Glad it was helpful!
There is one interesting thing about these DS3231 modules. They are trying to charge the CR2032 battery! I can't remember where I found the schematics of this module and noticed this couple of years ago, so I can't give a link. But you need to remove one 200 ohm resistor right next to the SCL pin on the 4 pin connector side. It is between the MELF diode and the SCL pin. Both the diode and the resistor are in on this very wrong charging circuit, so you can remove either or both. This may also be the reason of higher than expected current draw.
Or you get rechargeable cells
I even have one with a rechargeable battery still in it. Dead as a dodo now of course. I will check whether the charging circuit is still included on mine and remove the resistor/diode. Good information, thanks for posting.
@@RalphBacon www.onetransistor.eu/2019/07/zs042-ds3231-battery-charging-circuit.html
I spent 2 months in lockdown messing with this stuff trying to build a temperture/humidity data logger with a mini pro, got current consumpion down to around 3mA when sleeping which is still very high.
alot of help from thecavepearlproject.org/2014/05/21/using-a-cheap-3-ds3231-rtc-at24c32-eeprom-from-ebay/
Desoldering the led and charging resistor and the vcc leg of the 3231 chip make a massive difference but you need to power the leg from an arduino pin when reading and recording data
And Nick Gammon site was also very helpful
gammon.com.au/forum/?id=12106
He claims less than 7 micro amps for his logger
@@Ed19601 check this site for reasons not to use the charging circuit on these boards thecavepearlproject.org/2014/05/21/using-a-cheap-3-ds3231-rtc-at24c32-eeprom-from-ebay/
Excellent addition to the previous videos. Thank you.
Glad you like them! Nice to hear from you, Simon.
Excellent video! I did a breadboard/bare bones project like this, and ran into the RTC eating too much current during sleep. My solution was to power the DS3231 from a pin on the microcontroller. Before going into deep sleep, I set the pin low, then set it as an input without pull-up. I think I got to around 40 microamps. The DS will still trigger the low alarm signal, so having the Int pin with internal pull-up is necessary. Runs for around 16 months on 3 AAA batteries I think.
Nice work! 16 months on 3 AAA batteries is pretty good. I tried powering it from an Arduino pin but got strange results and I was pushed for time. Nice to hear it can be done by you Andrew. Thanks for the post.
@@RalphBacon You're welcome! One thought: Did you remove the charging circuit from your board? The diode/resistor pair near the auxilliary SCL connector form a (really bad) charger from Vcc direct to the battery. (From memory, the boards are meant to have a rechargeable 2032 but usually have a CR2032, but in any case the charger is inadequate/dangerous depending on Vcc) I'm wondering if that would pull down the GPIO pin's output too much? Out of interest(?) my proto board also had a tiny OLED display for setting the clock and some other parameters for my project (environmental air sampler), so I used the same trick for that with a GPIO pin to power it during setup. You've got to love this stuff!
I didn't but plenty of viewers reminded me to do so!
great !
by any chance can you share diagram and code please ?
@@ighost_1337 should be able to. It was a work project, so I'll check if anything needs stripped before sharing. Drop me a message in a few days if I don't respond again! Cheers.
Great job as always Ralph.
Thanks again! Nice to hear from you Steven.
I live in rural Michigan. I wish I could find any electronics locally. Everything I get comes from Aliexpress. :P
Thanks for the awesome tutorials. I've learned so much since I found your channel recently. Thanks Ralph!!!
Glad to help! Note that Amazon also sell some stuff (yes, source from the Far East, too) which might be an option for you. And you have the "big boys" such as Digikey, Mouser and so on.
Bugger, I just bought a handful of 1307s! Need to get my hands on some 3231's now (not that I need them, but I love this function)!
Ditch the 1307s, Nick. I have some still and will never use them, they lose seconds per day and are not temperature compensated (so they get more inaccurate the hotter it is, during the summer, for example). Sad but true.
@@RalphBacon Bloody hell! I had no idea. Thanks very much for the heads up. I'll keep a couple for the archives and bin the rest!
Thoroughly thorough !
All bases covered then, Andy? Great!
I used a similar idea to save power when using a venerable PIC 16F84A to make something similar to the "who got in first" device used on quiz shows. The B port would be set up to trigger an interrupt on a button press, then the Sleep instruction executed to put the processor into a low-power state. An interrupt would wake up the processor and the interrupt routine would simply return, allowing the rest of the program to continue (check for which button triggered the interrupt, light up a LED to show which button was pressed and make a sound by bit-bashing a port, then go back to sleep until a reset is received).
Sounds like a decent PIC project (ah, memories, memories). I don't do any PIC work now, shame.
@@RalphBacon They're fun to play with. my next project was making an 8-pin PIC produce a single-bit "white noise" output by internally simulating a 32-bit ripple counter with XOR feedback, effectively making a pseudo-random number generator.
My latest project has been programming an Arduino Nano to drive a 32x8 Neopixel display with static text and a colour-changing border.
It's all fun, until it comes time to put a box around it... sigh.
Thanks for all the videos Ralph ... I have learned a ton from you .
Very much appreciated ... :)
Glad you like them!
@@RalphBacon
Very much so ...
Been meaning to say thanks for ages...
Been very helpful ... :)
Thanks A TON! I ran across your video whilst searching for anwers on why my interrupt wouldn't work. I was forgetting to clean the flag bits
Glad I could help!
I was waiting for today's video, an even without watching, i know it will be something usefull..
Hey i was first :-)
Hope you enjoyed it!
Great video! Thank you for the detailed explanation and for pointing to the right library
You're very welcome!
Been looking at making a birthday clock using a DS1307, promini and 16x2 lcd and came across your video as I was looking for more info on the use of structs.
In some ways seems simple enough but it can get rather deep rather quickly and hence loss of understanding.
So a list of names and the day and month of the birthday and then display something like "happy birthday johnny" ...other times just display the time etc. I guess or "no birthdays today".
I'll keep at it.....cheers Jeff
Don't use a DS1307, Jorgo, they are notoriously inaccurate. A DS3231 is much, much better.
The way to approach a project like this is to split it up into logical sections. Get each section working without worrying about whether the time is 4 pixels too far to the right!
So, I would:
1) Get the LCD working. Display HELLO WORLD on it. That proves your I2C is working too assuming you are using one with the extremely useful "I2C backpack" which I covered in a recent 'Bacon Bytes' video.
2) Read the date/time from the DS3231 (Getting the date/time INTO the DS3231 is another task). Display it on the (working) LCD. Ignore the fact that it's the wrong time and date. You will need a TIMER TASK to run a function every minute to update the time.
3) Find out how you set the date/time on an DS3231. It's best to do this in a SEPARATE sketch otherwise you run the risk of overwriting the real date/time with some past date/time in your code. Don't ask me how I know this!
4) Decide how you will store the birthday info. On an SD card? Whilst you _can_ hold such info in EEPROM, that is more difficult initially. Updating an SD card is easy on your PC/Mac and then just read it in the sketch.
It would take me probably a few days to do all this so that I had a working prototype. It might take you considerably longer. The best advice that I can offer is to do the tasks one by one and get it WORKING well enough before moving on. And watch my video #BB9 about organising your code, you will thank me! Good luck!
@@RalphBacon Hi Ralph...thanks...covered up to point 3 and will take a look at your link. Had been looking at storing [10] birthday names with day and month in progmem in a struct but how to retrieve is yet to come. I guess a "for loop" to check the now time and compare. Anyhow, onwards and thanks for the link. Cheers Jeff
Observation: the pull-up resistors are not only applied to I2C's SCL and SDA, but to SQW. The DS3231 chip supplies SQW on an open drain, but the board with its pull-up resistors connects SQW to the board's Vcc, and Vcc is connected (amongst other things) via the LED to ground. That means that when the RTC is running on its button battery (no power on I2C), volts (from an external source) applied to SQW are attempting to power the LED and other bits of the board, and current is draining from the external source even while the alarm has not yet fired. Which rots my socks.
Probably explains the higher-than-expected current drain.
If you have a power-critical application, a simple ultra low power timer like the TI TPL5010 would be a good way to go. You could power down the RTC just before going into deep sleep, and the timer would draw 35-50 nA until it wakes up the MCU. You'd be limited to sleep times of 2 hours (for this timer anyway), but most applications need to wake up more often anyway. And if you need to wait until a specific time of day, you can set it to wake periodically, wake up the RTC, check the time, and go back to sleep if the time isn't met. With sleep intervals of more than a few minutes, you'd still gain a lot of battery life.
Indeed, Chris, 'tis true and I did video #125 on the TPL5110, there are many roads to Rome. ruclips.net/video/Qms_iEL7Uqg/видео.html
@@RalphBacon Nice!
Great video btw! excellent explanation.
Glad you liked it!
I think, when the DS3231 is powered from external source (5V of Arduino) and the vcc is higher than the coin cell voltage, the coin cell is being charged from that external power source, hence the higher consumption. I think I read it in the data sheet.
You are correct, Milen. The charging circuit is present and will attempt to charge a non-chargeable battery (eg CR2032) if fitted! One of my DS3231s actually has a rechargeable battery still fitted. I must remove the charging circuit resistor to avoid any unpleasant surprises with that coin cell. Thanks for posting, good to hear from you.
Been watching you for a few years now and I like the way you over-explain everything. It really helps people get what you mean. I love yer new shop for doing yer vids. Did you need a permit for that? I made a greenhouse and Melanie " Low Vision Life"thinks I needed a permit for that. Wadda ya think?
It's nice you are still with me on my Arduinite journey, Drex! My "new" workshop (now two years+ old) did not need a permit as it is less than the permitted 2.5m high (when near a boundary, ie fence) and is classed as a "shed". I could have had it bigger (if I had more room next to my house) and still not need a permit. The rules have relaxed in the last few years.
Ralph S Bacon As others have said, the cave pearl project is a mine of great information.
Hi Ralph great video again. I do a lot of deep sleep projects for farm sensors running on AA batteries so always interested in new ideas. I think if you are serious about deep sleep performance you will need to use the DS3231 IC rather than the module, only turn on the pull ups when you need to reset the Alarm. Then you could use the alarm to power on rather than wake up the uC. Although it sounds silly waking every 8 seconds its actually hard to beat for consumption the power lost is less than normal battery losses for time and requires an oscilloscope to detect it has even happened. I have sensors waking every 30 mins to sample and send long distance via nRF24 and lasting 18mths +...
Absolutely, Andrew. I do believe I originally mentioned this only to cut it out - using a module is within the grasp of most Arduinites, soldering a 16-pin SMD (of which only half the pins do anything) is a soldering iron too far! Yes, the power consumption thing would have to be measured very accurately to determine whether this method was better than waking up every 8 seconds. But your empirical evidence makes it sound that the WDT method still has merit (and no extra hardware required). It's a pity no Chinese manufacturer has made an Arduino clone with a DS3231 built in.
@@RalphBacon that sounds like a challenge, perhaps i should make one. First i will do ther theoretical math based on the data sheet. To see if it has any chance of being better at power consumption. Thanks again n for the great video
Or do what others have suggested here: desolder the EEPROM chip, remove the battery charging circuit resistor (and diode too if you want), power the VCC to the DS3231 from the Arduino GPIO pin. Job done. I'll try all this soon. You first!
@@RalphBacon FYI using CurrentRanger and Oscilloscope i can see that it takes 16.3ms for each 8sec wake up which is 3min 1sec perday 18hr per year. For my 10ma project thats less than 10% of 3 AA batteries in a year. The lowest standby for ds3231 will use~50%. So no chance of being better.
So there we have it, a scientific reason to keep using WDT. But I guess this is another way of doing it... right? Right?
You are not up to date on LiIon batteries, the 18650 is up to 3400mAh and 2000mAh is not very common.
I have been testing LiIon batteries the last 8 years, this table shows brand and capacity and links to a review of each cell:
lygte-info.dk/info/batteryIndex.html
A very useful table. Thanks for posting. Bob
That's both useful and an eye-opener for me. the last 18650 batteries I bought were in 2018, 6 x Samsung 2500mAh for the princely sum of £22. Things do change quickly in the battery world these days.
Great video as always. Have you calculated how much power it would take to just use the watchdog timer, wake up every 8 seconds, increment a counter, check for 10,800, and go back to sleep. If you did not need "real" time, it might take less power then running the I2C lines.
I haven't but Andrew Toogood (comment below) has Real Life experience of using the WDT and thinks it the way to go. They switch on so fast and go back to sleep again that he needs an oscilloscope just to prove they work up! I can't argue with that!
Warning !!!!!!!!!!! The module (DS3231) is delivered with a CR2032. This is a lithium battery.
That would be no problem if the module did not have an armed charging circuit. During operation, the input voltage of the module is on the battery, and this can also be 5 V. The charging circuit can be removed by removing the diode (red) or the 201 above or by interrupting the line.
Indeed, Thomas, and you're not the only one warning me (and others) about this. Crazy design decision.
@@RalphBacon What do you make of MAXIM's statement on the DS3231 datasheet "The device is UL recognized to ensure against reverse charging when used with a primary lithium battery." Is there evidence of problems, rather than a theoretical concern? (I sound like Dr. Fauci.)
This should be a pinned comment.
Another good video thanks,
the ds3231 module along with a EEPROM has a diode and resistor from 5v to the battery adding a sleep drain along with the I2C resistors. Working days and weeks ahead is a pain unless have UNIX time a count of seconds and decode void to convert back to time format ts. The time library does this ? Graham
The Time library (or something very similar) does this, Graham, as I use UNIX time in the HomeAlone project so it will be an #include in that code. Whoever is interested, that code (2,000 lines of it) is in my GitHub.
Yes, others have mentioned the charging circuit (which I had forgotten about, even though one of my DS3231 actually has a rechargeable battery in it).
Good stuff here! Given that you mention that I2C is only good for distances of ~1 meter or so, what would you use to go further? I saw mention in one comment about "stuff all around the house", what would you use for something like that?
WiFi is the obvious thing to connect stuff around the house, roy, although if you really wanted a wired connection then RS485 is robust (I even did a video on it, #106). You can get extenders for various protocols too, that all run on CAT5/6 cable, which convert the signal from one protocol to another and back again. That way you can run I2C over hundreds of meters (see learn.sparkfun.com/tutorials/qwiic-differential-i2c-bus-extender-pca9615-hookup-guide/all ). WiFi (if you have decent enough signal) is the "cleanest" method though.
Thanks for these well presented and clear videos. I'm teaching myself simple electronics and find certain Arduino projects really helpful. I plan to use this RTC video on one of my tasks, but only need a "wake up" at the same time each day. In this case do I still need to "set next alarm" each time the sleep pin goes low.
I don't think the alarm is held over to the next cycle (unlike your bedside alarm clock) so you need to set it each time. Pretty sure, but best check the datasheet or just try it out!
@@RalphBacon Yes I will. Thanks for the quick response. I am still having problems getting it to repeat for the first time. I'll get there, and let you know. It's just that you said somewhere in the video that the DS3231 held the data permanently and I assumed that once the hour/min/sec was set it was there until the battery ran out. I still need to work out what I am doing wrong. It works fine on day one, but seems to stall after that.
Grand video. A couple of thoughts to save current. As the DS3231 has a backup battery would powering the DS3231 from an arduino pin then allow you to cut the supply in the go to sleep sequence [I dont know if that affects the alarm out pin]. Second idea, would wire.end() de-energise the I2C just ahead of sleep, then wire.begin() on wake up?
Best to keep the DS3231 on its own 3v battery - it will last for at least a year. And, yes, it needs the power to function (ie create the alarm, of course). does Wire.begin/end control the power or just start the protocol?
Do you just send SQW --> Gpio something and detect the low in software?
Yes. The Arduino is in Deep Sleep (suspended, effectively) but will be woken by a LOW signal on the chosen GPIO pin because your code told it (attachinterrupt etc).
I made a box to remind the boss to take her medication at breakfast every morning using theDS3231. Great chip. Remove the resistor array to kill the EEPROM (big blob of solder took the whole thing off!) and cut power track. Using Lidl AAs, it’s still going strong 16 months later (so is she!). It flashes a LED every 3 seconds until she stops it. This battery calculator is much better for this type of project oregonembedded.com/batterycalc.htm.
And you can power the DS from an Arduino pin and switch it off before sleeping. Interrupt still drops on alarm!
I wish I had found that battery calculator page! Yes, I guess removing the EEPROM and the battery charger circuit would do wonders for the current consumption. I will have to modify my one to do this and re-measure. Now, I tried powering the DS3231 VCC from an Arduino GPIO pin but got weird behaviour so I didn't mention it during the video. I'm glad you said it works OK so I will retry that. Great information, thank you.
Oh those library names... You wouldn't believe just how many libraries out there called LiquidCrystal_I2C...
Yes, I can believe it. So annoying.
Another lovely informative video
Glad you enjoyed it
Great video with loads of information. Can one use the same alarm wakeup method for the ESP8266 / ESP32?
See my reply to Mr.Chauhan regarding the ESP8266. I've not done a Deep Sleep on the ESP32 yet so I don't know if this will work or not.
@@RalphBacon Thought I'd report back. I tried this on the ESP32 and it works like a charm. I used the esp_sleep_enable_ext0_wakeup function
For even more power saving, would it not work to try and use a Si4599 as part of a power latch circuit? I recently watched your other video on power latches, and it seems that a N channel and P channel mosfet can be used, is this not what the Si4599 provides?
Report back: I tried it out and it works great. The Si4599 is a small chip and cheap, this works really well as a power latch. Thanks Ralph, I wouldn't have known about it without your videos
Please pardon the intrusion for jumping on this thread but I'm quickly approaching the end of my reason and am no closer to a solution. I have watched ALL of your low/save power Arduino videos but I don't have the knowledge to use the info effectively.
I am trying to build the most efficient battery powered circuit that will illuminate a LED when movement is sensed by a PIR. This will only happen during 'night' hours meaning start at 4pm in winter & 9pm in summer. My idea is that it would power off at say 12am and then repeat 24hrs later. I acknowledge thast the change from winter to summer time will be manual.
My proposed solution is ...
Use Arduino to programme a RTC with actual time together with relevant start and finish alarms.
@ Alarm 1 the RTC (running 100% on internal battery) will send a signal to the gate of a BJT.
In response the BJT will switch power to a PIR.
When the powered up PIR senses movement it will send a signal to a 2nd BJT.
This second BJT will switch power to the LED for as long as movenment is sensed.
When movement stops there will be no signal from PIR to 2nd BJT thus cutting off power to LED.
Process continues until Alarm 2 when the RTC will stop sending a signal to the first BJT.
No power will flow until the Alarm 1 is triggered the next day.
Is this possible?
Am I thinking about it the wrong way?
Can an RTC alarm be used as described to stop a singal being sent to the first BJT?
I love the comment (from another project)... "It's impossible to over-engineer hobby projects" 😂
Again I do apologise for the hijacking but desperate people do desperate things at desperate times.
I feel your frustration but, as always, there is a technical solution, just maybe not the one your were expecting!
Whether you can _directly_ power an LED (I'm assuming a proof-of-concept 5mm LED?) from the PIR, rather than use a microcontroller, I cannot say as I've never done it. Using a BJT might work, but again it's not a path I have trod before. Sounds plausible.
You can certainly use an RTC (DS3231) to switch on (and off) something like an Arduino ATMega328p chip (not the board, like an UNO, as that consumes far too much current). As the RTC is independently powered, usually by a 2032 button battery) it won't cause your main power source to become depleted.
The PIR needs powering too and from what I recall they are not so low-power friendly. Usually, you would have to either power continuously or *use a solar cell* during the day to charge a Li-Ion battery for use overnight. The PIR needs to be active during all the night hours so current consumption becomes a factor.
The advantage of a rechargeable circuit is that Arduino chip can also be powered from it, albeit only when the PIR detect a movement, sends a signal to the Arduino to wake it up from Deep Sleep, light LED for as long as it gets the PIR signal, and then go back to Deep Sleep (the ATMega328p only needs < 1μA when in Deep Sleep).
TL;DR my take on this would be to use a solar/rechargeable solution, with a standard Light Dependent Resistor (LDR) that determines when the circuit as a whole should run. Thus, no need for an RTC at all. There are millions of light-level switch circuits out there on the Internet (basically a comparator circuit).
This LDR circuit could then trigger and power an ATMega328p chip with minimalist circuitry just like my demo. It would be in Deep Sleep for 99% of its life but would wake up when triggered by the PIR's output. That would then control the LED whilst it was getting the trigger (and could extend the light's duration, just like your security light). A BJT might be all you need at this stage, no μC at all!
Whilst using discrete components as you suggest _might_ be possible, it's not the way I'd do it. Whilst you mull over some possibilities I'll try and see whether I can devise an analog circuit with a DS3231 and PIR to do what you initially proposed.
@@RalphBacon
Thank you, Ralph, for taking the time to consider my post and reply.
I have sucessfully driven a LED via a BJT (2N2222) from both PIR #1 & PIR#2. I haven't yet tried this on P1R#3 - see below.
Are you saying that an RTC (DS3231) via a second alarm can effectively stop sending the signal from the first alarm? If so, this is very encouraging.
It is my intention to power both PIR and LED from the same battery.
To date I have looked at three PIRs...
PIR #1 is an HC-SR501 which uses 65mA. However this model can be set up to continue sending a signal while it senses movement.
PIR#2 is an AM312 which is marketed as Low Power. In my experience this is very low power & does not have the option to set a delay.
P1R#3 is a RCWL-0516 which uses microwaves and is very low power. It generates a 3.3v output but no control over the delay time.
This particular project is not solar friendly. I am trying to draw attention to a sign when a person enters a corridor. The corridor has windows and the sign is obvious during daylight. However, it is easy to miss under artifical lighting. While access to the project is fine unfortunately there is no convenient source of AC power.
I think I'd be able to complete the project using a bare bones Arduino (and I probably will for practice) but at this stage I am trying to design the simpliest solution I can think of.
So having scribbled out a diagram or two, it quickly became apparent that doing this with analog/discrete components without some sort of microcontroller was becoming far too complex.
Then I had the thought to consider how my garden ornaments lit up at night; most were solar powered (charging during daylight hours) but we also have one, battery controlled PIR light that works very effectively.
It's a commercial device, cheap and there are unmpteen variations on the format and design, but all fall within your brief of a battery-powered device that lights up something when movement is detected during the hours of darkness. Here's a link to what I have, but as I say there are many of this format: amzn.to/3vzqgdd
There is one downside to this particular device (and, come to think of it, many of this type): they are easily detachable (mostly magnetic) because they need regular recharging via a USB port or need new batteries now and again. Great for the home user, maybe not so great for a public place with light-fingered visitors? You may need a different format device or some way of securing it (which might include placing it high enough so that it cannot be reached without a ladder, for example).
I hope this "blue-sky", "out-of-the-box," "pushing the envelope" thinking may help you in coming up with a solution that is cheap and easy to install! Sometimes the easiest solution if one that has already been thought of and manufactured.
Thanks again for your time and recommendation.
I assume the PIR becomes live when ambient light is low i.e. when it gets dark.
I'm trying for a situation where the PIR becomes active within defined on/off times.
My original goal was to design the simplest project possible but it looks like I will need to include an AtMega328 chip to achieve that.
Thanks again
Is it possible to power on arduino with this alarm clock? I mean, when using mosfets to completely shut down the arduino, then start it with an alarm from the DS3231
If you combined this with my Auto On/Off circuitry (or variant) you could do it:
#173 ruclips.net/video/S2y1oAVmxdA/видео.html
A better way would be to build your own Arduino UNO with a bare chip (only requires about 5 components) then put it into Deep Sleep which consumes just 0.2μA. Wake upon external trigger.
How do you program the chip, do you put it back in a UNO upload the sketch then pull the chip and put it in the little test mule you built? Or do you have to play around with one of those finicky FTDI things?
When I design a circuit I allow for the ICSP connections (so the SPI pins, basically) and use a standard programmer (or an Arduino-as-ISP) to program them.
Once you have used an FTDI (USB-to-Serial device) a bit, you'll find them a lot less finicky I assure you!
Great video! What programming software are you using? It's not IDE. I like that you can collapse the remarks.
In this video I'm probably using the Eclipse (Sloeber) but that's now dead in the water. I recommend the new Arduino IDE 2.0, now available as Release Candidate 5 (so very, very nearly done).
Get it here: www.arduino.cc/en/software#experimental-software
another great video, BTW how is Benny?
Not so good, right now, fingers crossed he will recover. Thanks for asking.
At 3:42 you say, referring to setting an alarm time "you can have days weeks MONTHS hours minutes seconds" but neither alarm1 nor alarm2 allow for MONTH. Maybe in a short month you could specify a day of month of 31 and not alarm at the end of the current month (I haven't tried that), but there is no alarm register that will accommodate a month number (or year number, for that matter).
You are right, the granularity stops with days. Which is a shame really, because if you wanted an annual or bi-monthly reminder it can't be done (easily).
@@RalphBacon Thirty days hath September / April, June and November / All the rest have thirty-one / Except February which hath but twenty-eight days clear / or twenty-nine in each leap year. :)
Calculating a leap year:
Divide the year by four. If it does not divide evenly, it's not a leap year, otherwise go to the next step.
Divide the year by one hundred. If it does not divide evenly, it's a leap year, otherwise go to the next step.
Divide the year by four hundred. If it does not divide evenly, it's not a leap year, otherwise it is a leap year.
Yes, it's complicated. The complexity is because the Earth's orbit around the Sun isn't an exact number of days. It's _almost_ 365 and a quarter days, but not quite, which is why a leap year has to be skipped every so often.
Hi Ralph, old one i know but I get conflicting info and thought you might know. I'm changing from a DS1307 to a DS3231 RTC and one aspect is, some say a rechargable LiR2032 is required rather than, like you use here, a CR2032.
Most also say no need to change anything with the includes etc. as this ds3231 will work the same. Any comments?
Used wire.h and RTClib.h and RTC_1307 rtc;....also have a 1602 i2c lcd on library hd44780.h as I'm told this is a far better library for the display.
Reason for the change is due to the time drift on the ds1307.......would like to keep it as is but cannot find a simple way to correct it from time to time externally(up down buttons)
The DS1307 should be withdrawn, it is very inaccurate. Hence the DS3231 which is super accurate.
You do NOT need a rechargeable battery but some boards do include a charging resistor on the DS3231 modules which should be removed if you are using a standard CR2032 battery. If you don't remove it I'm not sure any bad things happen; the voltage will simply be used instead of the battery, I guess... (if your house burns down do not blame me, though 😲)
I haven't used library hd44780.h as the one I use does everything I need, but no harm in trying it out!
Great video, perfect and detailed explanation. And it works .... unit you do something more in the "I am awake" state. Adding DHT11 reading, Writing to an SDcard, a Delay(2000) and .... everything stops with me. Any ideas?
When you say "stops", what do you mean?
You need to put in several Serial.println statements so you know at what point the code got to before not getting any further.
Are you sure you used the exact code of my demo (including the "don't go to sleep again until I tell you" line)?
Now it works OK. My code here: github.com/mitjad123/IOTarduino/blob/main/DHT11-SDcard-DS3231, fritzing: www.dropbox.com/s/5yowvr9a5iqoxns/Schematic_arduino%20pro%20mini%20ds3231%20dht11_2021-01-27.pdf?dl=0
I did try this sketch but it seems that the wakePin is changing state constantly, meaning goes to sleep and wakes up in milliseconds ! any idea why ? i used the same rtc module with an Arduino Uno.
If the wake pin is suppose to go LOW to wake the device, ensure you have either defined it as an INPUT PULLUP or have attached a 10K resistor from it to VCC.
Holey cow! Right when you pulled the power wire my video stopped! Could you hear me screaming "plug it back in"?
I heard you! Spooky!
Another brilliant video.
Glad you enjoyed it
Enjoyed your video, but I have a slightly different problem that I think you can help with. I am trying to wake up a ESP8266 12-E NodeMCU with the DS3232 Alarm and haven't been able to make it happen. I have not been able to find a wiring diagram that works. My sketch sets the alarm(s) and they fire as directed, but I have not been able to wire the SQW pin to the ESP8266 RST pin and make the wakeup/reset work. I think I have tried every combination of transistors/resistors/etc. but nothing seems to work. My aim is to use ESP.deepsleep(0), but can't get the alarm to reset even when the ESP8266 is awake. Your help would be appreciated. John B.
Such a long time ago, John... my brain is foggy. I covered Deep Sleep for the ESP8266 in video #118 (ruclips.net/video/NgPwPKXCLFY/видео.html ) and I seem to remember that the RST pin had to be held LOW for a minimum period; I'm not sure the SQW output is LOW long enough but you could prove this pretty quickly I'm sure with a 555 monostable getting its wake up from the DS3231 which then provides a much longer pulse for the ESP8266. If you just short the RST to GND does the ESP8266 wake up OK?
@@RalphBacon Thanks for your reply. Yes it does wake up (restart) when connected to GND. I don't do much EE type stuff but I can tell you what I see. When I measure the SQW output I get 3.5v and same for RST. When SQW alarm fires SQW drops to 0v and after the alarm it goes back to 3.5v. It is a very short pulse. If I connect the SQW to the RST it locks up the processor until I disconnect the wire. I've never used the 555 monostable and only know what I have learned on the web over the last two minutes. Do you have a video explaining it? Thanks again, John B.
I haven't done such a video (other than my 555 watchdog) but if you email me (my email is in the About tab of my channel - but not from a phone) I'll send you the best book on 555 timer chips that you can peruse.
What I do not understand that sleep current consumption in this video is not verified with multimeter.
I'm watching this with pretty much the same setup and Arduino Pro Mini 3.3V (basically Atmega chip, efficient, but weak voltage regulator unable to provide high current for SD card for example, reset button, oscillator, few capacitors and resistors and nothing else), trying to resolve issues which either do not exist in your setup (due to code differences or I omitted something). But first mistake I can see is that battery charging circuit is not disabled which may add few milliamps extra to overall power consumption at 5V because battery is being charged (regardless CR2032 is not rechargeable). Other problem is that in this exact setup, RTC circuit consumes roughly 90uA and Arduino 60uA with ADC disabled. I'm not sure why Arduino consumes so much. When I tried to remove VCC from RTC powering it from pin, it switches to battery, but also interrupt goes to low at this moment so falling edge is not detected or interrupt is triggered briefly after arduino enters the sleep. Another problem is that BOD has to be disabled within few instructions before entering sleep, but with power consumption being 150uA in my setup, I don't bother to save maybe 10uA.
Weirdly I checked The Cave Pearl project which mentions that 90uA as well, but it also mentions that RTC can be powered via digital pin, without mentioning interrupt. I can try to set BBSQW bit on, it's undocumented what effect it has in interrupt mode.
A bare-bones Arduino ATMega328P chip will use just 0.2μA in Deep Sleep. Of course, achieving that depends on disconnecting just about every other bit of the circuit, normally done by a P-MOSFET (so the Arduino brings the gate of the MOSFET low and thus powers the rest of the system).
Using any kind of "dev board" is a no-go unless it has been specifically designed for low power use. For example, ThingPulse do a low power version (15μA) of the ESP32 (called ePulse Feather) which is about as good as you can get with that chip. There's probably a low-power version for the Arduino too.
i got compilation error it says: Compilation error: Arduino_Sleep_DS3231_Wakeup.h: No such file or directory
how to fix this?
You need to add a line at the top of your sketch to include that libraty:
#include "name of library here.h"
and that should do the trick. Make sure the library is in your library folder!
@@RalphBacon i use Arduino IDE, i use exactly the code you use and it says that error. I try to find that library, I also write it at the top of my code still error
Where have you put the library? It should be in the libraries folder, which is normally a sub-folder in your sketches folder.
Just to test it out, you could put the library files (not the folder) in the same folder as your sketch but it will be a bit messy!
Can it wake up a Wemos D1 from deep sleep every 15min from 18h to 7h30?
The way you could do this is to set the alarm (programmatically) to 18:00h. On wake-up the Wemos does its stuff then sets the alarm for 18:15. Wash, rinse, repeat until 7h30 at which point it sets the next alarm for 18h.
Remember that "wake up" in this context means a fresh reboot - you will have to restore any values you need in the setup( ) routine.
@@RalphBacon I was able to hammer it together, thank you. The ESP8266 needs a quick LOW pulse to its RESET pin in order to wake up from deep sleep, however, the pulse coming from SQW on the DS3231 stays LOW after the alarm is triggered until your clear the alarm flag and set a new alarm. Therefore, to convert this constant LOW into a quick LOW pulse, I used the "esp8266 dtr reset circuit" found online. As soon as the ESP8266 gets this pulse, it resets and immediately sets a new alarm, and SQW is HIGH again. I used the library by Rodan like you showed. Thank you again.
Hi,
thanks for a very nice and very helpful deep sleep videos. I had difficulties using watch dog and thinking about using RTC instead. In the end i got everything working but questions arose. Why? I get it that from a person perspective waking up every 8 sec can be tedious but Arduino can not complain unless its programmed to. I havent cought it in the video(s), but is there some reason why should i be using RTC as a interrupt source instead of WDT worth that increased consumption? I understand that these tradeoffs depends the most on the project but are there some generall pros and cons for battery projects? Second question is just theoretical idea that iam not able to try because i dont have DS3231 in hands. Is it possible to disable I2C before sleep and enable again to save power?
The main advantage of using an external RTC to wake up a processor is that you can schedule (complex) timetables to do so. Eg, every 43 minutes, or twice a day or... you get the picture.
You can, of course, wake up the microcontroller every 8 seconds using the RTC but the Arduino will have no idea of what time of day it is. The clock is not accurate enough to used as a RTC. So if you want something to fire up at 7am each day using the RTC is not going to be very reliable. Using an external RTC will give you that accuracy.
Regarding putting I2C to sleep, if we're talking ATMega328P (Arduino UNO) you can put just about every part of the processor to sleep independently. For example, you can put the Analog part of the device to sleep, the Brown Out detection and the Serial UART. Sometimes you need to do this in a particular order, or within a certain number of clock cycles but it can be done.
Nick Gammon has a lot about this on his website, you can read up on it here: www.gammon.com.au/power
@@RalphBacon Thanks a lot for a prompt answer and tip for a really interesting blog. Even though according to your explaination, it doesnt make much sense to using RTC for just periodical waking up, (f.e. every 15 mins) if i dont really care what time is it, i think i buy one to explore more. Thanks again for inspiration. Rabit hole here i come...
Under which stone do you come from ;) You can get 3400mAh and they are really 3400mAh tested it myself (Warning buy the good ones with proof from buyers)
I live in a cave, Albert. I don't get out much. Only Benny to visit me. And Dougle. So I am well behind the times as Henrik Jensen (comment below) has indicated with a very useful chart indeed.
lygte-info.dk/info/batteryIndex.html
How to set the clock to 8MHZ IN ARDUINO IDE?? Because in Arduino ide default clock is 16mhz. Please give me suggestion, so that I can run an atmega328 without a crystal and program it using Arduino ide
www.instructables.com/id/Configure-Arduino-IDE-for-Atmega-328P-to-Use-8MHz-/
untested, might help
Watch his earlier videos...
See video #117, #119, #116 Suraj, bound to be something there.
I want to know if there is a RTC with a programmable register that tells the RTC how many ticks of the crystal to one second?
The reason.. I want to make a RTC run a 24 hour day on Mars time...
1 Mars day = 24h 37m Earth time
I want to do it in such a way, that I set it only one time using NTP,,
then let it keep Mars time on it's own from that time going forward...
So you want a Mars RTC? I've never heard of anything that keeps anything other than Earth time, but you could program a simple Arduino (UNO/Nano) to keep Mars time instead.
The downside of using any kind of electronics is that you will be hard pushed to run it on a battery like the DS3231 (pretty accurate). You _could_ put it to sleep for a second, wake up, do the necessary calculations and put it back to sleep again to enable running off a battery but an Arduino will still take several milliamps for the short period it is running.
You mention using NTP to set the time (initially). That requires Internet access. If you don't need to run it on a battery then one of the small, newer ESP32 devices do this all automatically (for Earth Time) but you could easily run a simple routine to convert to Mars Time. The ESP32 gets the time from NTP periodically to ensure there is no drift as every microcontroller I've ever tried is not accurate enough for a clock.
I'm wondering if a DS3231 that has been correctly set initially could be used with an ATTINY processor of some sort so it can run on a battery for months if not years...?
Finally, if I were a Martian I would not say that my day is 24h and 37min (ie based on Earth time). It would just be 24 hours (or whatever the Martians agreed) and each "second" would be a longer-than-Earth second and so on. Now that could be programmed just by counting 'ticks' in a microcontroller (milliseconds) and then translating that to Mars seconds, minutes and hours. Just a thought.
@RalphBacon I want to thank you for responding to my crazy question.
The NASA Mars Rover team runs on Mars time, so they know when the window to transmit to the Rover is open..
(Rover being on the Earth side of Mars)
So in my scenario, if the Mars Rover had a spotting scope pointed straight up. Every time Earth passed the center field of view, would be noon..
(I know real Mars noon is based on the sun..not Earth)
but I want a clock that would tell me when the Mars Rover was on the Earth facing side of Mars.. (6AM to 6PM Mars time)
If I had to look it up every day, then there would be no point to using a RTC at all...
My RTC is the Ds1307.. It has an error of 7 seconds a day, which means I would have to NTP 7 times a day to keep it accurate to the second..
I was hoping there was a RTC that I could tweak the tick counter to compensate for tolerance errors in the crystal...
If it is fast by 7 seconds a day. How many ticks do I need to adjust by so it is accurate to 1 millisecond a day???
Do you know of any RTCs that have a tick count register to adjust how many ticks equals one second?
Then I make a 24 hour Mars day = (24h 37m 22.5s Earth time)
The only problem this would not fix is a Mars year is over 600 days
but I would at least have the Mars 24 hour day worked out...
I hope you could do a video on making a Mars clock to solve this problem..
One that you only need to set one time a year or better...
I'm afraid I don't know of a variable/programmable RTC, but the DS1307 is very poor at keeping time, which is why I mentioned the much more accurate DS3231. A daily NTP update is all you need, at most, perhaps even once a week is good enough.
If you don't need to run on a battery (like the RTC does) then you can easily program your own Mars clock, ideally with a huge LED display so you don't miss a critical time (like the ones NASA uses when a meteor is about to impact Earth). Using an ESP32, it auto-updates from an NTP.
Although you mention "Mars Time", you know how many seconds in a Mars Hour, Day etc so by using a standard RTC DS3231, you can just count the Earth seconds and create your own Mars clock.
@@RalphBacon My thought was to proportionally stretch the
24 hour RTC day, so it takes 24h 37m 22.5s to complete
(or whatever the actual calculated Mars day is)....
The problem with using (Earth time RTC) is knowing how many days expired since it was set....
Is it possible to edit the RTC library to stretch a 24 hour day?
I would be glad to use another RTC...
I was looking at the data sheet for the RV-3028-C7
(RV-3028-C7_App-Manual.pdf)
and it looks like it has (calibration registers) to adjust
Aging compensation with user programmable EEPROM Offset value (Factory Calibrated value may be changed by the user)
but I don't know if I could add as much as 37m to a day..
My thought on making the RTC keep the time, is if I set it,
I could put it away for a month or two and when I get it out,
it is still on Mars time..
Anyway, thank you so much for your ideas.. I would love to see
if such a thing is possible..
I was thinking more in terms of counting the seconds from a DS3231 (probably using an interrupt) via the 1Hz output pin, and then in the Arduino program incrementing the user-controlled secs/mins/hours/days etc according to Mars rules. That way, you have full control over all aspects of Mars time.
I bought a bunch for 43 cts a piece 5 years ago. No postage
Deal of the decade, that was Fred. Were you in China at the time?!?
@@RalphBacon nope. Just aliexpress. Bought some rechargeable button cells for them as well
16:10: Should lines 59 & 60 be reversed? Right now you are setting it LOW first and then you instruct the MCU that this is an output.
Hey LJ .
No , I think Ralph did that as setting as output first will set the pin to high .
Set as low first and it will start low .
The way you are thinking will send a high pulse before going low .
Ralph did explain this in a video , only I cant remember which one ...
Maybe Ralph can remember or explain a little better ... :)
Karen is correct. By setting the HIGH/LOW first avoid any microsecond blip as the set the pin to OUTPUT and then digitalWrite it LOW. Nick Gammon (no relation) taught me this so who am I to argue?
@@karens-jclark4199 Thanks
@@LJWinkler247
No problem ... Picked this up from Ralph , lots of good info from Ralph .
Happy to help when I can :)
Hi Ralph Bacon
I have been following your video with great interest regarding “# 192 Wakey, wakey! Let the DS3231 RTC wake up your Arduino-easy! ” I can not program, but I can use your sketch for some practical use, and not just flashing LEDs. I have a sketch that runs on ESP32 and which is an Internet clock that is updated every minute, along with Temp. and Humidity from DHT 22, all of which are shown on an E-Paper display.
Since I do not see or use the Internet clock at night, it was best that it is in Deep Sleep, as it is powered by a battery, thereby saving power. I could imagine that ESP32 Wakeup, for example, time 0800 and, and goes into Deep Sleep at 2300, and it can do that every day. I do not have the ability to combine the 2 sketches into one sketch as I do not have enough knowledge of programming, so could you help me with that?
How do I combine Setup from the 2 sketches in one sketch, and the same in Loop, so that it can be used for something practical.
With best regards Georg
Have we not had this conversation already, Geog? I'm sure I replied. Perhaps I just forgot to press SUBMIT? Anyway, to combine the sketches is fairly straightforward. Copy each line of code from the simplest sketch into the more complex one. Don't repeat stuff and make sure it works as you go by compiling and uploading. I've just done the exact same exercise copying my TFT Screen code into my Internet Radio code, testing as I went. A couple of hiccups (forgot an #include library) but other than that all sweet.
Great video thanks!
Glad you liked it!
Please, add scheme. It's takes a lot of time to understand what you do. Thanks a lot!
Very sorry, it's too time-consuming to add an actual schematic but I've added a new file describing how to connect the DS3231 to the Arduino. I'm sure it will help you.
github.com/RalphBacon/192-DS3231-Wake-Up-Arduino
Thanks
Welcome!
Sony/Murata VTC6 - 3000 mAh without any protection
That is certainly a high capacity 18650 (assuming it's genuine) and at just a fiver each (in the UK) good value too.
Thank you
Please replicate same with ESP8266 :)
The ESP8266 does things a different way, when waking from Deep Sleep. It just "reboots" and there is a flag that the developer can read to detect it is, in fact, rebooting from so-called Deep Sleep rather than just being switched on at the plug. The only way it can "remember" values is by writing them to the RTC's RAM area before it goes to sleep. But it doesn't resume execution from the next statement in the sketch, it just starts the sketch from the very start. Not so great. But the DS3231 could trigger the reboot, I guess. Watch video #116 (ruclips.net/video/NgPwPKXCLFY/видео.html ) to see if that gives you the answer.
Hello sir how are you 😊
All good, Yogesh, I hope you are too.