Servo flicker when RFID reader (RDM 630) reads.

I’m doing a cat feeder project that works great except one thing (or two but let’s start with this one).
Setup:

  • Arduino UNO R3
  • Micro servo
  • RFID reader RDM 630

Servo and RFID reader use same ground and 5 v.

The issue is that every time the RFID tag gets close to the reader the servo flickers i.e. move one degree back back and fourth. I’ve tried different pins for both reader and servo but get same result each time.

I stripped down the code so only the part with the servo and the reader are present. Rest is irrelevant here. Here’s the code:

#include <Servo.h>
#include <SoftwareSerial.h>

#define RX_PIN         8   // RX pin for RFID reader.
#define TX_PIN         7   // TX pin for RFID reader. (Not used)
#define SERVO_PIN      10   // Pin for lid servo.

SoftwareSerial RFID = SoftwareSerial(RX_PIN, TX_PIN); // RX and TX new serial port.
Servo lidServo;                                       // create servo object to control servo for box lid
boolean lidOpen;                                      // Keeps track of the lid position.
int okTag[14] = {2,48,67,48,48,50,53,51,54,54,48,55,70,3}; // The correct RFID tag number.
int tagNr[14] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0};        // Number returned from RFID reader.

void setup()
{
  pinMode(RX_PIN, INPUT);
  pinMode(TX_PIN, OUTPUT);
  pinMode(SERVO_PIN, OUTPUT);
  RFID.begin(9600);            // start serial to RFID reader.
  Serial.begin(9600);          // start serial to PC.
  lidServo.attach(SERVO_PIN);  // attaches the servo to the servo object.
  lidServo.write(180);         // Close the lid.
  lidOpen = false;             // lid closed from beginning.
}

void loop()
{
  if (RFIDReader()) {                    // Read RFID reader if something is in range.
    if (compareTags(okTag, tagNr)) {     // Check if correct tag.
      Serial.println("Correct tag!");
      if (!lidOpen) {                    // Check if lid is open.
        lidOpen = moveLid(lidOpen);      // Open lid if closed.
      }
    }
    else {                               // Wrong tag read. 
      Serial.println("Wrong tag!");
      if (lidOpen) {                     // Check lid open.
        Serial.println("Closing lid.");
        lidOpen = moveLid(lidOpen);      // Close lid.
      }        
    }
  }
  delay(200);                                                 // Add delay before next round of checks
}

boolean RFIDReader(){              //Checks if there's a tag number available.
  boolean returnValue = false;
  if (RFID.available() > 0) 
  {
    returnValue = true;            // Got something.
    delay(100);                    // needed to allow time for the data to come in from the serial buffer.
    for (int z = 0 ; z < 14 ; z++) // read the rest of the tag
    {
      tagNr[z] = RFID.read();
    }
    RFID.flush();                  // stops multiple reads
  }
  return returnValue;
}

boolean moveLid(boolean openLid) {      // Opens or close the lid. Return the position of lid after move.
  int pos;                              // variable to store the servo position
  if (openLid){
    for(pos = 0; pos < 180; pos++) {    // goes from 0 degrees to 180 degrees in steps of 1 degree 
      lidServo.write(pos);              // tell servo to go to position in variable 'pos' 
      delay(15);                        // waits for the servo to reach the position 
    }  
  }
  else {
    for(pos = 180; pos >= 1; pos -= 1) { // goes from 180 degrees to 0 degrees                               
      lidServo.write(pos);               // tell servo to go to position in variable 'pos' 
      delay(15);                         // waits for the servo to reach the position 
    }
  }
  return !openLid;
}


boolean compareTags(int a[14], int b[14]) { //Compare two tags.
  boolean returnValue = true;
  for (int i = 0 ; i < 14 ; i++) {
    if (a[i] != b[i]){                      // Check each position.
      returnValue = false;                  // If different end and return false.
      i = 14;
    }
  }
  return returnValue; 
}

Any idea what could cause this flicker? Arduino board or reader or maybe servo or something else? My programming?

Thanks!

/Andreas

Nobody has any idea what this could be?

Servo and RFID reader use same ground and 5 v.

I don’t see anything in your code that would produce this issue, so it sounds electrical. What is powering these devices? Hopefully not the arduino.

It's power by the +5V pin on the Arduino so your fear is correct. I'm a programmer not an electrician. :blush:

How do I set that up with an external source? The ground needs to shared among all devices right? including the UNO. Should minus from the external source be connected to same ground and plus for all devices exept the UNO connected to external power source?

Ante_Man: It's power by the +5V pin on the Arduino so your fear is correct. I'm a programmer not an electrician. :blush:

How do I set that up with an external source? The ground needs to shared among all devices right? including the UNO. Should minus from the external source be connected to same ground and plus for all devices exept the UNO connected to external power source?

That's it.

Thanks!

I will test if that makes a difference.

So, finally I got some time to test this. I took 4 x 1,5v AA batteries (= 6v) and connected minus to ground on Arduino and plus 6v to plus on the servo. I hooked up the Arduino using USB and the servo totally flipped out. It went back and fourth in full speed.

I then loaded the Sweep program and removed everything except the servo. My setup now looks like this. Arduino connected to PC with USB. Servo connected to Arduino on pin 9 and ground on ground. Plus on servo connected on plus 6v on battery pack and minus on battery pack connected on Arduino and servo ground. Same result. The servo went crazy. It goes back and fourth in full speed for a couple of turns. The one turn slow and then back to full speed and suddenly one turn slow and so on.

I got no idea what I'm doing wrong. I check and the servo can take 4,8v - 6v. The servo works perfect if I connect it to the Arduino 5v pin.

Any ideas?

Edit: Found the issue here. The batteries were bad. Replaced for new once and suddenly it worked!

So, now the servo works with external power source. I added back the RFID reader to test. Now servo use external power source and rfid reader use Arduino 5v power supply. I still get the same result. When the reader reads a tag the servo flickers. Really strange. New ideas?

Hi, your RFID tag reader is a pulse RF transmitter, check the spec of the reader, it should tell you how much current is needed during a read process. All the same I'd have the RFID on its own supply, as the pulse current would cause the arduino almost do a reset, if not put an unwanted pulse on the servo signal line.

Tom..... :)