I was working on an Electronic Door Lock/Unlock system using Arduino Uno and RFID Reader/Tags on Ubuntu 18.04.02 lts.

Now the problem is that whenever I punch-in the correct RFID tag to the RFID reader, the Serial Monitor stops working and I notice that the "Port" value under (tools>Port) has also changed or even got un-selected.

Like, before my Port = /dev/ttyACM0

then whenever I punch in the correct tag, Port value either becomes None or gets changed to (= /dev/ttyACM1)

Also, after every 2nd or 3rd upload, I get the error message as /dev/ttyACM0: Permission Denied

My code is as follows:

#include <Servo.h>
#include <SPI.h>
#include <MFRC522.h>

#define SS_PIN 10
#define RST_PIN 9
#define ledPin1 A0
#define ledPin2 A1
#define Buzz A2
Servo servo;
int pos = 0;
MFRC522 rc522(SS_PIN, RST_PIN);

void setup() {
  // put your setup code here, to run once:
  rc522.PCD_Init();     // Initialize card reader
  pinMode(A0, OUTPUT);
  pinMode(A1, OUTPUT);
  pinMode(A2, OUTPUT);
  Serial.println("Scan the Card:");

void loop() {
  // put your main code here, to run repeatedly:

  // check if any card is present and also scan only one card if multiple are present
  if(!rc522.PICC_IsNewCardPresent() || !rc522.PICC_ReadCardSerial())  return;

  // check if the type of the card is what we need and not any other card.
  MFRC522::PICC_Type type = rc522.PICC_GetType(rc522.uid.sak);
  if(type!= MFRC522::PICC_TYPE_MIFARE_MINI &&
     type!= MFRC522::PICC_TYPE_MIFARE_1K &&
     type!= MFRC522::PICC_TYPE_MIFARE_4K) return;
  String strID = "";
  for(byte i=0; i<4; i++) strID += (rc522.uid.uidByte[i] < 0x10 ? "0" : "") + String(rc522.uid.uidByte[i], HEX) + (i != 3 ? ":" : "");

  // put ID in capitals
  Serial.print("Card: ");

  // Do the verification
  if(strID.indexOf("92:AA:CD:73") >=0){
    Serial.println("Access Granted");
    digitalWrite(A0, HIGH);
    tone(Buzz, 3000, 500);
    for (pos = 0; pos <= 60; pos += 1) {  // goes from 0 degrees to 60 degrees
    // in steps of 1 degree
    servo.write(pos);                // tell servo to go to position in variable 'pos'
    delay(10);                       // waits 10ms for the servo to reach the position
  for (pos = 60; pos >= 0; pos -= 1) {  // goes from 60 degrees to 0 degrees
    servo.write(pos);                   // tell servo to go to position in variable 'pos'
    delay(10);                          // waits 10ms for the servo to reach the position
    digitalWrite(A0, LOW);
    Serial.println("Access Denied");
    digitalWrite(A1, HIGH);
    tone(Buzz, 300, 200);
    tone(Buzz, 300, 200);
    tone(Buzz, 300, 200);
    digitalWrite(A1, LOW);

Please Help!

Thanks in Advance.

  • Sounds like your code is crashing.
    – Majenko
    Commented Apr 27, 2019 at 12:22
  • Same code was working in Windows, but showing peculiar output in ubuntu. Also, can you help me out with why every second time I need to grant permission to ttyACM0/ttyACM1? Commented Apr 27, 2019 at 12:26
  • on Windows you didn't notice the reset, because the port didn't change?
    – Juraj
    Commented Apr 27, 2019 at 17:42
  • Comment out all the code related to what happens when you tap the right tag. Then add it back in a few lines at a time until it fails.
    – Majenko
    Commented Apr 28, 2019 at 11:16


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.