One of the more popular projects i build with kids is my Arduino Morse radio, so i started to wonder whether the nRF24L01 can also transmit sound. That’s how i found the excellent RF24Audio library. This library includes all basic functionality for a walkie talkie, so the sketch is extremely simple, included below.

img_20161111_113900069

I connected the nRF24L01 the usual way, on the SPI pins D11,D12,D13 and 2 extra: D7 and D8. The audio library works on top of the RF24 library, which i also updated to the optimised version from the same source. For maximum reach, i configured the userConfig.h file in the library folder, to the lowest speed RF24_250KBPS and a sample rate of 16kHz which should be fine for speech. I tried higher settings to transfer music, putting my phone’s headphone output on A0 but the quality was rather low; good enough to recognise the song but not pleasant to listen to (noise/distortion).

I include a basic wiring diagram below, showing the 2 LEDs and transmit button:

  • the LED on D6 goes on while a signal is received
  • the LED on the button (A1) goes on while sending
  • the MIC is an amplified electret microphone
  • the speaker is a cheap 8ohm 0.5W speaker

img_20161111_114029798

In this application the nRF24L01 seems to draw more power than usual, so i needed to add a large capacitor on the 3.3V line as decoupling capacitor; anything from 470uF upwards seems to work. (note: when i used an Arduino Nano for another nRF24 project it did not provide enough power at the 3.3V pin so i ended up using a separate 3.3V regulator; other solutions mentioned here).

With this simple setup, we get about 20 meters reach, or less with concrete walls in between. Enough to play with, but for a useful project you probably need an external antenna on the nRF24L01 and/or a better 3.3V supply.

The code is below (same sketch for both sides), including the printf.h file that you have to put inside the sketch’s folder, for the radio.printDetails() function to work (handy diagnostics).


/* Arduino UNO with nRF24L01 module
 * Tom Tobback Nov 2016 - BuffaloLabs
 * 
 * WALKIE TALKIE:
 * -press button on A1 to transmit, LED on, speak into the mic
 * -other LED goes on when receiving
 * 
 * Need large capacitor on 3.3V line
 * 
 * nRF24L01 connected to SPI D10,D11,D12 and D7,D8 
 * button connected on A1 is taken care of by library
 * LED on D6 (receiving) is taken care of by library
 * 
 * RF24 Audio Library TMRh20 2014
This sketch is intended to demonstrate the most basic functionality of the audio library.

Requirements:
2 Arduinos (Uno,Nano,Mega, etc supported)
2 NRF24LO1 Radio Modules
1 or more input devices (microphone, ipod, etc)
1 or more output devices (speaker, amplifier, etc)
1 or more external buttons or switches to control recording/volume/etc.

Setup:
1. Change the CE,CS pins below to match your chosen pins (I use 7,8 on 328 boards, and 48,49 on Mega boards)
2. Connect buttons as desired to the button pins listed below.
2. Upload this sketch to two or more devices
3. Use external buttons to control all devices

Default Pin Selections:
Speaker: pins 9,10 on UNO, Nano, pins 11,12 on Mega 2560
Input/Microphone: Analog pin A0 on all boards

Transmit button: Pin A1
VolumeUp button: Pin A2
VolumeDn button: Pin A3
Remote Transmission: Pin A4

Note: See http://arduino.cc/en/Tutorial/InputPullupSerial for info on how to wire the buttons to the pins
Note: Pin selections can be overridden by modifying the userConfig.h file included with the library
*/


#include <RF24.h>
#include <SPI.h>
#include <RF24Audio.h>
#include "printf.h" // General includes for radio and audio lib

RF24 radio(7,8); // Set radio up using pins 7 (CE) 8 (CS)
RF24Audio rfAudio(radio,1); // Set up the audio using the radio, and set to radio number 0.
 // Setting the radio number is only important if one-to-one communication is desired
 // in a multi-node radio group. See the privateBroadcast() function.

void setup() { 
 Serial.begin(115200); // Enable Arduino serial library
 
 printf_begin(); // Radio library uses printf to output debug info 
 radio.begin(); // Must start the radio here, only if we want to print debug info
 radio.printDetails(); // Print the info
 
 rfAudio.begin(); // Start up the radio and audio libararies

// rfAudio.transmit();
 rfAudio.receive();
 rfAudio.setVolume(7); // max vol
}

void loop() {
 
 // Audio playback and button handling is all managed internally.
 // In this example, the radio is controlled by external buttons, so there is nothing to do here
 
}

