Abstract: In textile machinery, cotton pressing can produce sparks or embers, leading to substandard textile products. Furthermore, the presence of iron wires or iron-containing alloys in the cotton can damage the knitting equipment. Therefore, a textile inspection device was developed to detect sparks, embers, and iron-containing alloys, triggering an audible and visual alarm upon detection. The product utilizes sensors, a microcontroller, a PLC, and a text display to perform detection, signal transmission, display, and action execution. Practical application has proven that the device can effectively detect sparks, embers, and iron-containing alloys, generating audible and visual alarms. It can also display the data magnitude, the amount of iron content, and whether it is a spark or an iron-containing alloy detected. Keywords: Programmable Logic Controller, Microcontroller, Sensor, Text Display. The textile inspection device comprises a sensing detection section, a signal amplification section, a signal transmission section, a program execution section, and a text display section. The sensing and detection section consists of a photosensitive sensor and an iron alloy sensor. The photosensitive sensor detects open flames and smoldering flames, transmitting the signal to the PLC. The PLC executes corresponding actions, including an audible and visual alarm, and then uses a solenoid valve to draw the detected cotton into the waste bin. The iron alloy sensor detects iron alloys, transmitting an analog signal. This analog signal is amplified by a signal amplifier and then sent to an analog-to-digital converter (ADC) to convert it into a digital signal for the microcontroller. The microcontroller, through programming, converts the analog signal back into a digital signal and transmits it via a RS-232 serial port to a MAX232 microcontroller. The MAX232 then transmits the digital signal to the PLC, which performs corresponding actions based on the digital signal, including an audible and visual alarm, and then uses a solenoid valve to draw the detected cotton into the waste bin. I. Sensing and Detection Section The sensing and detection section is divided into a photosensitive sensor and an iron alloy sensor. The photosensitive sensor detects open flames and smoldering flames, detecting any light present. The iron alloy sensor detects iron wire, screws, and other hard objects containing iron alloys. (I) The process of detecting open and smoldering flames with a photosensitive sensor: The photosensitive sensor uses a 444 photosensitive element with a withstand voltage of 12V. The requirement is to detect both open and smoldering flames. The photosensitive element detects light. The sensor has two identical sensing devices, and they must be aligned precisely. If this is not achieved, the light source cannot be detected. The angle must be 120 degrees to provide good detection capability for both open and smoldering flames. The detected signal is very small, with a voltage of 2-3V. Since the input trigger voltage of the Emerson PLC is 18-24V, the detected signal needs to be pulled up to 18-24V. There are several ways to pull up the level: 1. A transistor switching circuit: The detected signal is applied to the base, triggering conduction and converting the 2-3V to 18-24V, thereby driving the Emerson PLC to perform the corresponding action. 2. Optocoupler Drive: Based on the 2-3V voltage transmitted by the sensor, the LED of the optocoupler is triggered, which in turn triggers the phototransistor. Since the phototransistor voltage is 24V, it can achieve the trigger voltage required by the Emerson PLC. Because the optocoupler provides signal isolation, it filters out spikes and other impurities, retaining only the useful trigger signal. Therefore, this sensor uses this optocoupler drive. (II) Iron Alloy Sensor: Detecting Iron Alloys. The iron alloy sensor detects substances containing iron alloys based on changes in inductance. The iron alloy sensor has inductors distributed at different locations. When iron passes through the inductor, the inductance changes. Based on the magnitude of the change, it can be identified as large, medium, or small iron filings. The principle is Lenz's law: the change in inductance caused by iron passing through the inductor. II. Signal Amplification Section The signal amplification section is mainly designed for iron alloy sensors. Because the change in inductance sensed by the ferroalloy sensor is very small, it does not meet the circuit design requirements. Furthermore, the sensitivity of the circuit can be adjusted within the signal amplification circuit. The signal amplification circuit amplifies the weak signal detected by the ferroalloy sensor through a differential amplifier circuit, and then processes it through chips such as 4066, 3140, OP07AJ, and LM358, further amplifying the weak signal. Regarding the sensitivity issue of the ferroalloy sensor, it can be adjusted in the signal amplification section by changing the distributed resistance of the differential amplifier circuit. III. Signal Transmission Section The signal transmission section is also designed specifically for the ferroalloy sensor. It uses a 51 microcontroller to convert the analog signal to a digital signal. The signal transmission section first processes the analog signal from the ferroalloy sensor through the 0832 analog-to-digital converter module, then sends it to the 51 microcontroller, then to the communication modules MAX232 and MAX485, and finally to the PLC, which executes the corresponding actions. The microcontroller contains a corresponding analog-to-digital converter program, which then passes through a communication circuit. During communication, it's necessary to understand the Modbus protocol. There are two types of communication programs. (I) The analog-to-digital conversion program is as follows: ADCS BIT P3.5; Enable interface ADCLK BIT P3.4; Clock interface ADDO BIT P3.3; Data output interface ADDI BIT P3.3; Data input interface CH EQU 30H; Channel selection register ADOUT_M EQU 31H; Data output register ADCONV: MOV CH,#01H; Load channel selection value; (00H: CH0+CH1-, 01H: CH0-CH1+, 02H: CH+, 03H: CH-) SETB ADDI; Initialize channel selection NOP NOP CLR ADCS; Pull low /CS terminal NOP NOP SETB ADCLK; Pull high CLK terminal NOP NOP CLR ADCLK; Pull low CLK terminal, forming a falling edge MOV A,CH MOV C,ACC.1; Determine the channel selection value MOV ADDI,C NOP NOP SETB ADCLK ; Pull CLK high NOP NOP CLR ADCLK ; Pull CLK low to form a falling edge 2 MOV A,CH MOV C,ACC.0 ; Determine the channel selection MOV ADDI,C NOP NOP SETB ADCLK ; Pull CLK high NOP NOP CLR ADCLK ; Pull CLK low to form a falling edge 3 SETB ADDI NOP NOP MOV R7,#8 ; Prepare to send the next 8 clock pulses AD_11: MOV C,ADDO ; Receive data MOV ACC.0,C RL A ; Shift left once SETB ADCLK NOP NOP CLR ADCLK ; Form one clock pulse NOP NOP DJNZ R7,AD_11 ; Loop 8 times MOV C,ADDO ; Receive data MOV ACC.0,C MOV ADOUT_M,A MOV R7,#8 AD_13: MOV C,ADDO ; Receive data MOV ACC.0,C RR A ;Shift left once SETB ADCLK NOP NOP CLR ADCLK ;Generate one clock pulse NOP NOP DJNZ R7,AD_13 ;Loop 8 times CJNE A,ADOUT_M,ADCONV ;Data verification SETB ADCS ;Pull high /CS terminal CLR ADCLK ;Pull low CLK terminal SETB ADDO ;Pull high data terminal, return to initial state RET (II) The communication program is as follows: MOV TMOD,#10H ;Timer 1 works in mode 1 MOV TH1,#0FFH ;Timer 1 count initial value MOV TL1,#0FDH ;Set baud rate 9600bit/s SETB EA ;Enable interrupt CLR ES ;Disable serial interrupt, send data block length STEB TR1 ;Start timer 1 LCALL LOOP ;Call analog-to-digital conversion program MOV SCON,#40H ;Serial port works in mode 0 MOV SBUF,A ; Send the digital signal from the analog-to-digital converter to SUBF, start sending JNB TI,$ ; Wait for CLR TI to finish sending ; Clear TI IV. Program Execution Section The program execution section is controlled by an Emerson PLC, which processes the signals from the photosensitive sensor and the ferroalloy sensor accordingly. The photosensitive sensor controls the relay through the input/output points; the ferroalloy sensor controls the relay through communication port 1, using the data transmitted via communication. The relay controls the output. The output includes audible and visual alarms and control of the solenoid valve. The program execution consists of two parts: (I) Processing of signals from the photosensitive sensor. The photosensitive sensor outputs two signals. As long as there is a signal, it triggers the input point of the Emerson PLC. According to the internal program processing logic of the Emerson PLC, the corresponding action occurs: an alarm for 10 seconds, driving the solenoid valve, closing the valve, and the exhaust fan drawing the detected cotton into the waste bin. (II) Processing of Signals from Ferrous Alloy Sensors The signal from the ferrous alloy sensor is amplified by a signal amplifier circuit and a microcontroller communication circuit. It is then transmitted via serial communication to the Emerson PLC, which stores the data in its internal memory. Based on the data volume, a data comparison instruction is used to compare the data. The Emerson PLC's internal processing logic then triggers corresponding actions: an alarm is activated for 10 seconds, the solenoid valve closes, and the exhaust fan draws the detected cotton into the waste bin. V. Text Display Section The text display section uses an AutoeViewMD204L text display. It primarily displays the signal volume from the ferrous alloy sensor and, based on the data volume, indicates whether the iron filings are large, medium, or small. This information can be programmed using the AutoeViewMD204L's programming software and displayed on the text display. The AutoeViewMD204L can communicate with the Emerson PLC, hence the selection of the AutoeViewMD204L text display. Conclusion The development of textile inspection equipment has solved a major problem in the textile industry, enabling textile machinery to operate effectively. The use of advanced technology has greatly improved the reliability of textile machinery. References: ① *EC20 Series Programmable Controller User Manual*, Emerson Network Power; ② *AutoeView MD204L Text Display User Manual*; ③ Zhu Dinghua and Dai Ruping, eds., *Microcomputer Principles and Applications*, Tsinghua University Press and Northern Jiaotong University Press, August 2003.