Problem with serial read

Hello world !

I have a problem with atmega328P in my code the LED don’t work when i write in RX atmega328p

/*
 * ----------------------------------------------------------------------------
 * This is a MFRC522 library example; see https://github.com/miguelbalboa/rfid
 * for further details and other examples.
 * Typical pin layout used:
 * -----------------------------------------------------------------------------------------
 *             MFRC522      Arduino       Arduino   Arduino    Arduino          Arduino
 *             Reader/PCD   Uno           Mega      Nano v3    Leonardo/Micro   Pro Micro
 * Signal      Pin          Pin           Pin       Pin        Pin              Pin
 * -----------------------------------------------------------------------------------------
 * RST/Reset   RST          9             5         D9         RESET/ICSP-5     RST
 * SPI SS      SDA(SS)      10            53        D10        10               10
 * SPI MOSI    MOSI         11 / ICSP-4   51        D11        ICSP-4           16
 * SPI MISO    MISO         12 / ICSP-1   50        D12        ICSP-1           14
 * SPI SCK     SCK          13 / ICSP-3   52        D13        ICSP-3           15
 */

#include <SoftwareSerial.h>
#include <SPI.h>
#include <MFRC522.h>
#include <Arduino.h>

#define RST_PIN		9		// 
#define SS_PIN		10		//

const int wake = A3;

const int led = 2;

MFRC522 mfrc522(SS_PIN, RST_PIN);	// Create MFRC522 instane

byte readCard[7];

void setup() {

  pinMode(wake, OUTPUT);
  digitalWrite(wake, LOW);
  
  pinMode(led, OUTPUT);
 
  Serial.begin(9600);		// Initialize serial communications with the PC
  while (!Serial);		// Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
  SPI.begin();			// Init SPI bus
  mfrc522.PCD_Init();		// Init MFRC522
  // ShowReaderDetails();	// Show details of PCD - MFRC522 Card Reader details
  // Serial.println(F("Scan PICC to see UID, type, and data blocks..."));
  // btSerial.begin(9600);
  mfrc522.PCD_SetAntennaGain(mfrc522.RxGain_max);
  
  delay(2000);
  digitalWrite(wake, HIGH);
  digitalWrite(led, HIGH);
  delay(2000);
  digitalWrite(wake, LOW);
  digitalWrite(led, LOW);
}

void loop() {
 
  if ( ! mfrc522.PICC_IsNewCardPresent()) { //If a new PICC placed to RFID reader continue
    return;
  }

  if ( ! mfrc522.PICC_ReadCardSerial()) {   //Since a PICC placed get Serial and continue
    return;
  }

  for (int i = 0; i < 4; i++) {  //
    readCard[i] = mfrc522.uid.uidByte[i];
    Serial.print(readCard[i], HEX);
    digitalWrite(led, LOW);
  }

  Serial.println("");
  mfrc522.PICC_HaltA();
  return;
 
  if (Serial.available())
  {
    digitalWrite(led, HIGH);
    
  }
  
}

Do you have a idea ?

THX

bigfoot69100:
Hello world !

I have a problem with atmega328P in my code the LED don’t work when i write in RX atmega328p

void loop() {

if ( ! mfrc522.PICC_IsNewCardPresent()) { //If a new PICC placed to RFID reader continue
   return;
 }

if ( ! mfrc522.PICC_ReadCardSerial()) {   //Since a PICC placed get Serial and continue
   return;
 }

for (int i = 0; i < 4; i++) {  //
   readCard[i] = mfrc522.uid.uidByte[i];
   Serial.print(readCard[i], HEX);
   digitalWrite(led, LOW);
 }

Serial.println("");
 mfrc522.PICC_HaltA();
 return;

if (Serial.available())
 {
   digitalWrite(led, HIGH);
   
 }
 
}




Do you have a idea ?

THX

Your code will never reach the digitalWrite(led,HIGH);
Remove the return after the:
mfrc522.PICC_HaltA();

The way your loop() is structured, The Serial.Available will only be check when the following compound if clause is true, and the processor is faulty, (skips the return statement).

if (mfrc522.PICC_IsNewCardPresent()) { //If a new PICC placed to RFID reader continue
  if ( mfrc522.PICC_ReadCardSerial()) {   //Since a PICC placed get Serial and continue
     return;
// can never reach here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     if (Serial.available()){
        }
     }
   }

Chuck.