Issue with coding barcode scanner

I am using the 2D Barcode Scanner Breakout device for my project on arduino. So far what I am doing is using a switch/case system where we have 4 different barcodes and when a certain barcode is scanned it activates the case and starts a sequence. Once one barcode is scanned, we see the barcode come up in the serial monitor and then we use a vibrating motor with a short delay before and after, then the case ends. Each barcode activates the same vibrating motor but each one has a different initial delay. Although once we switch to another barcode, no new code is “identified” in the serial monitor and the same sequence with the prior barcode begins. If you’d like I can attach the arduino code to show the issue. Thanks in advance!

Share the code :smiley:

/*

Begin scanning for barcodes

By: Nick Poole

SparkFun Electronics

Date: April 14th 2020

License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).

This example demonstrates how to get the scanner connected and will output any barcode it sees.

NOTE: You must put the module into TTL mode by scanning the POR232. barcode in the datasheet.

This will put the module in the correct mode to receive and transmit serial. The baud rate in POR232

defaults to 115200 which is too fast for software serial. This library will automatically set the baud rate to 9600bps.

To connect the barcode scanner to an Arduino:

(Arduino pin) = (Scanner pin)

2 = TX pin on scanner

3 = RX pin on scanner

GND = GND

3.3V = 3.3V

*/

#include “SoftwareSerial.h”

SoftwareSerial softSerial(2, 3); //RX, TX: Connect Arduino pin 2 to scanner TX pin. Connect Arduino pin 3 to scanner RX pin.

#include “SparkFun_DE2120_Arduino_Library.h” //Click here to get the library: http://librarymanager/All#SparkFun_DE2120

DE2120 scanner;

#define BUFFER_LEN 40

char scanBuffer[BUFFER_LEN];

int motorPin = 4; //motor transistor is connected to pin 4

void setup()

{

Serial.begin(115200);

if (scanner.begin(softSerial) == false)

{

Serial.println(“Scanner did not respond. Please check wiring. Did you scan the POR232 barcode? Freezing…”);

while (1)

;

}

{

pinMode(motorPin, OUTPUT);

}

}

void loop()

{

if (scanner.readBarcode(scanBuffer, BUFFER_LEN))

{

Serial.print("Code found: ");

for (int i = 0; i < strlen(scanBuffer); i++)

Serial.print(scanBuffer*);*
Serial.println();

//Serial.println(scanBuffer[6]);
switch (scanBuffer[6]) {
/* case ‘1’:
delay(10);
break;
case ‘2’:
delay(10);
break;
*/
case ‘3’:

Serial.println(“Station recognized: Secaucus Junction”);
delay(2000); // delay one second
digitalWrite(motorPin, HIGH); //vibrate
delay(3000); //wait 1 seconds.
digitalWrite(motorPin, LOW); //vibrate

break;
case ‘4’:

Serial.println(“Station recognized: Newark Broad Street”);
delay(4000); // delay one second
digitalWrite(motorPin, HIGH); //vibrate
delay(3000); //wait 1 seconds.
digitalWrite(motorPin, LOW); //vibrate

break;
case ‘5’:
Serial.println(“Station recognized: Brick Church”);
delay(5000); // delay one second
digitalWrite(motorPin, HIGH); //vibrate
delay(3000); //wait 1 seconds.
digitalWrite(motorPin, LOW); //vibrate

break;
case ‘6’:
Serial.println(“Station recognized: Orange”);
delay(6000); // delay one second
digitalWrite(motorPin, HIGH); //vibrate
delay(3000); //wait 1 seconds.
digitalWrite(motorPin, LOW); //vibrate

break;

default: ;
}

}
}