RTC 3231 to turn LEDs on and off

I've spent hours looking for a basic tutorial that shows how to set up a RTC 3231. After installing the 3232 library, the red light on the 3231 came on. I opened the serial monitor to set time and added 17,1,8,11,45,30, When I clicked send it disappeared-I don't know if the time is set or not.

This sketch works for manually dimming the LEDs with a pot. Now, I need to turn the LEDs on and off with the 3231. Any help would be much appreciated.

 #include <DS3232RTC.h>

 
 
int nemLED = 3; 
int nemPOT = A1;
int rightrockLED = 5;
int rightrockPOT = A2;
int leftrockLED = 6;
int leftrockPOT = A3;
int purpLED = 9;
int purpPOT = A4;
int FANS = 4;

void setup() {
  
  pinMode(nemPOT, INPUT);
  pinMode(nemLED, OUTPUT);
  pinMode(rightrockPOT, INPUT);
  pinMode(rightrockLED, OUTPUT);
  pinMode(leftrockPOT, INPUT);
  pinMode(leftrockLED, OUTPUT);
  pinMode(purpPOT, INPUT);
  pinMode(purpLED, OUTPUT);
  pinMode(FANS, OUTPUT);

   

}

void loop(void) {
   
  analogWrite(nemLED, (analogRead(nemPOT)/ 4));
  analogWrite(rightrockLED, (analogRead(rightrockPOT)/ 4));
  analogWrite(leftrockLED, (analogRead(leftrockPOT)/ 4));
  analogWrite(nemLED, (analogRead(nemPOT)/ 4));
  analogWrite(purpLED, (analogRead(purpPOT)/ 4));
  digitalWrite(FANS, HIGH);

 
}

Post the sketch that you used to set the time on the DS3231 then some one will help you to add a serial print statement to it which will confirm that the time has been correctly set.

6v6gt:
Post the sketch that you used to set the time on the DS3231

Oh, the sketch in the first post is it. Oops. I thought I was all set when the red light on the RTC came on, ha.

Thanks for pointing me in the right direction.

The posted sketch does nothing to or with the RTC.

You could try following this tutorial or perhaps this one. There are many others.

jremington:
The posted sketch does nothing to or with the RTC.

You could try following this tutorial

I went to that link and clicked on the Download RTClib and selected save. Then, I went to documents, then downloads and found RTClib-master.zip.

The directions say to rename the uncompressed file, but the only option I can find to rename is with the compressed file.

Where have I gone wrong?

Thanks for that link. I was looking at YouTube videos and between people flying around on computer screens and poor images, I was having an awful time. Reading something is better. Still stuck, but not as bad.

OK, got that RTClib-masterzip renamed and it's in the list of libraries. But unlike the tutorial, 3231 isn't listed in it's examples-only 1307. ugg.

I have Jack Christensen's library for the Ds3232/3231.

I opened SetSerial under examples for that library and uploaded it to my UNO with RTC 3231 connected.

I made sure the baud rate at Serial.begin(115200); is the same as the baud rate on the serial monitor.

I opened the serial monitor and added 17,1,10,8,56,30, and clicked send. The numbers disappeared, but there's no indication the time is set.

I thought maybe I had a bad battery in the 3231, so I installed a new one.

The 3231 is plugged directly into the UNO with 32K and SQW disconnected.

Have I done something the wrong way?

Or do I maybe have a bad UNO or 3231?

saltyjoe:
...
Have I done something the wrong way?
...

Obviously, cause if you hadn't, it would be working to your satisfaction, right?

We don't know what you are doing. You need to use code tags and post your code - the code you are using to set the time, not your LED dimming code! I don't get why you typed 17,1,10,8,56,30 into the serial monitor. If you were running the sketch you posted in the OP, then you have certainly NOT set the time.

Add a link to the RTC you are using. I don't know of any that have a red LED on them.

Here's the code I used this morning. Sorry, I'm not sure what a code tag is...

I followed the instructions Jack Christianson included with the example. I got no indication time was set. That's why I wondered if maybe I have bad hardware.

My RTC3231

Thanks.

