0

I connected EM18 rfid reader to NodeMCU to read rfid card data. It showed card number very quickly and consistently till it was connected to my PC's USB. But when I connected it to 5v power source (mobile phone charger) then it didnt read cards well i.e. sometimes it read and sometime dosent. Thants very strange. Grounds might not be the issue as EM18 is powered from NodeMCU and NodeMCU ultimately connected to source(mobile phone charger)

Code is given below :

int count = 0;
char input[12];
boolean flag = 0;

void setup()
{ 
   pinMode(LED_BUILTIN, OUTPUT);
   // begin serial port with baud rate 9600bps
   Serial.begin(9600);
}

void loop()
{
   if(Serial.available())
   {
      count = 0;
      // Read 12 characters and store them in input array
      while(Serial.available() && count < 12)
      {
         input[count] = Serial.read();
         count++;
         delay(5);
      }
      // turn the LED on (HIGH is the voltage level)
      digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));   
  }
}
  • Where did you see the card number.? Why are you sure it reads the card? Or did you mean the LED goes on, when you said it had read the card number? The only thing I can imagine is that if the MCU is connected to the PC, the if(Serial.available()) is true and can enter the block (for what reason ever). If you have the EM18 also connected to the same Hardware serial port (it seems so) then this connection might fail. check the setup or add a picture of you setup to the question. – Peter Paul Kiefer Jan 3 at 16:39
  • Thanx for reply <3, and yeah you are right ! To check if card is read... in built LED is turned on or off as per above code. When I connect it to PC I have serial monitor thus i see card number and LED blinks accordingly. But when i connect it to power source then cards sometimes read and sometimes not in a single attempt because the in built LED doesn't on or off to prove the same. It seems as the Tx pin got slowed down (just to imagine as this is so strange issue). If you need pictures I can post but there se nothing to show as the setup is very simple. EM18 is just connected to Nodemcu. – Kushagra Behere Jan 3 at 18:34
  • You see the card number in the serial terminal on the PC if this is connected. But you do not write the card number from the MCU to the PC.(at least if that is the original code) I fear you connected the EM18 to the RX TX pins that are also connected to the USB to Serial converter on the board. So the PC can spy and read the card number. I never thought this is possible but it seems so. You should use two serial ports one for the EM18 and the standard port for the PC. Hint: community.blynk.cc/t/… – Peter Paul Kiefer Jan 4 at 11:12
  • I will give it a try and will inform you shortly. – Kushagra Behere Jan 4 at 12:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.