real-time clock DS3231 for arduino

I’d like to represent you a real-time clock. With this component you can get the actual time.

schema
The pins are connected with Arduino Uno R3:

RTC DS3231 Arduino Uno R3
VCC 5V
GRD ground
SCL A5
SDA A4

Bildergebnis für ds3232rtc example

configuration
To set up the time for the real-time clock, write two assignments in the setup-function.

setTime(23, 31, 30, 13, 2, 2018); //set the system time to 23h31m30s on 13Feb2018
RTC.set(now()); //set the RTC from the system time

The complete instructions for time-lib are to find on page:
https://github.com/JChristensen/DS3232RTC

include libraries in your code:
DS3232RTC-master
Time-master

coding in arduino SDK

/*
* TimeRTC.pde
* Example code illustrating Time library with Real Time Clock.
* This example is identical to the example provided with the Time Library,
* only the #include statement has been changed to include the DS3232RTC library.
*/

#include <DS3232RTC.h> //http://github.com/JChristensen/DS3232RTC
#include <Time.h> //http://www.arduino.cc/playground/Code/Time
#include <Wire.h> //http://arduino.cc/en/Reference/Wire (included with Arduino IDE)

void setup(void)
{
Serial.begin(9600);
setSyncProvider(RTC.get); // the function to get the time from the RTC
if(timeStatus() != timeSet)
Serial.println("Unable to sync with the RTC");
else
Serial.println("RTC has set the system time");
}

void loop(void)
{
digitalClockDisplay();
delay(1000);
}

void digitalClockDisplay(void)
{
// digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.print(' ');
Serial.print(day());
Serial.print(' ');
Serial.print(month());
Serial.print(' ');
Serial.print(year());
Serial.println();
}

void printDigits(int digits)
{
// utility function for digital clock display: prints preceding colon and leading 0
Serial.print(':');
if(digits < 10)
Serial.print('0');
Serial.print(digits);
}

RFID key tag

Identify your tag on id.

There are different useful use cases, for instance:

  • access control
  • tracking objects
  • identify objects

Bildergebnis für MFOne S50 key tag

This picture shows a MFOne-S50 key tag. The key has a number with eight signs like B260B673.

To get the card id use following code for Arduino.

/*******************************************
* function:get the id of RFID key
* RFID Uno r3
* VCC 3.3V
* RST 2
* GND GND
* MISO 3
* MOSI 4
* SCK 5
* NSS 6
* IRQ 7
****************************************/

#include"rfid1.h"
RFID1 rfid;//create a variable type of RFID1

uchar serNum[5]; // array to store your ID

void setup()
{
Serial.begin(9600); //initialize the serial
rfid.begin(7, 5, 4, 3, 6, 2); //rfid.begin(IRQ_PIN,SCK_PIN,MOSI_PIN,MISO_PIN,NSS_PIN,RST_PIN)
delay(100);//delay 1s
rfid.init(); //initialize the RFID
}
void loop()
{
uchar status;
uchar str[MAX_LEN];
// Search card, return card types
status = rfid.request(PICC_REQIDL, str);
if (status != MI_OK)
{
return;
}
// Show card type
rfid.showCardType(str);
//Prevent conflict, return the 4 bytes Serial number of the card
status = rfid.anticoll(str);

if (status == MI_OK)
{
Serial.print("The card's number is: ");
memcpy(serNum, str, 5);
rfid.showCardID(serNum);//show the card ID
Serial.println();
Serial.println();
}
delay(500);

rfid.halt(); //command the card into sleep mode
}

To use the card id for access control use this code segment to identify a person named Alisha or an object for example.

uchar* id = serNum;
if( id[0]==0xB2 && id[1]==0x60 && id[2]==0xB6 && id[3]==0x73 )
{
lcd.setCursor(0,1);
lcd.print(" Alisha ");
delay(2000);
lcd.clear();
}

 

Have fun with RFID’s in your projects.

Download libraries: RFID_kit_V1.0_for_Arduino.zip 
https://www.sunfounder.com/learn/category/RFID_kit_V1_for_Arduino.html