Table of Contents
Prev
Start: of Posts Show
Next

Barcode Reader / Scanner USB on PLC using Arduino USB Host Shield


This application about barcode reader/scanner USB for use on PLC, with additional hardware using Arduino Uno and Arduino USB Host Shield.

Transfer data from barcode reader /scanner to arduino using HID (Human Interface Device) protocol and transfer data from arduino to PLC using Modbus protocol.

Example application with barcode reader/scanner in industrial such as Kanban System or Toyota's "just-in-time" (JIT) production system, counting the number of products, accessing machine with barcode card , lamp/light control with barcode card, and other application.

For example, I use light control using barcode.



Barcode Reader Scanner USB on PLC for Light Control

Hardware Preparation:
1. Barcode reader/scanner USB
2. Arduino USB Host Shield
3. Arduino UNO
4. Serial Port Module, TTL to RS232 male connector
5. RS232 PLC Cable for Siemens S7-200 PLC
6. Siemens S7-200 PLC

Hardware of Barcode Application On PLC


Hardware Connection:

Hardware Connection of Barcode on PLC

Barcode for Light ON / Light OFF:

Barcode on PLC (Programmable Logic Controller)

Download Project File:
1. Arduino Project File (BarcodeToPLCviaModbus), click here


2. PLC ladder programming (BarcodePLCModbus), click here

Barcode Setting in PLC Ladder Programming:
Download Character to Value (ASCI code), click here

Setting of Barcode Value in PLC ladder programming


Arduino Code:
#include <hid.h>
#include <hiduniversal.h>
#include <usbhub.h>
#include <avr/pgmspace.h>
#include <Usb.h>
#include <usbhub.h>
#include <avr/pgmspace.h>
#include <hidboot.h>

#include <SimpleModbusMaster.h> 
//Arduino Serial Port Connect to Port 0 of Siemens PLC S7 200
#define slaveAddr 1
#define baud 9600
#define timeout 1000
#define polling 200
#define retry_count 0
#define TxEnablePin 2 
enum
{
  PACKET1,
  TOTAL_NO_OF_PACKETS
};
Packet packets[TOTAL_NO_OF_PACKETS];
packetPointer packet1 = &packets[PACKET1];
#define Char_Max 20
unsigned int writeRegs[Char_Max];
boolean ModbusUpdate=true;
static uint32_t update_time = 0;  


USB     Usb;
USBHub     Hub(&Usb);                                          
HIDUniversal      Hid(&Usb);                                  
HIDBoot<HID_PROTOCOL_KEYBOARD>    Keyboard(&Usb);
 
class KbdRptParser : public KeyboardReportParser
{
        void PrintKey(uint8_t mod, uint8_t key);
protected:
 virtual void OnKeyDown (uint8_t mod, uint8_t key);
 virtual void OnKeyPressed(uint8_t key);
};
 
void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key) 
{
    uint8_t c = OemToAscii(mod, key);
 
    if (c)
        OnKeyPressed(c);
}
 

void KbdRptParser::OnKeyPressed(uint8_t key) 
{
static uint32_t next_time = 0;    
static uint8_t index_array = 0;

    if( millis() > next_time ) {
      memset(writeRegs,0,sizeof(writeRegs));
      index_array = 0;
      writeRegs[0] = (word) 0;
    }
    
    next_time = millis() + 100;   
    
    index_array++;    
    if (index_array<Char_Max){
      writeRegs[index_array] = (word) key;
      ModbusUpdate=true;
      update_time = millis() + 500;
    }else{
      //Error, I use value 255
      writeRegs[0] = (word) 255;  
      ModbusUpdate=false;  
    }
    
};
 
KbdRptParser Prs;
 
void setup()
{
    modbus_construct(packet1, slaveAddr, PRESET_MULTIPLE_REGISTERS, 0, 20, writeRegs);
    modbus_configure(&Serial, baud, SERIAL_8E1, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS);  
    if (Usb.Init() == -1) {
        //Error, I use value 255
        writeRegs[0] = (word) 255;
        ModbusUpdate=false;
    }
 
    delay( 200 );
 
    Hid.SetReportParser(0, (HIDReportParser*)&Prs);
    delay( 200 );
}
 
void loop()
{
  Usb.Task();
  if(ModbusUpdate)modbus_update();  
  if( millis() > update_time ) ModbusUpdate=false;  
}



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

ShareTo
Share on Facebook Tweet this Share to Google Plus
CLOSE

Enter Your Email Address




All Labels

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

Search This Blog

Loading...
Copyright © 2009- All Rights Reserved