# Interfacing barcode scanner with arduino using RS232

I want to connect a barcode scanner with Arduino. I used MAX232 to convert the levels. I have taken only 3 pins: 2(RX), 3(TX) and 5(GND) from the DB9 cable and given them to pins of MAX232 as shown in the figure:

This is the code written in Arduino:

#include <SoftwareSerial.h>
SoftwareSerial mySerial(6, 7); // RX, TX

void setup()
{
Serial.begin(9600);
pinMode(6,INPUT);
pinMode(7,OUTPUT);
mySerial.begin(9600);
}

void loop()
{
if (mySerial.available())
}


When I move the TX pin on DB9, I get readings like 255, 240, 189, etc., i.e. random numbers. However, when I scan the barcode, I am not getting any output. I also checked the output of TX pins on an oscilloscope, which showed symmetric waves for a very short amount of time. Again, when the pin 12 of MAX232 (TTL output) was connected to the oscilloscope, no reading was observed.

• Do you know what is the protocol the scanner is communicating? – Eugene Sh. Feb 6 '15 at 18:47
• Have you used the correct capacitors around your MAX232? – brhans Feb 6 '15 at 18:49
• Yes, I have programmed it to run on RS232 protocol. I connected it with a desktop and received the proper value in decimal. – explorer Feb 6 '15 at 18:51
• Yes, the connections of all the five capacitors are as per the diagram. – explorer Feb 6 '15 at 18:52
• btw, can you show how exactly pins are connected to the DB9? – Eugene Sh. Feb 6 '15 at 19:46