Table of Contents
Prev
Start: of Posts Show
Next

PLC Real Time Clock Using Arduino

PLC real time clock using arduino and real time clock module. for real time module use DS3231 RTC Board. The way it works is: Arduino reads data from the DS3231, this data is sent directly to the PLC memory. and for setting the date and time via the DS3124 and computer by using visual basic net (VB.Net)

PLC real time clock process:
1. Read date and time from DS3231 RTC Board with Arduino via I2C communication
2. Send data to PLC with Arduino via RS232 communication and PLC Protocol
3. Receive data in PLC data memory
Flow process of the PLC Real TIme Clock:
Flow process of the PLC Real TIme Clock

Hardware requirements:
1. DS3231 RTC Board Module
DS3231 RTC Board Module

2. Arduino Nano
Arduino Nano Ver3

3. Multi Master Cable S7-200 RS-232
Multi Master Cable S7-200 RS-232

4. Siemens PLC S7-200 (not real time clock)
Siemens PLC S7-200 CPU 226

5. DB9 Male crossover cable
DB9 Male crossover cable

6. RS232 Serial Port To TTL Converter Module
RS232 Serial Port To TTL Converter Module


Wiring of DS3231 Module to Arduino
Wiring of DS3231 Module to Arduino

Upload Program to Arduino
1. Download Arduino Project File, click here
2. Open Project file and Upload to Arduino

Date Time Setting in DS3231 Module using VB.NET:
1. Connect USB cable from Arduino to computer
2. Download VB Project File, click here
3. Open VB Project File and RUN
See Video for DS3231 Setting:

Download Ladder PLC Programming to PLC
1. Download file, click here
2. And Download Ladder programming to PLC

Wiring of DS3231,Arduino,PLC Cable, RS232 Cross and PLC
For a description of the image numbers, can be seen in the hardware requirements
Wiring of PLC Real Time Clock Using Arduino

Clock in PLC memory

VB0=SECOND : 0 to 59
VB1=MINUTE : 0 to 59
VB2=HOUR OF DAY : 0 to 23
VB3= DATE : 1 to 28/29/30//31
VB4= MONTH : 1 to 12
VB5= DAY OF WEEK : 1-SUNDAY, 2-MONDAY, 3-TUESDAY, 4-WEDNESDAY, 5-THURSDAY, 6-FRIDAY, 7-SATURDAY
VB6= YEAR: 0 to 99

Arduino Source Code
#include <Wire.h>;
const int DS1307 = 0x68;
byte second = 0;
byte minute = 0;
byte hourofday = 0;
byte dayofweek = 0;
byte date = 0;
byte month = 0;
byte year = 0;
byte set[7];
const char delimiter = ',';
String  message;
byte i;
int y;

void setup() {
  Wire.begin();
  Serial.begin(9600,SERIAL_8E1);//9600,8,Even,1
  Serial.setTimeout(800);
}

void loop() {
  sendTime();  
  message = Serial.readString();  //= "year,month,date,week,hour,minute,second";
  incomeTime(); 
}
byte decToBcd(byte val) {
  return ((val/10*16) + (val%10));
}
byte bcdToDec(byte val) {
  return ((val/16*10) + (val%16));
}

void incomeTime() { 
  i=0;
  y=-1;  
  do
  {
      y = message.indexOf(delimiter);
      if(y != -1)
      {
          if(i<=5)set[i]=message.substring(0,y).toInt();
          message = message.substring(y+1, message.length());
          i++;
      }
      else
      {
         if(message.length() > 0 && i==6)
           set[i]=message.toInt();         
      }
   }
   while(y >=0);
   
   if (i==6){
     if(set[0]>=0 && set[0]<=99){
       if(set[1]>=1 && set[1]<=12){
         if(set[2]>=1 && set[2]<=31){
           if(set[3]>=1 && set[3]<=7){
             if(set[4]>=0 && set[4]<=23){
               if(set[5]>=0 && set[5]<=59){
                 if(set[6]>=0 && set[6]<=59){
                   setTime();
                 }
               }
             }
           }
         }
       }
     }
   }

}
void setTime() { 
  year =set[0]; 
  month =set[1]; 
  date =set[2]; 
  dayofweek =set[3]; 
  hourofday =set[4]; 
  minute =set[5]; 
  second = set[6];
  Wire.beginTransmission(DS1307);
  Wire.write(byte(0));
  Wire.write(decToBcd(second));
  Wire.write(decToBcd(minute));
  Wire.write(decToBcd(hourofday));
  Wire.write(decToBcd(dayofweek));
  Wire.write(decToBcd(date));
  Wire.write(decToBcd(month));
  Wire.write(decToBcd(year));
  Wire.write(byte(0));
  Wire.endTransmission();
}

