iRidi NFC
NFC (Near Field Communication) is a short-range wireless data transfer technology that lets devices exchange data at distances of up to 10 centimeters.
Required:
iRidi Pro
NFC works by reading data from a tag programmed beforehand. NFC tags can automatically send any commands to a device. For example, a portable NFC tag can contain an access code for a hotel room or for registering in a system. In public places, tags can be used to pay for services; at home, they can trigger a device or an entire scenario.
- The driver reads and sends values in NDEF format with encryption.
download example: *NFC *NFC child control
Application examples
- Restricting control of electrical appliances. If you have a child and want to limit access to certain appliances, you can easily configure rules. When the child enters the house and checks in with a tag, kitchen appliances and several outlets are blocked.
- An NFC tag can record a person's check-in at a specific location in a shopping mall or on a floor of a sports complex. You can track visits and turn on lighting in specific parts of the floor,
- Tracking parking capacity. Create a token whose value increases by one with each new tag. When it reaches a specified value, a signal is sent to the display. When a car leaves, the token value decreases and a scenario permits entry to the parking lot
Operation on iOS and Android
1. iOS NFC
After activating the NFC scanner in an iRidi project, the standard iOS NFC interface opens. The user then reads a tag, the data is passed to the project, and iRidi continues operating. The device's NFC scanner turns off.
2. Android NFC
In the Android version of the application, enable NFC in Android's system settings. This platform does not allow iRidi to turn the NFC scanner on or off. Once NFC is enabled on Android, the scanner runs continuously until it is turned off in the device's system settings.
Writing to an NFC tag
You can write to a tag using applications available on Google Play or the App Store. Some options are listed below:
- NFC TagWriter by NXP
- Trigger (NFC Task Launcher)
- NFC Tools
- NFC Tag writer
After writing to a tag, check the recorded data: applications may add extra characters. To trim them, store the tag's value in a variable and remove the unwanted characters.
Remove 3 characters from the beginning of the value.
var number = value.slice(3);
Remove 3 characters from the end of the value.
var number = value.slice(-3);
Working in iRidi
- In iRidi Studio, create a Panel Project and draw a button that will activate the NFC scanner.

- Create an item to display the received data:

- Open the script editor and create a script for the NFC driver (the full script is provided at the end of the description).
After the script creates the driver, it has 1 command channel (Commands), "NFCDefaultChannel", and 2 feedback tags (Feedbacks), "NFCDefaultTag" and "NFCSimpleTag". For complete driver information, see Driver properties
Creating the NFC driver
IR.CreateDevice(IR.DEVICE_NFC_DEVICE,"NFC") //создаем драйвер NFC
Activating the NFC scanner on a press
IR.AddListener(IR.EVENT_ITEM_PRESS, IR.GetItem("Page 1").GetItem("Item 2"), function ()
{
IR.GetDevice("NFC").Set("NFCDefaultChannel", 1); // активация сканера NFC по нажатию на кнопку
});
- Create a listener to receive data from the driver's tags.
IR.AddListener(IR.EVENT_TAG_CHANGE, IR.GetDevice("NFC"), function(name, value)
// подключаем слушатель на изменение тегов в драйвере
{
// полную информацию выводим на Item 1:
if(name == "NFCDefaultTag")
IR.GetItem("Page 1").GetItem("Item 1").Text = value;
//основную информацию выводим на Item 4:
else
IR.GetItem("Page 1").GetItem("Item 4").Text = value;
});
The driver is now ready to use!
Full script
IR.AddListener(IR.EVENT_START,0,function()
{
IR.CreateDevice(IR.DEVICE_NFC_DEVICE,"NFC") //создаем драйвер NFC
IR.GetItem("Page 1").GetItem("Item 1").Text = driver;
IR.AddListener(IR.EVENT_ITEM_PRESS, IR.GetItem("Page 1").GetItem("Item 2"), function ()//активация сканера NFC по нажатию на кнопку
{
IR.GetDevice("NFC").Set("NFCDefaultChannel", 1); //Отправляем значение 1 для включения
});
IR.AddListener(IR.EVENT_TAG_CHANGE, IR.GetDevice("NFC"), function(name, value) //подключаем слушатель на изменение тегов в драйвере
{
if(name == "NFCDefaultTag")
IR.GetItem("Page 1").GetItem("Item 1").Text = value; //полную информацию выводим на Item 1
else
IR.GetItem("Page 1").GetItem("Item 4").Text = value; //основную информацию выводим на Item 4
});
});
Driver properties
Commands
Send a command to read a tag.
Syntax:
IR.GetDevice(driver).Set(type, value)
| Input | Value | Description |
|---|---|---|
| driver | "NFC" | type: String - driver name |
| type | "NFCDefaultChannel" | type: String - channel name |
| value | 1 | type: Value Value to send: 1 - activate the scanner, 0 - deactivate the scanner |
Feedbacks
Receive values from an NFC tag.
Syntax:
IR.GetDevice(driver).GetFeedback(name)
| Input | Value | Description |
|---|---|---|
| driver | "NFC" | type: String - driver name |
| name | "NFCDefaultTag", "NFCSimpleTag" | type: String Received value format: Full information Basic information |
| Data (NFCDefaultTag) | {“ID”:”0”,”Type”:””, “Payload”:”12345”} | type: String Full data |
| Data (NFCSimpleTag) | 12345 | type: String Basic data |