/----------------------------------------------------------------------

  • Display the date and time from a DS3231 or DS3232 RTC every second. *
  • Display the temperature once per minute. (The DS3231 does a *
  • temperature conversion once every 64 seconds. This is also the *
  • default for the DS3232.) *
  • Set the date and time by entering the following on the Arduino *
  • serial monitor: *
  • year,month,day,hour,minute,second, *
  • Where *
  • year can be two or four digits, *
  • month is 1-12, *
  • day is 1-31, *
  • hour is 0-23, and *
  • minute and second are 0-59. *
  • Entering the final comma delimiter (after "second") will avoid a *
  • one-second timeout and will allow the RTC to be set more accurately. *
  • No validity checking is done, invalid values or incomplete syntax *
  • in the input will result in an incorrect RTC setting. *
  • Jack Christensen 08Aug2013 *
  • Tested with Arduino 1.0.5, Arduino Uno, DS3231/Chronodot, DS3232. *
  • This work is licensed under the Creative Commons Attribution- *
  • ShareAlike 3.0 Unported License. To view a copy of this license, *
  • visit Creative Commons — Attribution-ShareAlike 3.0 Unported — CC BY-SA 3.0 or send a *
  • letter to Creative Commons, 171 Second Street, Suite 300, *
  • San Francisco, California, 94105, USA. *
    *----------------------------------------
 #include <DS3232RTC.h>        //http://github.com/JChristensen/DS3232RTC
#include <Streaming.h>        //http://arduiniana.org/libraries/streaming/
#include <Time.h>             //http://playground.arduino.cc/Code/Time
#include <Wire.h>             //http://arduino.cc/en/Reference/Wire

void setup(void)
{
    Serial.begin(115200);
    
    //setSyncProvider() causes the Time library to synchronize with the
    //external RTC by calling RTC.get() every five minutes by default.
    setSyncProvider(RTC.get);
    Serial << F("RTC Sync");
    if (timeStatus() != timeSet) Serial << F(" FAIL!");
    Serial << endl;
}

void loop(void)
{
    static time_t tLast;
    time_t t;
    tmElements_t tm;

    //check for input to set the RTC, minimum length is 12, i.e. yy,m,d,h,m,s
    if (Serial.available() >= 12) {
        //note that the tmElements_t Year member is an offset from 1970,
        //but the RTC wants the last two digits of the calendar year.
        //use the convenience macros from Time.h to do the conversions.
        int y = Serial.parseInt();
        if (y >= 100 && y < 1000)
            Serial << F("Error: Year must be two digits or four digits!") << endl;
        else {
            if (y >= 1000)
                tm.Year = CalendarYrToTm(y);
            else    //(y < 100)
                tm.Year = y2kYearToTm(y);
            tm.Month = Serial.parseInt();
            tm.Day = Serial.parseInt();
            tm.Hour = Serial.parseInt();
            tm.Minute = Serial.parseInt();
            tm.Second = Serial.parseInt();
            t = makeTime(tm);
            RTC.set(t);        //use the time_t value to ensure correct weekday is set
            setTime(t);        
            Serial << F("RTC set to: ");
            printDateTime(t);
            Serial << endl;
            //dump any extraneous input
            while (Serial.available() > 0) Serial.read();
        }
    }
    
    t = now();
    if (t != tLast) {
        tLast = t;
        printDateTime(t);
        if (second(t) == 0) {
            float c = RTC.temperature() / 4.;
            float f = c * 9. / 5. + 32.;
            Serial << F("  ") << c << F(" C  ") << f << F(" F");
        }
        Serial << endl;
    }
}

//print date and time to Serial
void printDateTime(time_t t)
{
    printDate(t);
    Serial << ' ';
    printTime(t);
}

//print time to Serial
void printTime(time_t t)
{
    printI00(hour(t), ':');
    printI00(minute(t), ':');
    printI00(second(t), ' ');
}

//print date to Serial
void printDate(time_t t)
{
    printI00(day(t), 0);
    Serial << monthShortStr(month(t)) << _DEC(year(t));
}

//Print an integer in "00" format (with leading zero),
//followed by a delimiter character to Serial.
//Input value assumed to be between 0 and 99.
void printI00(int val, char delim)
{
    if (val < 10) Serial << '0';
    Serial << _DEC(val);
    if (delim > 0) Serial << delim;
    return;
}

OK, got that RTClib-masterzip renamed and it's in the list of libraries. But unlike the tutorial, 3231 isn't listed in it's examples-only 1307. ugg.

RTClib with the 1307 will work with the ds3231.

#include <DS3232RTC.h>        //http://github.com/JChristensen/DS3232RTC

excellent choice of library

I got no indication time was set

What do you see when you run this i2c scanner. The rtc module may not be seen on the bus.

// I2C Scanner
// Written by Nick Gammon
// Date: 20th April 2011

#include <Wire.h>

void setup() {
  Serial.begin (115200);

  // Leonardo: wait for serial port to connect
  while (!Serial) 
    {
    }

  Serial.println ();
  Serial.println ("I2C scanner. Scanning ...");
  byte count = 0;
  
  Wire.begin();
  for (byte i = 8; i < 120; i++)
  {
    Wire.beginTransmission (i);
    if (Wire.endTransmission () == 0)
      {
      Serial.print ("Found address: ");
      Serial.print (i, DEC);
      Serial.print (" (0x");
      Serial.print (i, HEX);
      Serial.println (")");
      count++;
      delay (1);  // maybe unneeded?
      } // end of good response
  } // end of for loop
  Serial.println ("Done.");
  Serial.print ("Found ");
  Serial.print (count, DEC);
  Serial.println (" device(s).");
}  // end of setup

