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.
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
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__
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?
Hi, yes same sketch goes on both Arduinos. i assume a ProMini will also work, it’s the same atmega328 chip.
can we connect 8 to 10 walkie talkie to gether for sqaud conversation ?
plz rply
hi, yes if you don’t set the channel you will have broadcast so anybody can hear. however, as i mentioned in the post, the reach of these standard radio modules is quite poor for this application, about 10-20 meters or so, so you will probably have to improve that if you want it to be useful. i’m not sure what you can get with 2.4GHz, it would make more sense to use a lower frequency module.
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 ?
i don’t remember any beeping sound; are you using an amplified electret microphone similar to mine?
Oh thats it. my bad.
imy girlfriend has tow arduino uno r3. are these good for this project ?
i wanna make another walkie talkie for her.
Sorry. those arduinos are Mega. is it good for ?
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
Hi. what about pin number 8 on nRF24L01 ? where should be connect ?
pin 8 (IRQ) not used for this application
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
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?
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.
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??
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).
Friend you did it with arduino one and in what version of arduino you did it
Arduino IDE 1.8.x
You did a nice project and i suggest you to replace your hand made sketch with a Fritzing diagram. You can find it here and its free http://fritzing.org/home/.
Hi Amit, i’m familiar with Fritzing and use it sometimes. however, i use this kind of sketches for my kids’ classes, printed on paper. Fritzing looks good on a screen, but is less ideal for printing, and i prefer the simple level of abstraction of my ‘maps’.
Can you communicate more than two Arduinos?
Hi Luis, if i recall correctly, i’m using the broadcast mode, not channel to channel, so the broadcast is received by all systems within reach.
hi, the communication is bidirectional?
yes both sides run same code and can send/receive
Pingback:Walkie talkie Arduino - Сайт для радиолюбителей
Hello,we did the same things what you wrote, the circuit works but after some time(10s-2 min) we need to reset the arduinos in order to rework it. Did it happen to you? What do you think?Why did it happen? Thank you.
Hi, Uchi, not sure why your Arduinos get stuck, my guess would be the power supply to the radio modules as mentioned in my post. so i’d suggest to use a proper 3.3V regulator to power the radio and see if that solves your issue. it may be interesting to add a diagnostic LED to the project to indicate the radio status, i’ll have a look at that.
I have added an LED on D3 for the status, and changed the loop to this:
wdt_reset();
delay(800);
if (radio.getPALevel() < 3) { Serial.println("radio error"); digitalWrite(3, HIGH); } else { digitalWrite(3, LOW); } It seems the radio fails from time to time, but then i restores itself. I'm not sure it really fails, maybe just the status command fails. But it definitely fails if the wiring is not correct. I have also added a watchdog timer with wdt_enable(WDTO_1S); in the setup. It triggers occasionally, sometimes not for 10min. I added at the end of setup: radio.setPALevel(RF24_PA_MAX); // rfAudio.begin seems to put this to PA_MIN I tested the range with a proper 3.3V voltage regulator but that did not make a difference. So the only way to get a better range i think is using a module with external antenna.
I Rebuild this whole Circuit ans put it in 2 Boxes. Now im Facing the issue that Theres only Noise/distortion both LEDs react äß expected ans im also getting Sound when i blow at the mic just no Real speach
Hi Stan, are you using an amplified mic pcb as in my pictures? if your using a non-amplified mic, the signal is too weak. maybe your amplifier is too strong, in that case you could put a voltage divider on its output, or a pot (GND, A0, mic output).
Dear Tom!
Thank you for your article.
I would like to ask: how could it be modified to be “full-duplex”? So i mean to be two-way communication simultanously? So talking to each other WITHOUT need to press any button, just use it like a phone call?
Thank you for your answer,
Ati
Hi Ati, i don’t think full-duplex is possible but you could check with the library author at https://github.com/nRF24/RF24Audio
Should i make the same connections and upload the same code to both the arduinos?
Will it transmit and receive the sound?
yes same code on both arduinos. press the button while speaking to transmit
Hi Tom!
I’m using this mic:
https://www.ebay.co.uk/itm/Sound-Detection-Sensor-Module-Electret-Condenser-Microphone-Arduino-PIC-Pi-LM393-/273149595283
and i cant seem to get it working..
is this the reason why?
hi, it seems that that module is a ‘sound detection sensor’ so the output is just digital yes/no, compared to a level you can set with the trimpot. it looks like the other A0 output is not amplified so that signal will not be strong enough
could you please update the link (or attach a new one) to the microphone? the one thats here isnt available anymore.
one more question,
after using the nrf for a few minutes, it stops working. i am using an arduino uno, and have checked that the output voltage is 3.3v
i dont know what else to check for problems.. any idea?
thanks a lot!
Hi, here is a current link to the same shop https://detail.tmall.com/item.htm?spm=a312a.7700718.1998025129.5.7e82ae53ZUNwRv&abtest=_AB-LR32-PR32&pvid=79e0f99c-6e1a-47eb-b75e-01f29e78173d&pos=5&abbucket=_AB-M32_B5&acm=03054.1003.1.2431317&id=42556688044&scm=1007.12144.93797.23864_0
do you have a large cap on your 3V3/GND power lines? if you look into the RF24 library you will probably find a way to check the status of the radio, and when it’s not responding, you could try re-starting it
I am putting on a walkie talkie workshop at school. We will build this project. There will be several pairs of walkie talkies functioning at the same time. How do I address or set channels? I want each group to be able to have private communication without interference from the other group’s walkie talkies. I tried radio.setChannel(108); in the void setup() section. Loaded this code to both walkie talkies. This did not work for me. Any thoughts?
thanks much
Re: Full Duplex – the simplest way is by imitation.
If you use a paired MCU+radio module for each half of the ‘Plex (1 pair for Rx, 1 pair for Tx), you can effectively mirror an AVR equiv to the old Pye PF1 – but by having isolated radio and audio chains, and split-frequency operation, you could set up group ops easily.
Have Rx listening for broadcast, Tx on a lower freq or reverse if preferred.
Repeator Mode – Then, with a bit of thought and elaboration, you could use a central repeater and all operators on portable/mobile sets. I’ll leave you to research that, but it’s neither complex or hard (that said, I’ve been involved in radio comma for half my life, so my perception of easy is relative – compared to my youth days era tech means, super easy).
Super Advanced – with some work, you could develop a proper packet transmission based digipeater based networked repeater op.
But regardless of how you go – your two immediate elaborations should be using either higher ERP radio modules, preferably not using PCB etched antennas, or (using low ERP or higher ERP modules), use efficient antennas – remember that your onboard etched antennas are negative gain – you’re aiming for unity gain or positive gain on the antenna front. With a little effort, you could build coax co-linears for good positive gain and still be omnidirectional or helically wound collinear at reduced positive gain efficiency.
Remember, particularly on the Rx side, stronger (within Rx tolerance) signals directly received via efficient means beats compensating for poor passive gain via Rx preamps.
Note – if you dig deep, you can find digital telephony/voice configured modules for ISM or permit-free allocations that all you need add is the smart bit (I.e. MCU for control and data modes, driving displays etc).
Hi tom.
I made the circuit. When i press the button i get some feedback on the other speaker. This means that my circuits are working. But it’s not transmitting and sound from microphone. I checked with two different microphone.
Secondly after few seconds arduino stops working and i need to restart it.
hi, the microphone is an amplified electret mic; it won’t work without the amplifier as the output would be to low.
if your system gets stuck, my guess is that the 3.3V power supply is not sufficient; are you using a large capacitor on 3V3/GND?
also, there are a lot of fake nRF24L01 modules around of varying quality
Dear Tom,
I would like to thank you for this article, I have a couple of questions I am thinking to do a similar project but instead of using nRF24L01 I am planning to use Arduino Ethernet Shield V1,
so I want to record my voice in my Arduino and send it to another Arduino (in the same Room), then hear it
do you think it’s possible to do it with the Ethernet Shield ?
thx.
Hi, that is a totally different project. i have not tried that but other people have, look e.g. at https://electronics.stackexchange.com/questions/48596/sending-audio-over-ethernet
https://www.instructables.com/id/Ethernet-Voice-Streaming/
Which pins is the speaker connected to??
it says on the drawing and in the code, D9 and D10
Sir please can you give me all connections properly to connect present I’m working on this project I should complete this project soon so please can you give me connections with neat circuit diagram
hi, i think the wiring diagram representing the breadboard in the picture should be clear; i build this project with 7-8 year olds and they can figure it out. just make sure you have an amplified mic board.
I tried this code on ATMEGA238P(Arduino Uno) but its not working. same code uploaded on both boards.
if your arduino really says ATMEGA238P then i would not expect much to work
Hi Tom,
I am able to get the two RF24L01s communicated with each other by using two UNO boards with exactly the same sketch and circuit from this web page. However, the noise (or interference I am not sure) generated by the module itself makes this pair of walkie talkie almost unusable even though they are only 5 feet apart. I tried to move all the components inside a confined space but the situation remained the same. Is there anything I can do to reduce that unwanted noise? Thanks a lot.
Sam
hi, i regularly make this project with groups of kids i teach, and while it is definitely not useful as a real walkietalkie (quality, range), it does work well enough to illustrate voice over radio waves. a good indicator to see whether it works is pressing the send button on unit 1, then the receive LED should light up on unit 2. if that does not work, the radio(s) are not working. if that works, maybe the noise comes from the microphone; maybe its gain is too high. if you have access to an oscilloscope, have a look at the mic output to check if it is relatively clean. or maybe to test you can connect A0 to GND instead of the mic, to see if you still get the noise.
Hi Tom,
Actually, the LED (instead of ON perminantly) blinked on unit 2 according to the audio level while the button on unit 1 was being pressed. I was pretty sure the transmission was working properly. In fact, I could still hear 10% of the voice from unit 1 amongst 90% of background noise. The same problem occured when unit 1 acted as an receiver.
By grounding A0 on the transmitter side as you had suggested, there was a complete silence on the receiver side. I don’t have an oscilloscope and frankly speaking, I don’t understand how it works. Could you tell me what I should do next?
Regards,
Sam
what microphone unit are you using? i’m using one that has a built-in amplifier MAX9812, which gives a good output range for the Arduino’s analog pin. if you have a microphone without proper amplification you may get a lot of noise. my setup is a bit of a hack, because we’re not supposed to draw much current from the 3V3 pin, and we’re connecting the nRF24 pins to 5V GPIO. If you want a more stable system you probably need to use level shifters (3V3 – 5V) and a good power supply. have a look at this blog post of the library author, i think he’s using level shifters and 7.2V batteries http://tmrh20.blogspot.com/2014/03/arduino-radiointercomwireless-audio.html
Hi Tom,
The microphones I used was exactly the same as yours with a VCC, GND and an OUT pin (connected to A0). Since I didn’t have any powerful wall transformers, all components drawed their powers from the arduino uno board (either 5V and 3.3V) respectively. I once replaced the 100uf capacitor with a 1500uf but there was not much improvement. Perhaps I have to source additional power supply before the next adjustment. Anyway, thank you very much for your continuous support.
Sam
hi Sam, i just saw that 2 ‘famous’ youtubers made a version of this walkietalkie about a month ago, using the same software and a similar setup, but with a self built mic amplifier. these 2 videos are quite instructive if you want to learn more about the signals involved https://www.youtube.com/watch?v=SZYwvvh6m-s and the fix https://www.youtube.com/watch?v=YJ25eQRbhaQ&feature=youtu.be
Hi Tom,
Thank you for your instruction. It is quite interesting to find someone making walkie talkie in that way. Nevertheless, those projects definitely require professional knowledge which is beyond my ability at this moment. Certainly, there is no harm reading more concerning RF technology. Meanwhile, I have made an order for a more powerful wall transformer from Amazon and hopefully it will work.
Regards,
Sam
Hi Tom,
Excellent project. I am trying to do it at home. But, for now, I have two questions. The first one: Why is not necessary to program what the button does? The second one: I do not have a speaker, my idea is to use a 3.5mm jack to connect some headphones, would it work? Or should I change the code?. Thank you very much.
hi, the buttons are handled within the library code. yes headphones will also work, on the same pin.
My last question, why in the code the line that says “rfAudio.transmit()” is commented? Do i have to uncomment it in order to upload the code?
I am a ham radio operator and designed a wireless cw(morse code) key using arduino nanos. I’m running a 100% wireless radio setup but the latency(delay) of hearing the cw is about 250 ms. I’m looking at he RF24 library as a means of wireless headphones with low latency. Any idea what kind of latency I will encounter?
Thanks
hi, i’m not familiar with ham. do you really need to transmit the CW (3kHz?) or would it be acceptable to transfer just one bit (on/off) and ‘decode’ it on the headphone receiver into a beep? i think that will give the best latency results (a few milliseconds? https://forum.arduino.cc/index.php?topic=570511.0) and will not add any hardware. for the RF24audio library, as far as i can see the buffSize is 32 bytes so i think the latency will be similar, but the audio quality might give you a headache.
Hey cool project… Did you understand all functionalities of the library when you did this project. Like you had any idea of what each commands in the library does?
you begin with this 115200 bits per second.
Serial.begin(115200);
My question is , if i reduce 115200 to 9600 is any thing happen in my audio or transmitting signal.
and please upload the schematic design or pcb design for this circuit
yes you can use 9600 baud, it only affects the speed of the Serial print over USB
Good morning friend, I made the connection as it appears but I cannot transmit the sound, it is only heard static, is it necessary to place the capacitor between gnd and VCC of the nfr24l01?
hi, yes the capacitor will improve stability (decoupling cap): the Arduino UNO’s 3.3V pin cannot deliver much current so the capacitor will help to smooth the peak current draw from the radio. without that cap, the radio does not work for me.
Hi.
Thanks for the tip, I added the capacitor and changed one of the two arduino (it was failing) and managed to send and receive sound, but it is not of very good quality, any advice to improve the sound?
Hi.
where the sentences are placed
#define SAMPLE_RATE 16000
#define RF_SPEED RF24_250KBPS
That’s in the userConfig file
Hi, somebody can explain me how can i transfer in privately?
Hola, alguien puede explicarme cómo puedo transmitir en privado?
Hola Daniel, lograste hacer funcionar el proyecto, yo no lo logro aún
Sí Manuel, con dos Arduinos UNO
Que tal daniel, lograste, minimizar el sonido de fondo, es muy molesto, como un pitido
Hola Manuel, el pitido no conseguí eliminarlo pero cumplen su función.