We will now write the code that will receive commands from the Android NFC app. The goal of this code will be to switch the relay on or off when the NFC shield receives a given code from the Android device. As the code for this part is quite long, we will split the code into several parts that will be detailed individually.
The code starts by including the required libraries:
#include "SPI.h" #include "PN532_SPI.h" #include "snep.h" #include "NdefMessage.h"
We will also define on which pin the relay is connected:
#define RELAY_PIN 8
After this, we will define the code that should be received from the Android app to switch the relay on or off:
#define RELAY_ON "oWnHV6uXre"
We will also need to create an instance of the NFC chip: ...