Near Field Communication (NFC) technology is increasingly used for everything from access control systems to interactive exhibits. It allows two devices to communicate wirelessly when they’re in close proximity – usually just a tap or a wave away. The ACR122U reader is one of the most popular NFC devices available because of its affordability and ease of setup on desktop systems.
However, if you’re developing interactive experiences, simulations, or games in Unity, you might have wondered how to integrate NFC functionality into your projects. Enter Lando, an open-source C# library that lets Unity detect when an NFC card is present and retrieve its unique ID (UID). This basic functionality is enough for a wide range of use cases:
- Security/Access Control: Let users tap an NFC badge to unlock doors or validate attendance in a VR training scenario.
- Interactive Installations: Create museum exhibits or kiosks where visitors tap physical cards to trigger digital content in Unity.
- Prototyping & Testing: Rapidly build demos that respond to real-world NFC tags without needing a full-blown mobile environment.
Nevertheless, Lando is a Class Library – so you can’t just press ‘Play’ in Visual Studio. You need to compile it into a .dll, then reference it in a Unity project. That’s what this guide is all about. We’ll walk you through:
- Cloning and building the Lando library into a .dll.
- Copying the DLL to Unity’s Plugins folder.
- Using this DLL in your Unity script to detect NFC cards.
In other words, we’re bridging the gap between hardware NFC interactions and virtual Unity experiences, opening up all kinds of possibilities for interactive design.
Let’s get started!
1. Overview of Lando
Lando is an asynchronous client library for ACR contactless card readers, including the ACR122U. It lets you:
- Watch for cards being tapped.
- Receive the UID (unique identifier) when a card is detected.
- Stop watching when done.
The key limitation is that it only provides the card’s UID. If you need to read or write card data (NDEF records, etc.), you’ll need another approach. But for quick ‘present a card → get an ID’ workflows, Lando is perfect.
2. Cloning Lando from GitHub
First, clone or download the Lando repository locally:
Inside, you should see a solution (Lando.sln) or a project that you can open in Visual Studio.
3. Creating the Lando.dll
Step A: Open Lando in Visual Studio
- Download or clone the Lando repository.
- Open the Lando.sln (or .csproj) in Visual Studio.
-
- If there’s no .sln file, create a new Class Library project and add Lando’s source files.
Step B: Add a Console App (Mandatory for Building)
Because Lando is a Class Library (producing a .dll), you cannot simply run it by pressing F5 in Visual Studio. There must be an executable (a Console App or similar) in the same solution that references and builds the library. Here’s how:
- Right-click your Solution in the Solution Explorer → Add > New Project…
- Choose Console App (e.g., ‘.NET Framework’ or ‘.NET Core’).
- Name it something like LandoTestConsoleApp, then click OK.
Your solution will now have two projects:
- Lando (the Class Library)
- LandoTestConsoleApp (the Console Application)
Step C: Reference the Lando Library in the Console App
- In the Solution Explorer, expand your new LandoTestConsoleApp.
- Right-click References (or Dependencies, depending on your .NET version) → Add Reference…
- In the dialog, go to Projects (or Solution).
- Find and check the box for Lando (the Class Library).
- Click OK.
Step D: Use Lando in Your Console App
Open Program.cs in LandoTestConsoleApp and write something like:
using System;
using Lando; // The namespace from the Lando library
namespace LandoTestConsoleApp
{
class Program
{
static void Main(string[] args)
{
// Instantiate the Lando card reader
Cardreader cardReader = new Cardreader();
// Start watching (for example, to see if it throws any errors)
cardReader.StartWatch();
Console.WriteLine("Watching for NFC cards... Press Enter to stop.");
Console.ReadLine();
// Stop and dispose
cardReader.StopWatch();
cardReader.Dispose();
}
}
}
This confirms the Lando library is being built and can be referenced without errors.
Important: Ensure you have the official ACS drivers for the ACR122U installed on your system. Otherwise, the card reader may fail to open or you could see errors like ‘No readers found.’
Step E: Set the Console App as the Startup Project & Build
- In the Solution Explorer, right-click LandoTestConsoleApp.
- Select Set as Startup Project.
- Press F5 (or Debug > Start Debugging).
Visual Studio will:
- Build the Lando Class Library (Lando.dll).
- Build the Console App (LandoTestConsoleApp.exe).
- Run the Console App, allowing you to see console messages or debug Lando code.
Step F: Locating Your Lando.dll
When the build succeeds, you’ll find the Lando.dll in the bin folder of the Lando project (e.g., Lando\bin\Debug or Lando\bin\Release). This DLL is what you’ll copy into Unity.
Tip: You can place breakpoints in the Lando source to debug the library. This is especially useful if you need to verify that card reading logic works correctly before moving into Unity.
Once you have Lando.dll (and the ACR122U drivers installed), you’re ready to integrate it into Unity.
4. Adding Lando.dll to Unity
Now that you have Lando.dll, let’s integrate it into Unity.
- Open your Unity project.
In the Project Window, locate (or create) a folder named Plugins under Assets:
Assets/
├─ Plugins/
└─ Scripts/
- If Plugins doesn’t exist, just create a new folder and name it ‘Plugins’.
- Copy the freshly built Lando.dll into Assets/Plugins.
Unity will automatically detect the DLL, but you may need to tweak some settings if you run into compatibility issues. For example:
- Project Settings > Player > Other Settings → set ‘Api Compatibility Level‘ to ‘.NET 4.x’ if needed (sometimes ‘.NET Standard 2.0’ can cause issues with external DLLs).
5. Writing a Simple NFC Reader Script
Now we’ll write a script that uses Lando to watch for card taps and logs the UID to the console.
- In your Unity project, create a new C# script (e.g., ACR122UReader.cs) in the Assets/Scripts folder.
- Open it in your code editor and add:
using UnityEngine;
using Lando; // <-- The namespace from Lando.dll
public class ACR122UReader : MonoBehaviour
{
private Cardreader cardReader;
// Called when the script is first enabled
private void Start()
{
// Instantiate the Lando card reader
cardReader = new Cardreader();
// Subscribe to the CardConnected event
cardReader.CardConnected += OnCardConnected;
// Subscribe to the CardDisconnected event
cardReader.CardDisconnected += OnCardDisconnected;
// Start watching for NFC cards
cardReader.StartWatch();
Debug.Log("Lando: Started watching for cards");
}
// This method is called every time a card is detected
private void OnCardConnected(object sender, CardreaderEventArgs e)
{
// The e.Card.Id property contains the card UID
string cardId = e.Card.Id;
Debug.Log($"ACR122U: Card connected with UID: {cardId}");
}
// This method is called every time a card is disconnected
private void OnCardDisconnected(object sender, CardreaderEventArgs e)
{
Debug.Log($"ACR122U: Card disconnected");
}
// Called when the script or the GameObject is destroyed or the scene changes
private void OnDestroy()
{
// Stop watching for new cards
cardReader.StopWatch();
// Dispose to free resources
cardReader.Dispose();
Debug.Log("Lando: Stopped watching and disposed reader");
// Unsubscribe from the events
cardReader.CardConnected -= OnCardConnected;
cardReader.CardDisconnected -= OnCardDisconnected;
}
}
- Attach this script to a GameObject in your Unity scene:
-
- For example, create an empty GameObject named ACR122UReader.
- Drag the ACR122UReader.cs script onto it.
- Press Play in Unity. With the ACR122U plugged in (and its official drivers installed), tapping an NFC card (or badge) on the reader should produce a log message in the Console showing the card’s UID.
6. Testing & Troubleshooting
- Driver Check:
Ensure you have the ACS drivers installed for the ACR122U on your system. Without the driver, Lando can’t interface with the device.
You can download the drivers from the official ACS website here.
- API Compatibility:
If you see errors about missing references or .NET compatibility, go to Edit > Project Settings > Player and set Api Compatibility Level to .NET 4.x.
- Platform Support:
Lando.dll is typically for Windows environments. If you need to deploy your Unity project to another platform (macOS, Android, etc.), you’ll need a different approach or a cross-platform library.
- UID Only:
As noted, Lando only gives you the UID of the card. If you want to read or write actual NDEF data, you’ll have to look for a more advanced solution or implement custom APDU commands.
Conclusion
Using Lando with an ACR122U in Unity is straightforward once you have the DLL. Here’s a quick recap:
- Clone and Build the Lando repository in Visual Studio, producing Lando.dll.
- Copy the DLL to Unity’s Assets/Plugins folder.
- Add a C# script that references Lando; and instantiates a Cardreader.
- Call StartWatch() on Start(), and handle the CardConnected event to log UIDs.
- Finally, StopWatch() and Dispose() in OnDestroy().
That’s all it takes to read card UIDs from an ACR122U in Unity. With this foundation in place, you can layer on additional logic—like mapping UIDs to specific behaviours in your game or app.
References
We hope this guide has helped you successfully integrate NFC functionality into your Unity projects using the ACR122U and Lando.dll. If you’re interested in exploring more about our experiences and expertise in e-learning and game development, follow this link here to learn more.
Looking to develop custom interactive solutions for your organisation? At Sliced Bread Animation, we specialise in crafting immersive experiences and innovative content. Contact us today to find out how we can bring your ideas to life!