Hey
I have bought Barcode Scanner Module, 1D/2D and programmed it. This scanner should control the servo motor.
When barcode scanners scan the barcode, if the third number is 8, the servo motor goes to 90degrees and comes back (to open the door). Although I have scanned the POR232 code, my scanner cannot scan the EAN code. So my servo motor does not work correctly. I have copied my codes here
Can someone help me to correct my codes?
#include "Servo.h"
#include "SoftwareSerial.h"
#include "SparkFun_DE2120_Arduino_Library.h"
SoftwareSerial softSerial(2, 3); //RX, TX: Connect Arduino pin 2 to scanner TX pin. Connect Arduino pin 3 to scanner RX pin.
DE2120 scanner;
#define BUFFER_LEN 40
char scanBuffer[BUFFER_LEN];
Servo myServo;
void setup()
{
myServo.attach(9);
Serial.begin(38400);
Serial.println("DE2120 Scanner");
if (scanner.begin(softSerial) == false)
{
Serial.println("Scanner did not respond. Please check wiring. Did you scan the POR232 barcode? Freezing...");
while (1)
;
}
Serial.println("Scanner online!");
}
void loop()
{
myServo.write(0);
if (scanner.readBarcode(scanBuffer, BUFFER_LEN))
{
Serial.println("Code found: ");
for (int i = 0; i < strlen(scanBuffer); i++)
Serial.println(scanBuffer*);*
-
Serial.println();*
-
myServo.write(90);*
-
delay(50000);*
-
myServo.write(0);*
-
}*
-
delay(200);*
}