Arduino / NewSoftSerial: Serial Barcode Scanner

I am trying to interface a Symbol LS9208 to my Arduino. I have pins 2 and 3 on the serial cable (DB9) wired to pins 2 and 3 on my Arduino. If I plug the same scanner into a serial port and open a terminal (9600-N-8-1) and scan items and get what I am expecting “06540001126\r”. When I run the following basic code to read from my NewSoftSerial port, I get "6VvöööÖÖ¶6V
". Same number of characters, but obviously something is wrong.

I am pretty new to the wonderful world of Arduino. Hopefully I’m missing something simple and obvious.

Any / all help would be greatly appreciated. Thanks

#include <NewSoftSerial.h>
char c;
NewSoftSerial mySerial(2, 3);
void setup() {
void loop() {
if (mySerial.available()) {
c = (char);

Are you inverting the data? Compared to what the Arduino's UART is expecting, RS232 devices use inverted voltage levels to represent 0s and 1s. You may be able to resolve this by setting the inverted flag in NewSoftSerial.

If the reader is feeding something like +/- 12V (which is possible with true RS-232) the Arduino pins might not be entirely happy about that. In which case you need to reduce the voltage. A chip like a MAX232 converts the voltage and inverts the data for you.

Professor Chaos for the win!

Forgot about the inversion thing. I changed the declaration to:

NewSoftSerial mySerial(2, 3, 1);

and it works as expected. Thanks very much for your help.

Hi there,

I saw your solution for connecting a barcode scanner to an arduino. I did the same thing but used the ps2kayboard library. My problem is that it works great for a while but then suddenly it starts to scan the code all wrong. I.E. the code is 2365295013572 and the input I get is qqqqhh++. Maybe a buffer problem?

Is there a possibility that the newsoftserial library can fix this problem?

Thanks in advance for your time!

Is there a possibility that the newsoftserial library can fix this problem?

The NewSoftSerial library can not make good data out of garbage.

You need to post the code you are using, and a link to the scanner, and a diagram of how it is connected. Then, maybe we can offer some suggestions about where the problem is occurring.

Thanks for the fast response and apologies for the lack of information.

We built a device consisting of an Arduino Duomilanove, an ethernet shield, three leds and two buttons and a barcodescanner (

It works as follows:

  1. Visitor scans card
  2. Two leds (positioned near the two buttons) light up and the visitor is asked to push one of the buttons
  3. Visitor pushes button and a php request is send by the ethernetshield containing the answer.

This setup works perfectly for an hour or so and randomly stops scanning the right barcode as I mentioned before. When I reset the Arduino, everything runs fine again…

I already posted some other issues on this forum concerning the ethernet shield, but these problems are fixed. I can imagine there may be some flaws in the way we connected everything. Everything (LEDs, barcode scanner) draws power from the internal 5 volt line from the arduino, which is powered externally by a 9 Volt adapter. I will post the scheme tomorrow. I also can imagine that it is a simple case of cheap electronics (barcode scanner). We are already going to use a watchdog timer to reset the whole thing as soon as the barcodescanner makes a bad read.

The part of the code that reads the barcode information is as follows (datapin is 3, IRQ pin is 2):

// Add a char to the code buffer if possible, silently fails if not possible.
void addChar(char c) {
if (codeBufferI < sizeof codeBuffer) {
codeBuffer[codeBufferI] = c;

void loop()
// Waiting for barcode
Serial.println(“Waiting for barcode”);
keyboard.begin(codeDataPin, codeIRQPin);
boolean done = false;
barcodeCheck = true;
int charCounter = 0;
while (!done) {
if (digitalRead(buttonAPin) == HIGH && digitalRead(buttonBPin) == HIGH) {
Serial.println(“Exiting debug mode”);
Serial.println(“Entering debug mode”);
if (keyboard.available()) {
char c =;
if (c == PS2_ENTER || charCounter > CHARCOUNTER_TERMINATE){
if (c == PS2_ENTER && charCounter == CHARCOUNTER_TERMINATE) {
Serial.print("[Code succesfully scanned]"); // Code succesvol ingelezen.
if (charCounter > CHARCOUNTER_TERMINATE) {
Serial.print("[Code over CHARCOUNTER_TERMINATE chars, terminating]");
barcodeCheck = false;
if (c == PS2_ENTER && charCounter < CHARCOUNTER_TERMINATE) {
Serial.print("[Code under CHARCOUNTER_TERMINATE chars, terminating]");
barcodeCheck = false;
addChar(’\0’); // End the string
strcpy(code, codeBuffer);
codeBufferI = 0;
done = true;
else {

if (Serial.available() > 0) {
// Waiting for answer
Serial.println(“Waiting for answer”);
digitalWrite(ledAPin, HIGH);
digitalWrite(ledBPin, HIGH);
while (digitalRead(buttonAPin) == LOW && digitalRead(buttonBPin) == LOW) {
digitalWrite(ledAPin, LOW);
digitalWrite(ledBPin, LOW);
if (digitalRead(buttonAPin) == HIGH) {
// Geef antwoord “Ja”
doRequest(code, YES);
else {
// Geef antwoord “Nee”
doRequest(code, NO);