
nRF21540 DK Library for Proteus: Long-Range BLE Simulation

Hello friends, I hope you all are doing great. Today, I am going to share the nRF21540 DK Library for Proteus, so you can run a long-range Bluetooth LE simulation of Nordic Semiconductor's nRF21540 development kit. The kit pairs the popular nRF52840 with the nRF21540, an RF front end that boosts the transmit power up to +20 dBm and amplifies what the antenna receives - a range extender for Bluetooth LE, Thread and Zigbee. With this library the kit runs your Arduino sketch in Proteus 8.5 and talks to a phone over Bluetooth LE.
nRF21540 DK Library for Proteus
Latest version: V1.0 (November 2026, this tutorial)
Helping Tools
- Laptop WiFi Monitor: a laptop on the Wi-Fi of your design: a browser, a TCP / UDP terminal and ping
- Mobile WiFi Monitor: a smartphone that opens the pages of your board and sends it commands
- Serial Monitor Advance: a serial terminal window for the UART of your board
For the demo we built a Bluetooth gate monitor for a farm gate or a yard gate far from the house - exactly where a range extender helps. A micro limit switch on the gate post knows whether the gate is closed, a red lamp shows when it is open, and an armed gate that opens raises an alarm on the phone.
NOTICE: Proteus has no nRF52840 model, so our team has put a lot of effort into building this board ourselves: the pins, the LEDs, the buttons and Bluetooth LE to the phone are all our own model, and your sketch compiles with our free TEP Boards for Proteus add-on. Your feedback is the fuel that keeps us going, so please tell us what you think in the comments below. And if our free libraries help you, you can buy us a coffee. So, let's get started with the nRF21540 DK Library for Proteus:
What is the nRF21540 DK?
The nRF21540 DK (PCA10112) is Nordic Semiconductor's development kit for the nRF21540 front-end module. It is built like the nRF52840 DK - the same SoC, headers, buttons and LEDs - but instead of the PCB antenna the radio goes through the nRF21540 to two SMA antenna connectors. The front end has a power amplifier (PA) for transmitting, a low-noise amplifier (LNA) for receiving and an antenna switch, all controlled by a few GPIOs and an SPI port.
| Part | The real nRF21540 DK | In the library |
|---|---|---|
| SoC | nRF52840: Cortex-M4F, 1 MB flash, 256 KB RAM, BLE, 802.15.4, NFC, USB | your Arduino sketch, ArduinoBLE |
| Front end | nRF21540: PA up to +20 dBm, LNA, two antenna ports | drawn with ANT1 and ANT2 |
| LEDs | LED1 to LED4 on P0.13 to P0.16, active LOW | LED1 to LED4 |
| Buttons | BUTTON1 to BUTTON4 on P0.11, P0.12, P0.24, P0.25 | BUTTON1 to BUTTON4, clickable |
| Headers | Arduino Uno layout | D0 to D13, A0 to A5, SDA, SCL |
Why a Range Extender?
An nRF52840 alone transmits at up to +8 dBm. Every 6 dB more roughly doubles the distance in open air, so the nRF21540's extra transmit power plus its receive gain can multiply the range several times. That turns a link that ends at the garden fence into one that reaches across a farmyard, a warehouse or a sports field - without changing the radio protocol or the phone.
How the Front End Is Controlled
The radio tells the front end what to do: TX_EN switches the PA on while it transmits, RX_EN switches the LNA on while it listens, PDN powers it down between packets, ANT_SEL picks ANT1 or ANT2 and MODE selects one of two gain settings. On the real kit Nordic's SDK drives these pins automatically, so the application code does not change. Our library draws the front end; the simulation has no radio range, so the phone stays connected at any distance.
For the same board without the front end see our nRF52840 DK Library for Proteus. A simulation lets you build the whole application - the sensor, the logic and the phone - before the kit and its antennas are on the desk.
Features of the nRF21540 DK Library for Proteus
- The board as it looks: the blue kit with the nRF52840, the nRF21540 between two SMA connectors, the interface MCU with its USB port, the power switch, RESET, four buttons, four LEDs, NFC and the Arduino headers, drawn compact, with our small TEP signature.
- Your sketch: a .hex for "Nordic nRF21540 DK (TEP Proteus)" with D0 to D13, A0 to A5, LED1 to LED4 and BUTTON1 to BUTTON4.
- Bluetooth LE: ArduinoBLE with services, characteristics, descriptors and notifications; our Mobile WiFi Monitor is the phone.
- The serial monitor: a click on the USB port.
- A complete package: about 4.4 MB with the part, the add-on, the limit switch, the LED, the resistor, the phone and the demo, without the source code of the models.
The nRF21540 DK in Proteus Simulation
Search NRF21540 in Pick Devices; the device NRF21540 DK is in TEPNRF21540DK.LIB (Microprocessor ICs, Bluetooth Boards), with the prefix U. The USB port opens the serial monitor.
The Pins
| Pins | What the library does with them |
|---|---|
| D0, D1 | Serial1 RX and TX, or GPIO (the real P1.01, P1.02) |
| D2 to D9 | GPIO, PWM, interrupt, pulse timing (P1.03 to P1.08, P1.10, P1.11) |
| D10 to D13 | GPIO, PWM; SPI (P1.12 to P1.15 - on the real kit also the front end's SPI) |
| A0 to A5 | analogRead 0 to 1023 for 0 to 3.3 V, or GPIO |
| SDA, SCL | Wire (P0.26, P0.27) |
| LED1 to LED4 | the green LEDs, lit when LOW |
| BUTTON1 to BUTTON4 | the buttons, LOW when pressed |
Download nRF21540 DK Library for Proteus
Click the button below to download nRF21540-DK-Library-for-Proteus-v1.0.zip (about 4.4 MB, without the source code of the models):
nRF21540 DK Library for Proteus V1.0- README.txt: installation, the demo, the pins, the properties, troubleshooting and the limits.
- Proteus Library Files:
TEPNRF21540DK.LIB, the limit switch, the LED and the resistor (TEPLIMIT.LIB,TEPLED5MM.LIB,TEPRESISTOR.LIB) and the phone and laptop. - Proteus Model Files:
TEPNET.DLL,TEPLIMIT.DLL,TEPLED5MM.DLLandTEPRESISTOR.DLL. - Arduino Code: the demo sketch and the TEP Boards for Proteus add-on 1.89.0, with ArduinoBLE.
- Proteus Simulation: the demo project, its HEX file and copies of the DLLs.
No Proteus yet? Read How to Download and Install Proteus 7 and 8. New to libraries? Follow How to Install a New Library in Proteus.
How to Install nRF21540 DK Library for Proteus
- Close Proteus and extract the whole zip file, for example to your Desktop.
- Copy the files from Proteus Library Files into the LIBRARY folder of Proteus.
- Copy the DLLs from Proteus Model Files into the MODELS folder, replacing an older
TEPNET.DLL. - Delete
TEPNRF21540DK.IDXfrom the LIBRARY folder if it is there. - For your own sketches, copy Arduino Code\TEP Boards for Proteus\hardware into your Arduino sketchbook (Documents\Arduino) and restart the Arduino IDE; the board is Nordic nRF21540 DK (TEP Proteus).
- Start Proteus, press P and search for NRF21540.
Demo: a Long-Range Bluetooth Gate Monitor in Simulation
A gate at the end of a long drive or at the edge of a field is easy to forget. Was it closed after the delivery? Did somebody open it at night? A small sensor on the gate post and a phone in the house answer both questions - if the radio reaches that far, which is the job of the nRF21540.
Open nRF21540-DK-BLE-Gate-Monitor.pdsprj. U1 runs DK21540_BLE_Gate_Monitor.hex; SW1 is the KW11 micro switch from our Micro Limit Switch Library for Proteus on the gate post - C to ground, NO on D2, so the closed gate pressing the lever reads LOW; D1 is a red LED from our 5mm LED Library for Proteus, the OPEN lamp, through R1 (220 ohm) on D3; MOB1 is the phone.
| What | Meaning |
|---|---|
| LED1 | the gate is closed |
| LED2 | armed |
| LED3 | a phone is connected |
| LED4 | ALARM |
| the red lamp | lit while the gate is open, flashing in an alarm |
| BUTTON1 | arm (only with the gate closed) / disarm |
| BUTTON2 | the alarm off |
The Bluetooth Service
Three characteristics carry the gate's state, the number of openings and whether the monitor is armed, each with a readable 0x2901 name for the phone:
BLEService gateService("19B100A0-E8F2-537E-4F6C-D104768A1214");
BLEStringCharacteristic stateChar("19B100A1-E8F2-537E-4F6C-D104768A1214", BLERead | BLENotify, 12);
BLEIntCharacteristic openingsChar("19B100A2-E8F2-537E-4F6C-D104768A1214", BLERead | BLENotify);
BLEByteCharacteristic armedChar("19B100A3-E8F2-537E-4F6C-D104768A1214", BLERead | BLENotify);
BLEDescriptor stateLabel("2901", "Gate");
BLEDescriptor openingsLabel("2901", "Openings");
BLEDescriptor armedLabel("2901", "Armed");
Reading a Bouncing Switch
A real micro switch bounces for a few milliseconds when its contacts close or open - and our limit switch model bounces too. readGate() accepts a new level only after it has stayed the same for 30 ms:
void readGate() { // the switch bounces: a new level counts after 30 ms without a change
const bool raw = digitalRead(GATE);
if (raw != lastRaw) { lastRaw = raw; rawSince = millis(); }
if (raw != level && millis() - rawSince >= DEBOUNCE_MS) {
level = raw;
gateChanged(level == LOW); // LOW = the lever is pressed = the gate is closed
}
}
Open, Closed and the Alarm
gateChanged() lights LED1 for a closed gate, counts every opening, and raises the alarm when an armed gate opens. Every change goes to the phone:
void gateChanged(bool nowClosed) {
closed = nowClosed;
led(0, closed);
if (closed) {
Serial.print(F(">> GATE CLOSED (open ")); Serial.print((millis() - openedAt) / 1000.0, 1); Serial.println(F(" s)"));
warned = false;
} else {
openedAt = millis();
openings++;
openingsChar.writeValue(openings);
Serial.print(F(">> GATE OPEN (opening ")); Serial.print(openings); Serial.println(F(")"));
if (armed) { alarm = true; led(3, true); Serial.println(F(">> ALARM: the gate opened while armed")); }
}
stateChar.writeValue(state());
}
The Buttons
BUTTON1 arms the monitor - but only with the gate closed, otherwise it would alarm at once - and disarms it again. BUTTON2 switches the alarm off and stays armed:
void handleButtons() {
for (byte k = 0; k < 2; k++) {
const bool now = digitalRead(BUTTONS[k]);
if (now == lastButton[k]) continue;
lastButton[k] = now;
if (now != LOW) continue; // act on the press
if (k == 0) { // BUTTON1: arm / disarm
if (!armed && !closed) { Serial.println(F(">> BUTTON1: close the gate first")); continue; }
armed = !armed;
led(1, armed);
armedChar.writeValue(armed ? 1 : 0);
if (!armed && alarm) { alarm = false; led(3, false); stateChar.writeValue(state()); }
Serial.println(armed ? F(">> ARMED") : F(">> DISARMED"));
} else if (alarm) { // BUTTON2: the alarm off (still armed)
alarm = false;
led(3, false);
stateChar.writeValue(state());
Serial.println(F(">> BUTTON2: the alarm is off"));
}
}
}
The Lamp
The red lamp is lit while the gate is open and flashes four times a second in an alarm, without stopping the loop:
void lamp() { // lit while open, flashing in an alarm
if (alarm) {
if (millis() >= nextBlink) { nextBlink = millis() + BLINK_MS; blinkOn = !blinkOn; digitalWrite(LAMP, blinkOn ? HIGH : LOW); }
} else digitalWrite(LAMP, closed ? LOW : HIGH);
}
Run the Simulation
Press Run. The serial monitor - the same window as our TEP Serial Monitor Advance for Proteus - shows the name the kit advertises. The switch starts released, so the gate is open and the lamp is lit:
nRF21540 DK Long-Range Bluetooth Gate Monitor - The Engineering Projects
Advertising as "nRF21540 Gate" BUTTON1 = arm / disarm, BUTTON2 = alarm off
Gate: OPEN
Connect the Phone
On the phone open the Bluetooth app, press SCAN and connect to "nRF21540 Gate" - LED3 lights. Nobody has closed the gate, so after 10 s the monitor reports it as left open:
Close the Gate
In the switch's window click Hold down - the gate presses the lever: GATE CLOSED, LED1, the lamp off:
Arm, and the Gate Opens
Click BUTTON1: ARMED, LED2. Now click Release in the switch's window - the gate opens: ALARM, LED4 and the lamp flashing. Here is the complete circuit while the simulation runs:
The Alarm Off
Hold the lever down again, then BUTTON2 switches the alarm off - the monitor stays armed - and BUTTON1 disarms it:
Phone connected
>> LEFT OPEN for 10 s
>> GATE CLOSED (open 13.4 s)
>> ARMED
>> GATE OPEN (opening 1)
>> ALARM: the gate opened while armed
>> GATE CLOSED (open 5.1 s)
>> BUTTON2: the alarm is off
>> DISARMED
Why NO and Not NC?
A micro switch has three tabs: C (common), NC (normally closed) and NO (normally open). With C to ground and NO on an input with a pull-up, the input reads LOW only while the lever is pressed - the gate is closed. For a security switch many installers use NC instead, so a cut wire looks like an open gate and raises the alarm; the sketch then reads the opposite level. Both work with the same code if you swap LOW and HIGH in readGate().
Mounting a Gate Switch
Outdoors the switch goes in a small weatherproof box on the post, with the roller lever where the closed gate pushes it about halfway down. The roller lets the gate slide past without bending the lever. A sealed reed switch and a magnet on the gate are the other common choice: no moving parts, but they need careful alignment.
Antennas and Range
With a range extender the antenna matters as much as the power. A small external antenna on one of the SMA connectors, mounted high and clear of metal, does far better than one inside a metal box. The front end's two antenna ports let a product choose between, for example, an antenna on the case and one on a cable. Local radio rules limit the transmit power, which is why the nRF21540's gain can be set.
Battery Life
A power amplifier at +20 dBm draws far more current than the radio alone, so a battery gate sensor keeps the front end powered down (PDN) between packets and sends as rarely as possible: a change of the gate, and a short heartbeat every few minutes. The nRF52840 sleeps in between, woken by the switch on an interrupt.
The Link Budget in Plain Words
Radio engineers talk about the link budget: the transmit power minus the weakest signal the receiver can still understand, both in dBm. Everything between the two antennas - distance, walls, trees, the human body - eats into that budget. A front end improves both ends of the sum: more power going out, and an amplifier that lifts weak signals coming in before the radio hears them. Bluetooth LE also has a long-range coded mode that trades speed for a few more dB, and the two together are how gate sensors and farm tags reach far beyond the usual few tens of metres.
Left Open, but Only Once
A gate left open after a delivery is not an emergency, but it is worth knowing. The sketch reports LEFT OPEN once, 10 s after the gate opened while the monitor is disarmed, and resets the warning when the gate closes again. An armed monitor skips this message because the ALARM has already said much more. Reporting a state change once, instead of repeating it, keeps the phone quiet and saves battery on a real sensor.
What the Phone Sees
The phone reads three characteristics: the gate's state as text, the number of openings and the armed flag. All three notify, so the phone shows ALARM the moment the gate opens, without asking. The 0x2901 descriptors give each value a readable name in any Bluetooth LE app.
Try It Yourself
- Send a heartbeat to the phone every minute so it knows the monitor is still there.
- Arm the monitor automatically at night and disarm it in the morning.
- Add a buzzer that sounds with the alarm.
- Add a writable characteristic so the phone can arm and disarm.
Ideas to Extend the Monitor
- Watch two gates with two switches on D4 and D5.
- Count how long the gate was open today.
- Use the NC contact so a cut wire also raises the alarm.
- Show the gate on a small OLED display in the house.
Your Own Sketches
Write the sketch in the Arduino IDE with the board Nordic nRF21540 DK (TEP Proteus), use Sketch > Export Compiled Binary and set the part's PROGRAM property to the .hex.
Moving to a Real nRF21540 DK
- Install Nordic's nRF Connect SDK with the board nrf21540dk/nrf52840; its front-end module support drives the nRF21540.
- Fit an antenna to ANT1 (or ANT2) - never transmit without an antenna on the selected port.
- Start from Nordic's Bluetooth peripheral samples and Zephyr's GPIO API.
- Wire the limit switch: C to GND, NO to a free GPIO with the internal pull-up; the lamp through 220 ohm.
- Move the logic of the demo across: the debounce, the arming, the alarm and the service.
The pins, the logic and the Bluetooth service stay the same; on the real kit Nordic's SDK takes the place of the Arduino calls.
Things to Know Before Using a Real nRF21540 DK
- The front end's SPI: on the real kit D11 to D13 are also the nRF21540's SPI - keep other SPI parts off them.
- Radio rules: +20 dBm is not allowed everywhere; set the gain for your country.
- Antennas: the SMA ports need an antenna for 2.4 GHz.
- 3.3 V: the I/O runs at 3.3 V; a 5 V module needs a level shifter.
Properties of the nRF21540 DK
| Property | What it does |
|---|---|
| PROGRAM | the sketch: a .hex from TEP Boards for Proteus (board "Nordic nRF21540 DK") |
| MONITOR, BAUD, AUTOOPEN | the built-in serial monitor: on, its baud rate (115200), open at Run |
Troubleshooting
- The phone's list is empty: call
BLE.begin(), set a local name andBLE.advertise(); callBLE.poll()in the loop. - One click counts twice: the lever bounces - accept a new level only after 30 ms without a change.
- BUTTON1 does not arm: close the gate first.
- The LEDs look inverted: they light when the pin is LOW, as on the real kit.
- A number goes wrong above 32767: int is 16 bits in the simulation - use long.
Limitations of the Simulation
- The nRF21540 front end and the SMA connectors are drawn, not modelled; the simulation has no radio range.
- One phone is the central; the board cannot be a central itself. 802.15.4, NFC and USB device classes are not modelled.
- Your sketch gets 8 KB of RAM in the simulation, and int is 16 bits there.
- nRF21540, nRF52840 and Nordic Semiconductor are names of Nordic Semiconductor ASA and Arduino of Arduino; this library is not made or endorsed by them or by Labcenter.
- Tested in Proteus 8.5 in November 2026 (the demo as shipped, about 28 s of simulation). Proteus 7 is not supported.
So, that was all about the nRF21540 DK Library for Proteus. I hope it helps you try your long-range Bluetooth ideas in a simulation before the kit and its antennas are on your desk - the switch, the logic and the phone, all on one sheet. If you have any questions, ask in the comments and I will help you out. Till the next tutorial, take care and have fun!






















Comments
0