void sendTime() {
  readTime();
  int VB0 = second;// VB0=SECOND : 0 to 59
  int VB1 = minute;//VB1=MINUTE : 0 to 59
  int VB2 = hourofday;//VB2=HOUR OF DAY : 0 to 23
  int VB3 = date;//VB3= DATE : 1 to 31
  int VB4 = month;//VB4= MONTH : 1 to 12
  int VB5 = dayofweek;//VB5= DAY OF WEEK : 1=SUNDAY, 2=MONDAY, 3=TUESDAY, 4=WEDNESDAY, 5=THURSDAY, 6=FRIDAY, 7=SATURDAY
  int VB6 = year;//VW6= YEAR 00 to 99

  int VWstart = 0; //Start from VW0
  int VWcount = 4; 

  byte str_write[45];
  long Temp_FCS=0;
  int i;
                    
  str_write[1] = (byte)((VWcount * 2) + 31);
  str_write[2] = (byte)str_write[1];
  str_write[24] = (byte)(VWcount * 2);
  str_write[16] = (byte)(str_write[24] + 4);
  str_write[33] = (byte)((VWcount * 16) / 256);
  str_write[34] = (byte)((VWcount * 16) % 256);

  str_write[29] = (byte)((VWstart * 8) / 256);
  str_write[30] = (byte)((VWstart * 8) % 256);

  str_write[0] = (byte)0x68;//H68
  str_write[3] = (byte)0x68;//H68
  str_write[4] = (byte)0x02;//H2
  str_write[5] = (byte)0x00;//H0
  str_write[6] = (byte)0x7C;//H7C
  str_write[7] = (byte)0x32;//H32
  str_write[8] = (byte)0x01;//H1
  str_write[9] = (byte)0x00;//H0
  str_write[10] = (byte)0x0;//H0
  str_write[11] = (byte)0x43;//H43
  str_write[12] = (byte)0x01;//H1
  str_write[13] = (byte)0x00;//H0
  str_write[14] = (byte)0x0E;//HE
  str_write[15] = (byte)0x00;//H0

  str_write[17] = (byte)0x05;//H5
  str_write[18] = (byte)0x01;//H1
  str_write[19] = (byte)0x12;//H12
  str_write[20] = (byte)0x0A;//HA
  str_write[21] = (byte)0x10;//H10
  str_write[22] = (byte)0x02;//H2
  str_write[23] = (byte)0x00;//H0

  str_write[25] = (byte)0x00;//H0
  str_write[26] = (byte)0x01;//H1  
  str_write[27] = (byte)0x84;//H84  
  str_write[28] = (byte)0x00;//H0

  str_write[31] = (byte)0x00;//H0
  str_write[32] = (byte)0x04;//H4


  str_write[35] = (byte)VB0;
  str_write[36] = (byte)VB1;

  str_write[37] = (byte)VB2;
  str_write[38] = (byte)VB3;

  str_write[39] = (byte)VB4;
  str_write[40] = (byte)VB5;

  str_write[41] = (byte)VB6;
  str_write[42] = (byte)0;

  for (i = 4; i <= 42; i++)
  {
      Temp_FCS = Temp_FCS + str_write[i];
  }
  str_write[43] = (byte)(Temp_FCS % 256);
  str_write[44] = (byte)0x16;//H16

  Serial.write(str_write, sizeof(str_write));

  delay(100);
    byte str_val[6];
    str_val[0] = (byte)0x10;//H10; 
    str_val[1] = (byte)0x02;//H2;
    str_val[2] = (byte)0x00;//H0;
    str_val[3] = (byte)0x5C;//H5C;
    str_val[4] = (byte)0x5E;//H5E;
    str_val[5] = (byte)0x16;//H16;
    Serial.write(str_val, sizeof(str_val));
  delay(100);
}


void readTime() {
  Wire.beginTransmission(DS1307);
  Wire.write(byte(0));
  Wire.endTransmission();
  Wire.requestFrom(DS1307, 7);
  second = bcdToDec(Wire.read());
  minute = bcdToDec(Wire.read());
  hourofday = bcdToDec(Wire.read());
  dayofweek = bcdToDec(Wire.read());
  date = bcdToDec(Wire.read());
  month = bcdToDec(Wire.read());
  year = bcdToDec(Wire.read());
}


Hopefully this article can add your insights.
Please follow me:

ShareTo
Share on Facebook Tweet this Share to Google Plus Stumble this article
CLOSE

Enter Your Email Address




