Thursday, June 12, 2014

PLC Analog Input Module With Arduino




Using Arduino as a replacement PLC Analog Input Module is a replacement at a cheap price. In this case, only use Siemens S7-200 PLC. See the video below, is the end result of use Arduino in PLC applications. In Arduino: Using the analog input voltage between 0V to 5V, and in PLC: Converted to a digital value between 0 to 1023.
PLC Analog Input Module Replaced by Arduino Nano V3.0
PLC Analog Input Module With Arduino


Arduino, TTL to RS232 and Potentiometer for Testing Variable Voltage.
Arduino, TTL to RS232 and Potentiometer

Step by step replacement PLC Analog Input Module with Arduino (Only Siemens S7-200 PLC):
A. Arduino Hardware and Programming:
1. Download the Arduino Software, click here
2. Install the Arduino software.
3. Connect Arduino Nano V3.0 to Computer use Mini USB.
Connect Arduino Nano V3.0 to Computer use Mini USB

4. Check the port number in Device Manager Computer.
Check the port number in Device Manager Computer

5. Download Project File (file name is "plcandarduino") , click here
6. Open File name "plcandarduino".
Open File name plcandarduino

7. Set Board to Arduino Nano w/ ATmega328.
Set Board to Arduino Nano with ATmega328

8.Set Serial Port to COM19 or Same with port number in Device Manager Computer.
Set Serial Port to COM19

9. Check Arduino Type and COM.
Arduino Type and COM

10. Click Upload.
Arduino Upload

11. Wait until the "Done uploading" and Close the Arduino software.
Arduino Done uploading


B. Arduino and PLC Connection
Arduino and PLC Connection

Remarks:
1. Arduino Nano V3.0.
2. Sensor with Analog Output (AO) Voltage: 0 Volt to 5 Volt.
3. TTL Serial to RS 232 Converter Module.
4. RS232 serial crossover cable / Create your own.
RS-232 serial crossover cable

5. Siemens RS232 PPI Multi-Master Cable.
6. Siemens S7-200 PLC.

C. PLC Ladder Programming And Arduino
1. PLC Ladder Programming for testing, Download: click here
2. Relation between Vw Vaue and Arduino Pin.
Relation between Vw Vaue and Arduino Pin

Remarks: .
2.1. Vw0 Value from Arduino Pin 19 (A0) .
2.2. Vw2 Value from Arduino Pin 20 (A1) .
2.3. Vw4 Value from Arduino Pin 21 (A2) .
2.4. Vw6 Value from Arduino Pin 22 (A3) .
2.5. Vw8 Value from Arduino Pin 23 (A4) .
2.6. Vw10 Value from Arduino Pin 24 (A5) .
2.7. Vw12 Value from Arduino Pin 25 (A6) .
2.8. VW14 Value from Arduino Pin 26 (A7) .

Note:
note1: Arduino A0 ~ A7 connect to Sensor with Analog Output (AO) Voltage: 0 Volt to 5 Volt. .
note2: 0 Volt is equal to Vw = 0, and the 5 Volt is equal to Vw = 1023 .

CheckOut Video : PLC Analog Input Module Replaced by Arduino Nano V3.0

D. Arduino Source Code
void setup(){
  Serial.begin(9600,SERIAL_8E1);//9600,8,Even,1
}

void loop(){
  // read the input on analog pin 0 to pin 7:
  int VW0 = analogRead(A0);
  int VW2 = analogRead(A1);
  int VW4 = analogRead(A2);
  int VW6 = analogRead(A3);
  int VW8 = analogRead(A4);
  int VW10 = analogRead(A5);
  int VW12 = analogRead(A6);
  int VW14 = analogRead(A7);

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

  byte str_write[53];
  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;//H0  ' type VW
  str_write[27] = (byte)0x84;//H82  'type VW
  str_write[28] = (byte)0x00;//H0

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


  str_write[35] = (byte)(VW0 / 256);
  str_write[36] = (byte)(VW0 % 256);

  str_write[37] = (byte)(VW2 / 256);
  str_write[38] = (byte)(VW2 % 256);

  str_write[39] = (byte)(VW4 / 256);
  str_write[40] = (byte)(VW4 % 256);

  str_write[41] = (byte)(VW6 / 256);
  str_write[42] = (byte)(VW6 % 256);

  str_write[43] = (byte)(VW8 / 256);
  str_write[44] = (byte)(VW8 % 256);

  str_write[45] = (byte)(VW10 / 256);
  str_write[46] = (byte)(VW10 % 256);

  str_write[47] = (byte)(VW12 / 256);
  str_write[48] = (byte)(VW12 % 256);

  str_write[49] = (byte)(VW14 / 256);
  str_write[50] = (byte)(VW14 % 256);

  for (i = 4; i <= 50; i++)
  {
      Temp_FCS = Temp_FCS + str_write[i];
  }
  str_write[51] = (byte)(Temp_FCS % 256);
  str_write[52] = (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);
}



Labels:



Newer Post Older Post Home

You may also like these ebook:

Get Free PLC eBook directly sent to your email,
and email subscription to program-plc.blogspot.com




We hate SPAM. Your information is never sold or shared with anyone.

Your Email Will Be 100% Secured !

Your email is stored safely on Google FeedBurner