Bar code scanner not working

Hello, I am using this QR/Barcode Scanner. I want to use it with an arduino uno to scan barcodes however when it detects a barcode it just beeps and doesn't return anything on the serial monitor. I connected the vcc to 5v, gnd to gnd, and then connected the green tx pin to pin 0 and white rx pin to pin 1. Here's the code I'm using

#include <SoftwareSerial.h>
SoftwareSerial mySerial(0, 1); // RX, TX
 
void setup()
{
  Serial.begin(9600);  
  mySerial.begin(9600); // set the data rate for the SoftwareSerial port
}
 
void loop()
{
  if (mySerial.available()) // Check if there is Incoming Data in the Serial Buffer.
  {
    while (mySerial.available()) // Keep reading Byte by Byte from the Buffer till the Buffer is empty
   {
      char input = mySerial.read(); // Read 1 Byte of data and store it in a character variable
      Serial.print(input); // Print the Byte
      delay(5); // A small delay
    }
  }
}

So can anyone tell me if there's something wrong with the code or if I'm not connecting the data pins to the right places for an uno?

#include <SoftwareSerial.h>
SoftwareSerial mySerial(4, 5); // RX, TX (0 and 1 colliding with hardware serial pins)
 
void setup()
{
  Serial.begin(9600);  
  mySerial.begin(9600); // set the data rate for the SoftwareSerial port
}
 
void loop()
{
  if (mySerial.available()>=1) // Check if there is Incoming Data in the Serial Buffer.
  {
    while (mySerial.available()) // Keep reading Byte by Byte from the Buffer till the Buffer is empty
   {
      char input = mySerial.read(); // Read 1 Byte of data and store it in a character variable
      Serial.write(input); // Print the Byte
      delay(5); // A small delay
    }
  }
}
SoftwareSerial mySerial(0, 1); // RX, TX

There is the problem

Don't use pins 0 and 1 with SoftwareSerial because the are already used by the hardware (USB) Serial interface

1 Like

OK, I thought you had to connect the tx and rx to the rx and tx. So can I just use any pins like (2,3)?

Yes

Great, I'll try it when I get home and see what happens.

Also I'm noticing almost all of the tutorials for this scanner uses the arduino Nano. Using a uno shouldn't cause any problems right?

There should be no problem

For your purposes the 2 boards are functionally identical

Ok I switched it to pins 4 and 5 and it has an extended beep and then nothing shows on the serial monitor. I was doing some tests and it doesn't even get past the if(mySerial.available()){
so for some reason it can detect a barcode but whenever it reads it it doesn't give any data to the serial monitor. Do I need to specify I'm trying to read barcodes? Or is this component just dysfunctional.

There seems to be some confusion about the serial interface of the barcode reader that you linked to

At one point on the page the serial interface is described like this

USB and TTL dual interface

and in another

Connectivity Technology RS232, USB Cable

RS232 and TTL are not the same thing. The Arduino uses TTL levels and cannot directly use an RS232 interface. Have you got a data sheet for the scanner that clarifies what type of serial interface it has ?

Ok on the amazon link it says it's a USB and TTL dual interface

Oh wait did you mean on the amazon link that it is saying 2 different things? Because in that case I do not have a data sheet for it.

Yes. They are saying 2 different things

If you have no data sheet then how did you know how to connect the scanner to the Arduino ?

I wanted to know how to read barcodes with an arduino and found this tutorial.

It is just more inconvenient than the Nano. :roll_eyes:

So why did you connect it differently to what the tutorial explains? :face_with_raised_eyebrow:

Well in the tutorial it says to connect it to pin 4 and 5 and I assumed that that was the tx and rx of the Nano. Turned out to be wrong but when I changed that to pin 4 and 5 of the uno it still didn't work.

Post your code.

I did, at the top

:rofl:

Sure. But you have changed it since.