I am troubleshooting my barcode sensor since it is not consistent in reading the barcode, I search for datasheet and found out a QR for restore factory function. I tried to scan it and the barcode scanner stops reading barcodes and always turns on. On other data sheets I found some QR codes to be used when accidentally scanned a restore factory QR but it didn't solve the problem, the scanner still can't read the barcode.
Here is the code:
#include <SoftwareSerial.h> //include library for barcode
#define rxPin 10
#define txPin 11
SoftwareSerial portOne = SoftwareSerial(rxPin, txPin); // TX RX
char barcodeData[7];
int barcodeIndex = 0;
bool barcodeComplete = false;
#define bar_switch1 7 // declare the pin for the first barcode switch
#define prx_snr1 9 //declare the pin for the first proximity sensor
void setup() {
Serial.begin(9600);
while (!Serial)
;
// Set the baud rate for the SoftwareSerial object
portOne.begin(9600);
pinMode(bar_switch1, OUTPUT);
pinMode(prx_snr1, INPUT);
}
void proximity() {
bool sensorState = digitalRead(prx_snr1);
delay(100);
digitalWrite(bar_switch1, sensorState ? LOW : HIGH);
delay(1);
}
void bar1() {
portOne.listen();
if (portOne.isListening()) {
while (portOne.available() > 0) {
char data = portOne.read();
if (data == '\n') {
barcodeComplete = true;
barcodeData[barcodeIndex] = '\0';
barcodeIndex = 0;
break;
}
if (barcodeIndex < 7) {
barcodeData[barcodeIndex] = data;
barcodeIndex++;
}
}
if (barcodeComplete) {
//Serial.print("ID : ");
Serial.print(barcodeData);
if (strcmp(barcodeData, "RND-MNL") == 0) {
//Serial.print(" | Name : ");
Serial.println(" | Round-Mineral");
} else if (strcmp(barcodeData, "RND-ALK") == 0) {
//Serial.print(" | Name : ");
Serial.println(" | Round-Alkaline");
} else if (strcmp(barcodeData, "SLM-ALK") == 0) {
//Serial.print(" | Name : ");
Serial.println(" | Slim-Alkaline");
} else if (strcmp(barcodeData, "RND-MNL") == 0) {
//Serial.print(" | Name : ");
Serial.println(" | Slim-Mineral");
}
barcodeComplete = false;
}
}
}
void loop() {
proximity();
bar1();
}
This is the wiring diagram I used
This is the actual problem, it is stuck on that state, it never turns off but it is not able to read barcodes anymore.