void loop() {}

cattledog:
What do you see when you run this i2c scanner. The rtc module may not be seen on the bus.

When I open the serial monitor I see this.

I2C scanner. Scanning....

The fact that the scanner hangs instead of returning "No devices found" is a bad sign.

What does the scanner program give you with nothing connected to the I2C lines. If it hangs, there is a problem with the arduino. If it says no devices found, then there is most likely a short between SDA and SCL or between either one of them and ground or to 5v on the module.

You have a hardware problem which must be solved before you can make any progress.

With the RTC disconnected, the serial monitor says this;

2C scanner. Scanning....

Done.

Found 0 device(s).

With my DMM set at 200k
SCL-SDA 9.2
SCL-VCC 4.6
SCL-GND 10.6
SDA-VCC 4.6
SDA-GND 10.6

IDK if these numbers tell you anything, but I have another RTC3231 somewhere and another UNO. When I find them, I'll try again. Thanks a ton!

I found my unopened UNO and unopened RTC3231 and uploaded the SetSerial example from post #7 with the exact same results. I ran the I2C scanner with the same results.

The baud rate is the same in sketch and serial monitor-115200. Autoscroll is checked and No line ending is selected.

I entered the time in the top space in line with the send button as, 17,1,11,8,10,30, then clicked send.

The same thing twice in a row with different hardware makes me think I must be doing something wrong. Any ideas?

ChrisTenone:
You need to use code tags

Ok, now I know those code brackets are called code tags. I didn't put the comments and instructions in the code tags because I thought they were strictly for code. Next time, comments will be included.

I ran the I2C scanner with the same results.

Can you provide a photograph of how the UNO and the rtc module are connected?

Gladly-thanks.

AREF can not be used as a general I/O pin like you are attempting. If you wish to plug the module directly into a header, use A2,A3,A4,A5 and run the following code. A4 is SDA and A5 is SCL. A2 will be gnd, and A3 will supply 5v.

#include <Wire.h>

void setup() {

 pinMode(A2, OUTPUT);//setup for rtc on A2,A3
 digitalWrite(A2, LOW);
 pinMode(A3, OUTPUT);
 digitalWrite(A3, HIGH);

  Serial.begin (115200);

  // Leonardo: wait for serial port to connect
  while (!Serial)
  {
  }

  Serial.println ();
  Serial.println ("I2C scanner. Scanning ...");
  byte count = 0;

  Wire.begin();
  for (byte i = 1; i < 120; i++)
  {
    Wire.beginTransmission (i);
    if (Wire.endTransmission () == 0)
    {
      Serial.print ("Found address: ");
      Serial.print (i, DEC);
      Serial.print (" (0x");
      Serial.print (i, HEX);
      Serial.println (")");
      count++;
      delay (1);  // maybe unneeded?
    } // end of good response
  } // end of for loop
  Serial.println ("Done.");
  Serial.print ("Found ");
  Serial.print (count, DEC);
  Serial.println (" device(s).");
}  // end of setup

void loop() {
}

Thank you cattledog, that was the problem alright. I appreciate that sketch, but I am using A1, A2, A3 and A4 for dimming my LEDs so I straightened the VCC pin from the 3231 and soldered a wire to it and hooked it to 5V.

In order to make the RTC turn my LEDs on and off, would I use the SetSerial example as a foundation sketch and add my dimming LED sketch to it, as well as some command for on and off?

In order to make the RTC turn my LEDs on and off, would I use the SetSerial example as a foundation sketch and add my dimming LED sketch to it, as well as some command for on and off?

Once you set the RTC, you will more likely be using the ds3232 library example TimeRTC as the model. You will actually be using the syntax from the Time Library for much of how you deal with time. The time Library will update/synchronize the internal arduino clock to the actual time contained in the RTC. You might also wish to use the Time Alarms Library depending on what timing you want for the leds.

Now that you have the RTC functioning, you will be better off posting the code you have for the LED's and their timing of turning on and off in a new sketch. The sketch you originally posted made no use of time, and it was not at all clear how you wanted to turn the led's on and off. Make an effort to incorporate timing, and post a new sketch in a new thread. You mention "dimming", and that is not something typically done with the rtc, and is more likely to use a "blink without delay" approach where you change the analogWrite() duty cycle at fixed intervals. The rtc is more likely to be used if you want to start "dimming" as a specific time of day.

Thanks, I'll work on that.