Connecting QR reader to arduino

Hello, I am working on a project with Arduino that involves a waste sorting system using a QR code reader (a GM805 Series UART USB DC5V). For convenience, we decided to use QR codes that contain numbers (1 for plastic, 2 for paper, and 3 for glass). The program is supposed to read the QR code, assign the read value to the variable (s), and use a switch statement to decide which of the three servomotors to activate.

With my limited programming knowledge and thanks to some videos on the internet, I managed to write the code for this project. However, when I moved to the practical part, I encountered a problem with reading the QR codes. I have no idea whether the problem lies in the code or the assembly of the QR reader.

This QR reader has a UART adapter with some cables (GND, 5V, RX, TX, D+, D-). I don't know what D+ and D- are, so I only connected the other pins (also because those two YouTube videos I found with similar QR readers did not have those pins). The GND and 5V are connected to the GND and 5V on the Arduino via the breadboard, and the TX and RX are connected to pins 2 and 3 of the Arduino. With this setup, the QR reader powers on, and if you scan a QR code, it reads it (I don't think this indicates that the assembly or code is correct, but it performs these default actions) but does not send data to the Arduino.

I am attaching the sketch I used and some images of the QR reader. I hope someone can help me find the problem that prevents the reader from communicating the read data to the Arduino.

#include <SoftwareSerial.h>
const int rxPin=2;
const int txPin=3;
int s;
int pulsante = 7;
Servo s1;
Servo s2;
Servo s3;
SoftwareSerial QR(2,3);


void setup(){
  s1.attach(5);
  s2.attach(6);
  s3.attach(9);
  s1.write(90);
  s2.write(90);
  s3.write(90);
  Serial.begin(9600);
  QR.begin(9600);
}

  
    
  
void loop(){
  
  if(QR.available()>0)
  {
  s=QR.read();
    s=s-48;
    Serial.println(s);
    delay(1000);
  } 
  else if(Serial.available()>0)
  {
  s=Serial.read();
    s=s-48;
    Serial.println(s);
  }
   
      
  
  switch(s){
    
     case 1:
     s1.write(0);
        
		delay(5000);
		
        s1.write(90);
      	delay(5000);
		s=0;
    	
    break;
    case 2:
    s2.write(0);
        
		delay(5000);
		
        s2.write(90);
      	delay(5000);
		s=0;
    case 3:
    s3.write(0);
        
		delay(5000);
		s3.write(90);
      	delay(5000);
		s=0;
    	
  
  }
  if(digitalRead(pulsante)== HIGH)
  {
   s1.write(0);
   s2.write(0);
   s3.write(0);
   delay(5000);
   s1.write(90);
   s2.write(90);
   s3.write(90);
   
}
}



This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.