# QR code reader with processing and arduino

**URL:** <https://discourse.processing.org/t/qr-code-reader-with-processing-and-arduino/7349>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [January 9, 2019, 6:49am UTC](https://discourse.processing.org/t/qr-code-reader-with-processing-and-arduino/7349 "2019-01-09T06:49:56Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![yoshvale](https://avatars.discourse-cdn.com/v4/letter/y/a5b964/32.png) [@yoshvale](https://discourse.processing.org/u/yoshvale)\
**Post date:** [January 9, 2019, 6:49am UTC](https://discourse.processing.org/t/qr-code-reader-with-processing-and-arduino/7349/1 "2019-01-09T06:49:57Z")

</div>

hi i’m yoshua, i’m new in processing  
my project is robot arm that can read 2 qr code (i.e : object A and object B) and send the data to arduino, so arduino will receive qr data, if arduino read object A then arm robot move to position A, and if arduino read object B then arm robot move to position B

i’m using qr code processing code from shiffman, my question is how the qr code data send to arduino ?

can anyone can help me please with the code ? i’m so stuck that i can’t find answers in google  
thank you

---

<div class="post-metadata">

**Author:** ![Architector\_4](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/architector_4/32/813_2.png) [@Architector\_4](https://discourse.processing.org/u/Architector_4)\
**Post date:** [January 9, 2019, 6:58am UTC](https://discourse.processing.org/t/qr-code-reader-with-processing-and-arduino/7349/2 "2019-01-09T06:58:31Z")

</div>

I can’t help with code, but I think you should split your task into separate, individual problems:

1. Read QR code with Processing;
2. Convert your data to a format you can send to Adruino in Processing;
3. Send data from Processing to Adruino;
4. Have Adruino receive it and process it;
5. Have Adruino move the robot arm.

Are you good with Adruinos? Can you make your Adruino move the arm by itself with code? What steps can you do right now?

I suggest you to solve each of these problems independently, and only then connect the solutions. And if you can’t, solve steps that you can independently of others, and then tell us which steps you are stuck on.

---

<div class="post-metadata">

**Author:** ![yoshvale](https://avatars.discourse-cdn.com/v4/letter/y/a5b964/32.png) [@yoshvale](https://discourse.processing.org/u/yoshvale)\
**Post date:** [January 9, 2019, 7:13am UTC](https://discourse.processing.org/t/qr-code-reader-with-processing-and-arduino/7349/3 "2019-01-09T07:13:34Z")

</div>

i have make arduino code to move arm by itself with string in arduino  
i’m stuck in point 2, 3, and 4, i don’t know how to convert qr code data to something that arduino can read, any ideas ?

but is it possible right to take qr data on processing (i.e convert qr data to variable) ?

---

<div class="post-metadata">

**Author:** ![Architector\_4](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/architector_4/32/813_2.png) [@Architector\_4](https://discourse.processing.org/u/Architector_4)\
**Post date:** [January 9, 2019, 8:19am UTC](https://discourse.processing.org/t/qr-code-reader-with-processing-and-arduino/7349/4 "2019-01-09T08:19:19Z")

</div>

Processing is pretty much Java, so it must be possible.  
I don’t know much about Adruinos, because I don’t have any, so I can’t help you in that part, but I think I can help you with the step 2 - then, you can find information on communicating between Processing and Adruino yourself - Google seems to return plenty of information on that topic.  
In which format do you get the QR code data? Is it a `String`? An image?  
Where can I find the processing code for QR you mentioned in your first message?

---

<div class="post-metadata">

**Author:** ![yoshvale](https://avatars.discourse-cdn.com/v4/letter/y/a5b964/32.png) [@yoshvale](https://discourse.processing.org/u/yoshvale)\
**Post date:** [January 9, 2019, 8:33am UTC](https://discourse.processing.org/t/qr-code-reader-with-processing-and-arduino/7349/5 "2019-01-09T08:33:55Z")

</div>

here you are [http://makezine.com/2011/03/02/codebox-use-qr-codes-in-processing/](http://makezine.com/2011/03/02/codebox-use-qr-codes-in-processing/)

when i run the code, new window appear with what webcam capture, and when i put qr code, the data show up in yhat window

---

<div class="post-metadata">

**Author:** ![yoshvale](https://avatars.discourse-cdn.com/v4/letter/y/a5b964/32.png) [@yoshvale](https://discourse.processing.org/u/yoshvale)\
**Post date:** [January 9, 2019, 8:49am UTC](https://discourse.processing.org/t/qr-code-reader-with-processing-and-arduino/7349/6 "2019-01-09T08:49:57Z")

</div>

// IMPORT THE ZXING4PROCESSING LIBRARY AND DECLARE A ZXING4P OBJECT  
import com.cage.zxing4p3.\*;  
ZXING4P zxing4p;

// PROCESSING VIDEO LIBRARY  
import processing.video.\*;  
Capture video;

// PIMAGE WITH THE BARCODES TO DETECT  
PImage scanArea;

// TEXT THAT WAS FOUND  
String decodedText;  
String latestDecodedText = “”;

// FORMAT OF THE LATEST FOUND BARCODE  
String barcodeFormat = “”;

int txtWidth;

// FOR THE VIEW FINDER AND SCAN AREA  
int frameWidth = 240;  
int frameHeight = 260;  
int lineSize = 40;

// CORNERS OF THE VIEW FINDER  
PVector ul, ur, ll, lr;

// LIST WITH BARCODE TYPES TO LOOK FOR  
ArrayList barcodeTypes = new ArrayList();

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
\*

- SETUP
- 

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/  
void setup() {  
size(640, 480);

// LAYOUT  
textAlign(CENTER);  
textSize(30);

// CREATE CAPTURE  
video = new Capture(this, width, height);

// START CAPTURING  
video.start();

// CREATE A NEW EN-/DECODER INSTANCE  
zxing4p = new ZXING4P();

// DISPLAY VERSION INFORMATION  
zxing4p.version();

// UPPER LEFT CORNER OF THE VIEW FINDER  
ul = new PVector((width - frameWidth) \>\> 1, (height - frameHeight) \>\> 1);  
// UPPER RIGHT CORNER OF THE VIEW FINDER  
ur = new PVector(ul.x + frameWidth, ul.y);  
// LOWER LEFT CORNER OF THE VIEW FINDER  
ll = new PVector(ul.x, ul.y + frameHeight);  
// LOWER RIGHT CORNER OF THE VIEW FINDER  
lr = new PVector(ur.x, ur.y + frameHeight);

// AREA TO SCAN  
scanArea = createImage(frameWidth, frameHeight, RGB);

// BARCODE TYPES THAT WILL BE SCANNED FOR  
// SUPPORTED BARCODE TYPES:  
// AZTEC  
// CODABAR  
// CODE\_128  
// CODE\_39  
// CODE\_93  
// DATA\_MATRIX  
// EAN\_13  
// EAN\_8  
// ITF  
// MAXICODE  
// PDF\_417  
// QR\_CODE  
// RSS\_14  
// RSS\_EXPANDED  
// UPC\_A  
// UPC\_E  
// UPC\_EAN\_EXTENSION  
barcodeTypes.add(“EAN\_8”);  
barcodeTypes.add(“EAN\_13”);  
barcodeTypes.add(“DATA\_MATRIX”);  
barcodeTypes.add(“QR\_CODE”);  
} // setup()

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
\*

- DRAW
- 

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/  
void draw() {  
background(0);

// UPDATE CAPTURE  
if (video.available()) video.read();

// DISPLAY VIDEO CAPTURE  
set(0, 0, video);

if (frameCount % 50 == 0) {  
// COPY THE VIEW FINDER AREA TO THE SCAN AREA  
scanArea.copy(video, (int)ul.x, (int)ul.y, frameWidth, frameHeight, 0, 0, frameWidth, frameHeight);  
}

// DISPLAY VIEW FINDER  
pushStyle();  
noFill();  
strokeWeight(4);  
stroke(255, 0, 0);  
line(ul.x, ul.y, ul.x + lineSize, ul.y);  
line(ul.x, ul.y, ul.x, ul.y + lineSize);  
line(ur.x - lineSize, ur.y, ur.x, ur.y);  
line(ur.x, ur.y, ur.x, ur.y + lineSize);  
line(ll.x, ll.y, ll.x + lineSize, ll.y);  
line(ll.x, ll.y - lineSize, ll.x, ll.y);  
line(lr.x - lineSize, lr.y, lr.x, lr.y);  
line(lr.x, lr.y - lineSize, lr.x, lr.y);  
popStyle();

// DISPLAY LATEST DECODED TEXT AND FORMAT  
if (!latestDecodedText.equals("")) {  
pushStyle();  
txtWidth = int(textWidth(latestDecodedText + " (" + barcodeFormat + “)”));  
fill(0, 150);  
rect((width\>\>1) - (txtWidth\>\>1) - 5, 15, txtWidth + 10, 36);  
fill(255, 255, 0);  
text(latestDecodedText + " (" + barcodeFormat + “)”, width\>\>1, 43);  
popStyle();  
} // if (!latestDecodedText.equals(""))

// TRY TO DETECT AND DECODE A QRCODE IN THE VIDEO CAPTURE  
// multiFormatReader(PImage img, boolean tryHarder)  
// multiFormatReader(PImage img, boolean tryHarder, ArrayList barcodeTypes)  
// img: image to scan for barcodes  
// tryHarder: false =\> fast detection (less accurate)  
// true =\> best detection (little slower)  
// barcodeTypes: barcode types to scan for  
try {  
// SCAN FOR ALL AVAILABLE BARCODE TYPES  
//decodedText = zxing4p.barcodeReader(scanArea, false);

```
// SCAN FOR SPECIFIC BARCODE TYPES
decodedText = zxing4p.barcodeReader(scanArea, false, barcodeTypes);

// GET THE TYPE OF THE LAST SCANNED BARCODE
barcodeFormat = zxing4p.getBarcodeFormat();

```

}  
catch (Exception e) {  
// NOT FOUND  
decodedText = “”;  
} // try

if (!decodedText.equals("")) {  
// FOUND A BARCODE!  
if (latestDecodedText.equals("") || (!latestDecodedText.equals(decodedText))) {  
println(“Zxing4processing detected: " + decodedText + " (” + barcodeFormat + “)”);  
}  
latestDecodedText = decodedText;  
} // if (!decodedText.equals(""))  
} // draw()

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
\*

- KEYBOARD HANDLER
- 

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/  
void keyPressed() {  
switch(key) {  
case ’ ':  
// RESET  
decodedText = “”;  
latestDecodedText = “”;  
break;  
} // switch  
} // keyPressed()

---

<div class="post-metadata">

**Author:** ![Architector\_4](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/architector_4/32/813_2.png) [@Architector\_4](https://discourse.processing.org/u/Architector_4)\
**Post date:** [January 9, 2019, 8:57am UTC](https://discourse.processing.org/t/qr-code-reader-with-processing-and-arduino/7349/7 "2019-01-09T08:57:46Z")

</div>

Quick suggestion, please use the little \</\> button in the text box when sending or editing a message `to make it look like this and make code more readable.`

Anyways, looking through the code, I see this:

```auto
if (!decodedText.equals("")) {
  // FOUND A BARCODE!
  if (latestDecodedText.equals("") || (!latestDecodedText.equals(decodedText))) {
    println(“Zxing4processing detected: " + decodedText + " (” + barcodeFormat + “)”);
    latestDecodedText = decodedText;
  } // if (!decodedText.equals(""))
} // draw()

```

From the obvious comment, I guess that this is where you can put an `if` statement and send a message to Adruino. Something like this:

```auto
if (!decodedText.equals("")) {
  // FOUND A BARCODE!
  if (latestDecodedText.equals("") || (!latestDecodedText.equals(decodedText))) {
    println(“Zxing4processing detected: " + decodedText + " (” + barcodeFormat + “)”);
    latestDecodedText = decodedText;
    if(latestDecodedText.equals("Your text for doing something")){
      tellAdruino("please do something");
    } else if(latestDecodedText.equals("Your other text for doing something else")){
      tellAdruino("please do something else");
    } else {
      //tellAdruino("I don't know what this text is but please do anything");
    }
  } // if (!decodedText.equals(""))
} // draw()

```

The `tellAdruino(...` function is not real. Replace the `tellAdruino(` function with whatever function that sends Adruino a message. I don’t know what it is.  
Again, Google has plenty instructions on Processing and Adruino connections. I suggest you to make a completely separate sketch that sends some text to Adruino by clicking anywhere, to make sure you can even send anything to your Adruino, and then combine the code you get as a result with this, replacing the `tellAdruino(`.

Good luck!

---

<div class="post-metadata">

**Author:** ![yoshvale](https://avatars.discourse-cdn.com/v4/letter/y/a5b964/32.png) [@yoshvale](https://discourse.processing.org/u/yoshvale)\
**Post date:** [January 9, 2019, 9:11am UTC](https://discourse.processing.org/t/qr-code-reader-with-processing-and-arduino/7349/8 "2019-01-09T09:11:10Z")

</div>

thank you so much, i’ll give a try and if something happen i’ll replay again

---

<div class="post-metadata">

**Author:** ![yoshvale](https://avatars.discourse-cdn.com/v4/letter/y/a5b964/32.png) [@yoshvale](https://discourse.processing.org/u/yoshvale)\
**Post date:** [January 15, 2019, 7:59am UTC](https://discourse.processing.org/t/qr-code-reader-with-processing-and-arduino/7349/9 "2019-01-15T07:59:42Z")

</div>

hi i’m again, thank you fou your suggestion before, now my arduino can receive qr data and move the arm 😃  
before, the qr code position is fixed to the camera (camera is attached to arm)  
but now i’ve got another problem, can camera detect object that non fixed ? so i can randomly put the qr code in range of camera, so then camera can move closer to qr code and then read it ? thank you again

---

<div class="post-metadata">

**Author:** ![yoshvale](https://avatars.discourse-cdn.com/v4/letter/y/a5b964/32.png) [@yoshvale](https://discourse.processing.org/u/yoshvale)\
**Post date:** [January 21, 2019, 8:48am UTC](https://discourse.processing.org/t/qr-code-reader-with-processing-and-arduino/7349/10 "2019-01-21T08:48:39Z")

</div>

can someone help me ? ☹

---

<div class="post-metadata">

**Author:** ![Hilmi98](https://avatars.discourse-cdn.com/v4/letter/h/c77e96/32.png) [@Hilmi98](https://discourse.processing.org/u/Hilmi98)\
**Post date:** [October 13, 2019, 4:57am UTC](https://discourse.processing.org/t/qr-code-reader-with-processing-and-arduino/7349/11 "2019-10-13T04:57:43Z")

</div>

Hi Yoshua, I’m interested with your project, and i’ve a project that need some methods like your project. what i want to ask is, how the arduino can connect to the camera? and what camera do you use?
