SoftwareSerial affected by proximity sensor

Hi,

I need to build an Arduino prototype that uses Parallax RFID reader and a Sharp IR proximity sensor.
If I take any of the sample codes from here: Arduino Playground - PRFID
I can read perfectly my tags.

But as soon as I plug a Sharp IR proximity sensor on Arduino UNO, whatever pin (digital, analog), with or without declaring its pin in the Arduino file, the Arduino file doesn't read the tags any more.

I have tried to use Arduino hardware Serial, SoftwareSerial, ReceiveOnlySoftwareSerial and I get the same result.

The RFID reader works fine on its own.
The proximity sensor works fine on its own.
But when I combine both, the proximity sensor works but not the RFID reader anymore.

Any idea why it’s behaving like this?
Thanks in advance.

Code example I’m using:

#include <SoftwareSerial.h>

#define enablePin  7 
#define rxPin      8  
#define txPin      9  

int i=20;


#define BUFSIZE    11  
#define RFID_START  0x0A  // RFID Reader Start and Stop bytes
#define RFID_STOP   0x0D

SoftwareSerial rfidSerial =  SoftwareSerial(rxPin, txPin);

void setup()  {
  
  pinMode(enablePin, OUTPUT);
  pinMode(rxPin, INPUT);


  digitalWrite(enablePin, HIGH);  // disable RFID Reader
  
  Serial.begin(9600);
  while (!Serial);   
  Serial.println("\n\nParallax RFID Card Reader");
  

  rfidSerial.begin(2400);

  Serial.flush();   // wait for all bytes to be transmitted to the Serial Monitor
  
  
} 
 
void loop()  {
  digitalWrite(enablePin, LOW);  
  
  char rfidData[BUFSIZE];  
  char offset = 0;        
  rfidData[0] = 0;         
  
   if(rfidSerial.available()>0){
      rfidData[offset]=rfidSerial.read();      
      if (rfidData[offset]==RFID_START){
        while (offset<BUFSIZE){         
          if (rfidSerial.available()>0){
            rfidData[offset]=rfidSerial.read();
            if (rfidData[offset]==RFID_STOP){
              rfidData[offset]=0;
              break;}
            else{ offset++;}
          }
        }
        offset=0;
        Serial.println(rfidData);
      }       
      delay(10);
  }
}

Kind of strange.

The proximity sensor is simply an Analog input, right? You're not communicating to it via any protocol. So I'd be shocked if your RFID reader somehow interferes with it. But it's the other way around..when you plug in your proximity sensor, it still functions (why wouldn't it) but your RFID reader which you talk to via UART (be it hardware of software bitbanged) does not.

  • How are you powering your arduino?
  • I don't see anything within your code to read the proximity sensor and make sure it's working properly. Or to init an Analog pin. Where, in the code that you posted, do you verify that the Proximity sensor is functioning while your RFID is not?