Radio doorbell on an Arduino Uno
Two Unos, an nRF24L01 radio each and no wire between them: the button on one rings the lamp on the other, and the sender knows it arrived. The whole build, an Arduino Uno and 5 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.
AdvancedRuns in your browser. Free, and no account needed.
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// Radio doorbell, the sending end.
//
// Press the button and this Uno sends a packet over its nRF24L01 to the other
// Uno, which rings. radio.write() waits for the other radio's acknowledgement
// and says whether it came: take the receiving board's program away, or put
// its radio on another channel, and every press prints "no answer".
//
// Both radios have to agree on three things: the channel (76 is RF24's
// default), the data rate, and the address, "00001" here. Change any one of
// them on one side only and the packets go nowhere.
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE on 7, CSN on 8
const byte address[6] = "00001";
const int BUTTON = 2;
int presses = 0;
void setup()
{
Serial.begin(9600);
pinMode(BUTTON, INPUT_PULLUP);
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
Serial.println("Press the button to ring.");
}
void loop()
{
if (digitalRead(BUTTON) == HIGH) {
return;
}
presses++;
char message[32] = "ding dong ";
message[10] = (char)('0' + presses % 10);
bool heard = radio.write(&message, sizeof(message));
Serial.print(message);
Serial.println(heard ? ": delivered" : ": no answer");
// Wait for the button to come back up, so one press is one ring.
while (digitalRead(BUTTON) == LOW) {
delay(10);
}
delay(50);
}
// Radio doorbell, the receiving end.
//
// This Uno listens on the same channel and address as the sender. Each packet
// that arrives is printed and flashes the LED. The radio acknowledges every
// packet on its own, in hardware, before the sketch has even looked at it:
// that acknowledgement is what makes the sender's radio.write() return true.
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE on 7, CSN on 8
const byte address[6] = "00001";
const int LED = 5;
void setup()
{
Serial.begin(9600);
pinMode(LED, OUTPUT);
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_MIN);
radio.startListening();
Serial.println("Listening.");
}
void loop()
{
if (!radio.available()) {
return;
}
char message[32] = "";
radio.read(&message, sizeof(message));
Serial.print("heard: ");
Serial.println(message);
digitalWrite(LED, HIGH);
delay(300);
digitalWrite(LED, LOW);
}
Parts list
8 parts, plus the jumper wires. Every one is in the editor's parts bin.
- 2 × Arduino Uno R3
- 1 × Full-size breadboard
- 2 × 2.4 GHz radio, nRF24L01+
- 1 × Pushbutton
- 1 × Resistor, 220 Ω
- 1 × LED, yellow
How it is wired
18 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.
- Ground: Arduino Uno R3 (1) pin GND; 2.4 GHz radio, nRF24L01+ (1) pin GND
- Arduino Uno R3 (1) pin 13; 2.4 GHz radio, nRF24L01+ (1) pin SCK
- Arduino Uno R3 (1) pin 12; 2.4 GHz radio, nRF24L01+ (1) pin MISO
- Arduino Uno R3 (1) pin 11; 2.4 GHz radio, nRF24L01+ (1) pin MOSI
- Arduino Uno R3 (1) pin 8; 2.4 GHz radio, nRF24L01+ (1) pin CSN
- Arduino Uno R3 (1) pin 7; 2.4 GHz radio, nRF24L01+ (1) pin CE
- Arduino Uno R3 (1) pin 2; Pushbutton pin 1a
- Arduino Uno R3 (1) pin 3V3; 2.4 GHz radio, nRF24L01+ (1) pin VCC
- Ground: Arduino Uno R3 (1) pin GND; Arduino Uno R3 (2) pin GND; LED, yellow pin C
- Arduino Uno R3 (2) pin 13; 2.4 GHz radio, nRF24L01+ (2) pin SCK
- Arduino Uno R3 (2) pin 12; 2.4 GHz radio, nRF24L01+ (2) pin MISO
- Arduino Uno R3 (2) pin 11; 2.4 GHz radio, nRF24L01+ (2) pin MOSI
- Arduino Uno R3 (2) pin 8; 2.4 GHz radio, nRF24L01+ (2) pin CSN
- Arduino Uno R3 (2) pin 7; 2.4 GHz radio, nRF24L01+ (2) pin CE
- Arduino Uno R3 (2) pin 5; Resistor, 220 Ω pin 1
- Arduino Uno R3 (2) pin 3V3; 2.4 GHz radio, nRF24L01+ (2) pin VCC
- Ground: Arduino Uno R3 (2) pin GND; 2.4 GHz radio, nRF24L01+ (2) pin GND
- Resistor, 220 Ω pin 2; LED, yellow pin A
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.