Go Down

Topic: RTC DS3231 and 1 channel 5 V Relay intigration  (Read 641 times) previous topic - next topic

shellgs

Hello,

I am new to Arduino, currently in the learning process, I am in the process of making circuit, which will stop my external devices after 1 year so that it can be put into maintenance mode, before goes into production.

I am planning to use RTC DS3231 programmed with Arduino and external devices attached using 1 channel 5 volt relay, but my external device are switched off every day hence I want my RTC should be running using internal lithium battery and trigger Relay LOW when time reaches one year.

Once program is loaded using Arduino IDE, into RTC DS3231 it should run by itself using Lithium battery and my Arduino Uno should be detached. I am not sure about which port of RTC DS3231 should be connected to Relay and how to make it run by itself.

I have checked few videos in YouTube.. they are explaining about Relay example (https://www.youtube.com/watch?v=g6k8sPJyif8&t=63s). and they are explaining about RTC DS3231 example (https://www.youtube.com/watch?v=kfgKg8LIGMs). But no one is explaining both together.

====================
I am planning to use below devices to achieve same.

1) DS3231(RTC) which has battery attached (https://robu.in/product/ds3231-rtc-module-precise-real-time-clock-i2c-at24c32/)

2) 1 channel 5V Relay (https://robu.in/product/1-channel-isolated-5v-relay-module-opto-coupler-for-arduino-pic-avr-dsp-arm/)

3) Arduino Uno board. (https://robu.in/product/arduino-uno-r3-ch340g-atmega328p-devlopment-board/?gclid=Cj0KCQjw_5rtBRDxARIsAJfxvYDxxiebKipfNPdqEi8b38V2TzaVIDgYXVYl46WXnuZSOTyw43jd4-saAuCJEALw_wcB)


If there is already a program and circuit diagram to integrate both RTC DS3231 and 1 Channel 5V Relay. Kindly share me details..

Please guide me.. Thanks in Advance.





Wesstun

Once program is loaded using Arduino IDE, into RTC DS3231 it should run by itself using Lithium battery and my Arduino Uno should be detached. I am not sure about which port of RTC DS3231 should be connected to Relay and how to make it run by itself.

You've got the right idea giving the DS3231 its own battery so that it can keep track of the time.  The DS3231 can run on a coin cell battery for a year pretty easily, but what you're trying to do - make the DS3231 control a relay by itself, isn't really possible.  The DS3231 is just a real time clock - all the DS3231 does is keep track of the time, and report the time over the I2C interface if it's requested.  It doesn't control anything - it just provides information that a microcontroller (like the arduino) can use to make decisions.

I'm guessing you want to detach the Arduino Uno from your circuit because the Arduino will drain your battery if it stays connected to your circuit.  Unfortunately it's the only part of your circuit that can control the relay, or make the decision if it's time to control the relay, so it has to stay.

Basically, you need to have the Arduino check the time on the RTC periodically, and every time it checks the time, it decides whether or not it needs to change the state of the relay.  The simplest way to do this is probably to provide external power to your circuit so that the arduino can stay active.  If power is lost, the RTC can still keep track of time with its battery, and when the power comes back on, the Arduino can go back to checking the time to see if it's time to switch the relay.

If you really need the entire system to run entirely on a battery, you will definitely need to have the arduino go to sleep most of the time, and only wake up occasionally to see if it's time to trigger the relay again.

Try Kevin Darrah's video on using an RTC to wake up an Arduino occasionally, and put the Arduino into an ultra-low power state when it's between checks.  Kevin has other low power videos that are also very informative.

https://www.youtube.com/watch?v=GvZCmH6BFHw


ballscrewbob

It may not be the answer you were looking for but its the one I am giving based on either experience, educated guess, google or the fact that you gave nothing to go with in the first place so I used my wonky crystal ball.

shellgs

Thanks for the replay, your suggestions are very valuables to me, my lithium battery will not stay relay for 1 year.

Basically I am saying, I will upload my code in RTC DS3231 using Arduino Uno and detach the Arduino Uno and attach my relay and also I have seen DS3231 has pin GND, VCC, SDA, SLC, SQW and 32K pins with lithium battery, I will take power from internal battery of my machine and pass it to VCC and GND pins of RTC DS3231.  My concern is, will this work? if I am removing the Arduino Uno and supply power from different source to DS3231 and make my relay work when my machine is down.

If my logic is correct, please suggest me which pin of SDA (data line) and SCL (clock line) are supposed to be connected to 1 channel 5V relay and please guide me with programming commands using which I will try to program.

Basically, I am in the process of making a low investment switch which will break my machine power supply so that I will put them in maintenance before going to production.  If my logic is wrong, please suggest me how to achieve my requirement.

I apologies for double posts, since I was not sure where to post.

Thank you very much for your replay.

Idahowalker

Quote
Basically I am saying, I will upload my code in RTC DS3231
You are expecting the RTC to hold and operate on code you upload to it?

You can set registers on the RTC to set alarms and interrupts, that's it. If your module has a serial EEPROM, you can load code into that but it will be just stored there as data and will not run.
Quote
power from internal battery of my machine and pass it to VCC and GND pins of RTC DS3231
Yes you can do that.
Quote
if I am removing the Arduino Uno and supply power from different source to DS3231 and make my relay work when my machine is down.
Can you restate the above?
Quote
If my logic is correct, please suggest me which pin of SDA (data line) and SCL (clock line) are supposed to be connected to 1 channel 5V relay and please guide me with programming commands using which I will try to program.
This idea will not work.

Wesstun

shellgs,

We understand you're a beginner.  Everyone has to start somewhere, but you are trying to run before you've learned how to walk.  Your project is very ambitious for a total beginner.  You need to start out mastering each of the concepts you want to use in your project individually.

You seem to misunderstand how the DS3231 works.  The DS3231 is ONLY an RTC.  It cannot control your circuit on its own.  To control your circuit you need a microcontroller - like an Arduino.  So, no, your idea of disconnecting the Arduino after setting up the DS3231 will not work.

I think you need to start smaller.  Try making a circuit of your own where an Arduino talks to a DS3231 to set and read the time instead of just watching the youtube video about it.  When you actually make the circuit yourself you'll quickly see what the DS3231 can do and what it can't do.

After that you can expand your project to add a relay.  Try making a circuit that turns the relay on and off every 5 seconds based on the time from the RTC.  Doing this will teach you the concept of controlling a relay based on the time that you read.  You need to do this, because it seems like you don't understand how to control relays from an Arduino.  Relays don't respond to commands form I2C lines.

Finally, you can try making your entire project power-efficient enough to run on a battery for an entire year.  This is not easy.  You will have to learn a lot before you are able to do this.  You have to be able to understand exactly how much power is being drawn from every component of your circuit and determine if your battery will support that.  You will almost certainly need to learn about putting your microcontroller into deep sleep to save power, and you probably won't be able to use a standard Arduino board, because the regulator and LED on that board consume too much power for long-term battery applications.  You might need to look into latching relays, or using their normally closed contacts, because driving a relay coil for a year on a battery will never work.  Even if you use normally closed contacts in the period leading up to a year, once your circuit activates the relay it will drain the battery very quickly.  You have to think these things through.

I think you're hoping that we can just paste some code here that will work for you and that we can solve your problem instantly, but we can't.  Your project requires a lot of design work.  We can help you with specific questions, but we can't design your project for you.

Go Up