All Labels

  1. ABB PLC
  2. Allen Bradley PLC
  3. Analog Input
  4. Android
  5. Android and PLC
  6. Android Bluetooth
  7. Audio and PLC
  8. Automatic Gates using PLC
  9. Baldor PLC
  10. Battery Level Indicator using PLC Analog
  11. BMS
  12. Building Management System
  13. Car Ticketing Machine using PLC
  14. CIMON PLC
  15. Click Series PLC
  16. Computer Vision
  17. Computer Vision and PLC
  18. Control Seven Segment Display with PLC
  19. Conveyor Control Using PLC
  20. CPU PLC
  21. CV and PLC
  22. CX-One
  23. DCS
  24. DDC
  25. DELMIA V5
  26. DeltaV
  27. Digital Input
  28. DirectLogic PLC
  29. DirectSOFT PLC
  30. Eaton PLC
  31. Elevator with PLC Program
  32. EPICS PLC
  33. Fatek PLC
  34. Festo PLC
  35. Fieldbus
  36. Forex Trading and PLC
  37. FPGA PLC
  38. GE Fanuc PLC
  39. GP proface
  40. GX Developer
  41. Heater Controller with PLC
  42. Hitachi PLC
  43. HMI
  44. Home Automation
  45. Honeywell PLC
  46. IDEC PLC
  47. Keyence PLC
  48. Koyo PLC
  49. LED Display
  50. LG PLC
  51. Lock Unlock Door Using PLC
  52. Logixpro PLC
  53. Maple OIT
  54. Matsushita PLC
  55. MELSEC A
  56. MELSEC Q
  57. Memory PLC
  58. Micro PLC
  59. MicroSmart PLC
  60. Mitsubishi PLC
  61. Mobile Application
  62. Modbus
  63. Modicon PLC
  64. Momentum PLC
  65. Motion Control
  66. National Instruments PLC
  67. Omron PLC
  68. OPC
  69. PAC
  70. Panasonic PLC
  71. Parking Information using PLC
  72. Password Using PLC
  73. PLC
  74. PLC Analog Input Module
  75. PLC and Android
  76. PLC and Arduino
  77. PLC and CNC
  78. PLC and Computer
  79. PLC and Facebook
  80. PLC and PC
  81. PLC and Servo
  82. PLC and Visual Basic
  83. PLC Battery
  84. PLC Beginner Guide
  85. PLC Book
  86. PLC Cable
  87. PLC Codesys
  88. PLC Companies List
  89. PLC Computers
  90. PLC Design
  91. PLC for 3 Movement
  92. PLC for Assembly Line
  93. PLC for Automatic Welding
  94. PLC for Binding Machine
  95. PLC for Cutting Machine
  96. PLC for Filling Machine
  97. PLC for Fountain Application
  98. PLC for Injection Molding
  99. PLC for Marking
  100. PLC for Packing
  101. PLC for Rotary Bottle Washing
  102. PLC for Snack Vending Machine
  103. PLC for Sorter Machine
  104. PLC for Water Treatment
  105. PLC Hardware
  106. PLC Hybrid
  107. PLC Information
  108. PLC Knowledge
  109. PLC Language
  110. PLC Link Model
  111. PLC Mitsubishi Download
  112. PLC Model
  113. PLC Modules
  114. PLC Real Time Clock
  115. PLC Simulator
  116. PLC Software
  117. PLC Supplier
  118. PLC Types
  119. PLC Wiring
  120. PLC WorkShop
  121. PLC-ANALYZER
  122. PLCSIM
  123. Power Supply for PLC
  124. Profibus
  125. ProSafe PLC
  126. Push ON Push OFF with PLC
  127. Quickpanel Operator Interfaces
  128. Raspberry Pi
  129. Raspberry Pi and PLC
  130. RTU
  131. RTU and PLC
  132. SAS
  133. SCADA
  134. Schneider PLC
  135. SHARP PLC
  136. Siemens PLC
  137. SINUMERIK CNC
  138. Small Modular PLC
  139. Standard Sequence Programming for PLC
  140. Substation Automation System
  141. Teco PLC
  142. Telemetry
  143. TEP PLC
  144. Texas Instruments PLC
  145. Timer Countdown with PLC
  146. Toshiba PLC
  147. Touch Screen PLC
  148. Traffic Light with PLC
  149. TWIDO PLC
  150. Types of PLC
  151. Unitary PLC
  152. Unitronics PLC
  153. VIPA PLC
  154. Vision PLC
  155. Weighing Machine Using PLC
  156. Yokogawa PLC
  157. Zelio PLC

Search This Blog

Loading...
Copyright © 2009- All Rights Reserved