# Save and Restore Preset Values With NFC (TfCD)

47

1

Published

## Introduction: Save and Restore Preset Values With NFC (TfCD)

We want to test how it works to adjust a certain value or setting and later recall this setting. For this experiment we used a NFC tag to read and then save the value on it. Later the tag can be scanned again and send the value back to restore a certain setting. To simulate the interaction we used an Arduino Uno as controller and a RGB LED ring as adjustable part. With an potentiometer the RGB hue can be set. The communication between the Arduino and the NFC tag was set up with an NFC shield.

(This project was an exercise for the TU Delft, Integrated Product Design, course: TfCD)

## Step 1: Collect Material

We used for this project the following material:

- Arduino uno
- NFC shield & tag (https://www.elecrow.com/wiki/index.php?title=NFC_Shield)
- Mokugi t-WS2812B-8LED
- Potentiometer (10 3B 42 5V)
- Switch
- 10K Ohm resistor

## Step 2: Use Potentiometer to Adjust RGB LED

First make sure that the LED you are working with functions, by running another test code.

Then you can connect the potentiometer to adjust the RGB of the LED. For this build the circuit as shown in the picture. Connect to power (5V) and ground, and connect the potentiometer to pin A0.

If you want to scale up the model and later save several different values you can already use more potentiometers at this step.

The code for this test is also attached. To get the code working you need to download the Adafruit_NeoPixel.h library.

We mix the hue of the RGB LED as follows: We chose to continuously have red on and adjust it towards purple by mixing blue in. If the potentiometer is high, blue is completely on, when it is low, blue is off.
For this we map the reading of the potmeter:

val = map(val, 0, 1023, 0, 255);

In order to avoid drift of the input value of the potentiometer, we only change the new value of the blue LED, when the difference between the current and the previous potvalue is high enough:

int diff = abs(val-oldVal);

if (diff > TOLERANCE) {
ChangeLED();

## Step 3: Integrate NFC

The next step is to integrate the NFC. First connect the NFC shield to the Arduino.

Also add the switch as shown in the photos. The switch is used to change between reading and writing to the NFC tag.

Download the library PN532.h for the NFC shield. The attached code is an adaptation of the example codes provided within the library. It is changed in that way that the RGB value of the LED is transferred.

You also can first test only the reading or the writing with the two codes which are attached separately.

Explanation final code

First all the used variables are initialised.

Then in the void setup the nfc connection is setup.

The void loop starts with reading the state of the switch.

Case 0 is when the button state is HIGH. In this case first the function Reading() is called. This reads the RGB value saved in block 8 of the NFC tag on the first place of the array (Blue = block[0];). Then the function ChangeLEDRead() is called, which changes the hue of the LED to the value, which was just read from the NFC tag.

Case 1 is when the button state is LOW. In this case first the function ReadPot() is called, which means that you now can manually can adjust the hue of the LEDs with the potentiometer. This input from the potmeter is then mapped to a value between 0 and 255. The function ChangeLEDPot() then controls the LED colour using the input from the potmeter. In this case also the function Writing() is called. This makes sure that as soon as an NFC tag is placed close to the shield the current value of blue will be written on it in the first place of block 8.

The same principle could be also used in other cases and is not only limited to NFC.
There are many possible implementations, where you want to adjust certain values to your preference, save them and restore your personal settings then at a later moment again.

Think for example about a shared working place, where you adjust the height of your chair, backrest angle and the height of the table to your personal preference. You save your preference by quickly scanning with an NFC tag. When you come back another day you scan your tag again, and the workplace changes to your settings.

Instead of an NFC chip, you can also use your smartphone. A special application or website can be used as interface.

Another implementation could be for example to scan a fingerprint instead of scanning the NFC tag. The fingerprint can be then linked to a certain user profile where preferences are saved.

## Recommendations

• ### Arduino Class

69,044 Enrolled

• ### Make it Move Contest

We have a be nice policy.