/* Documentation and References:

References:
All Library documentation: http://tmrh20.github.io/
New (2014) RF24 Audio Library: https://github.com/TMRh20/RF24Audio
Optimized (2014) RF24 Lib Source Code: https://github.com/TMRh20/RF24 
Optimized (2014) RF24 Network Lib: https://github.com/TMRh20/RF24Network

*/
 

And the printf.h file:

/*
 Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 version 2 as published by the Free Software Foundation.
 */
 
/**
 * @file printf.h
 *
 * Setup necessary to direct stdout to the Arduino Serial library, which
 * enables 'printf'
 */

#ifndef __PRINTF_H__
#define __PRINTF_H__

#ifdef ARDUINO

int serial_putc( char c, FILE * ) 
{
  Serial.write( c );

  return c;
} 

void printf_begin(void)
{
  fdevopen( &serial_putc, 0 );
}

#else
#error This example is only for use on Arduino.
#endif // ARDUINO

#endif // __PRINTF_H__

15 thoughts on “Arduino walkie talkie with nRF24L01

  • 16/11/2016 at 22:13
    Permalink

    first great project, i want to give it a try.
    but quick question do you upload the same sketch to both Arduinos?
    do you know if a pro-mini would also work?

    Reply
    • 18/11/2016 at 07:59
      Permalink

      Hi, yes same sketch goes on both Arduinos. i assume a ProMini will also work, it’s the same atmega328 chip.

      Reply
  • 06/01/2017 at 23:31
    Permalink

    is there any beep noise while talking with this walkie talkie ?
    i have it. a bad beep during talk into my walkie talkie.
    how can i fix it ?

    Reply
    • 07/01/2017 at 09:28
      Permalink

      i don’t remember any beeping sound; are you using an amplified electret microphone similar to mine?

      Reply
  • 14/01/2017 at 18:22
    Permalink

    imy girlfriend has tow arduino uno r3. are these good for this project ?
    i wanna make another walkie talkie for her.

    Reply
  • 14/01/2017 at 18:29
    Permalink

    Sorry. those arduinos are Mega. is it good for ?

    Reply
    • 16/01/2017 at 07:49
      Permalink

      Yes Mega will work too, just need to use other pins for the speaker as mentioned in the top section of the code: pin 11 and 12

      Reply
  • 15/01/2017 at 16:22
    Permalink

    Hi. what about pin number 8 on nRF24L01 ? where should be connect ?

    Reply
    • 16/01/2017 at 07:53
      Permalink

      pin 8 (IRQ) not used for this application

      Reply
  • 18/01/2017 at 00:12
    Permalink

    I have one leonardo and one uno. These are not working together. K
    I think because pins on leonardo are deferent. And i dont know witch one

    Reply
  • 19/04/2017 at 02:23
    Permalink

    Hi
    arduino IDE has an error.

    “””
    Arduino: 1.8.1 (Windows 10), Board: “Arduino/Genuino Uno”

    \\\\Arduino\libraries\RF24Audio-master\RF24Audio.cpp: In function ‘void __vector_11()’:

    \\\\Arduino\libraries\RF24Audio-master\RF24Audio.cpp:460:9: error: ‘class RF24’ has no member named ‘writeFast’

    radi.writeFast(&buffer[a],32);

    ^

    exit status 1
    Error compiling for board Arduino/Genuino Uno.
    “”””
    can you help me about that?

    Reply
    • 20/04/2017 at 11:32
      Permalink

      Hi Amir, i have just tried to compile the code again in IDE 1.8.2 and it works for me. Maybe you have not installed the RF24 library from the same source as the RF24Audio? There are a few different versions of RF24, you need the one from the same author.

      Reply
  • 28/09/2017 at 18:34
    Permalink

    hi to all
    I have a bad noise on speaker
    I work with nano arduino and lm386 amplifire
    I have a 3.7batteri li,polimer
    what I do for this problem??

    Reply
    • 02/10/2017 at 12:04
      Permalink

      have you tried connecting the speaker straight to the 2 Arduino pins as in the example? does this give you the same noise, or is the noise only there with the LM386? the sound output uses the 2 Arduino pins, have you connected them to pin2 and pin3 of the LM386?
      do you connect the LiPo 3.7V to the Nano’s 5V? i don’t think the 3V3 regulator on the Nano is LDO so that might not work well, the 3.7V input might be too low to get a stable 3.3V. better use a separate LDO voltage regulator to get a stable 3.3V and connect this to the Nano’s 5V and also power the nRF from this line (not from the Nano’s 3V3 pin).

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *