In this ESP8266 tutorial we are going to learn how to use your ESP8266 NodeMCU as a WiFi Radio. Yes, we can add multiple radio channels all over the world. ESP8266 will stream live radio, we are also connecting a speaker to ESP8266. As a result you can see how powerful that tiny ESP8266 chip is. So let’s get started.

Components Required:
  1. NodeMCU ESP8266 12E,
  2. Transistor (TIP 122) or NPN 2N3904 transistor,  
  3. 1k ohms resister,
  4. Speaker (3 watt, 4 ohms),
  5. 4 AAA 1.5V Battery Case,
  6. AAA 1.5V Battery,
  7. Jumper Wires,
  8. Breadboard.
Required Library:

You will need to download ESP8266 Audio library for making WiFi Radio,

Open Arduino IDE, go to

Sketches → Include Libraries → Add .Zip File → add downloaded .zip file

Library added successfully , you can see confirmation at the bottom of the Arduino IDE. To know more about how to add library click here.

Supplying power to Speaker:

As ESP8266 only provide 3.3V we can’t give that power to speaker. It may work if you run speaker with ESP8266’s 3.3V. But you may end up damaging your ESP8266. So better solution is provide separate power supply and use transistor. I am using TIP122, you can also use 2N3904.

Setup for Arduino IDE & Radio:
  1. If you haven’t setup your Arduino IDE for ESP8266, First you need to setup Arduino IDE for ESP8266.
  2. Open Arduino IDE, go to tools → Board → NodeMCU 1.0
  3. Go to tools → change CPU frequency to 160 MHz.

Change ESP8266 CPU frequency to 160 MHz

Finding Streaming Link for Radio:

This is very important step, you can find radio streaming link for your country and insert that link into the main code. You can find Radio streaming link from NDR. Currently it contains 11 radio station. You can select anyone, go and play online. Then download m3u file.

Download m3u file for streaming

Open that downloaded m3u file in VLC player. Click on left side VLC player icon, now you can see media information. Copy location address.

Copy streaming link from VLC playerPaste this streaming link into our main code.

const char *URL=""; //'N-JOY vom NDR -'

Note: Do not use https:// in streaming link. use http:// even if it contain https:// link. otherwise it will not work.

Circuit diagram for Wi-Fi Radio with ESP8266.

ESP8266 Wifi radio stream

Note: Remove Rx Pin before uploading the code, if it is connected, Arduino IDE will show you error.

Code for WiFi Radio with ESP8266:
#include <Arduino.h>

#ifdef ESP32
#include <WiFi.h>
#include <ESP8266WiFi.h>
#include "AudioFileSourceICYStream.h"
#include "AudioFileSourceBuffer.h"
#include "AudioGeneratorMP3.h"
#include "AudioOutputI2SNoDAC.h"

// To run, set your ESP8266 build to 160MHz, update the SSID info, and upload.

// Enter your WiFi setup here:
const char *SSID = "Wi-Fi";
const char *PASSWORD = "Password";

// Uncomment one link (I have added 6 radio streaming link, you can check each)

//flawlessly working radio streaming link
const char *URL=""; //'N-JOY vom NDR -'
//const char *URL="";
//const char *URL="";

// It will work but buffer alot
//const char *URL="";
//const char *URL= "";
//const char *URL="";//Radio RST(German)

AudioGeneratorMP3 *mp3;
AudioFileSourceICYStream *file;
AudioFileSourceBuffer *buff;
AudioOutputI2SNoDAC *out;

// Called when a metadata event occurs (i.e. an ID3 tag, an ICY block, etc.
void MDCallback(void *cbData, const char *type, bool isUnicode, const char *string)
const char *ptr = reinterpret_cast<const char *>(cbData);
(void) isUnicode; // Punt this ball for now
// Note that the type and string may be in PROGMEM, so copy them to RAM for printf
char s1[32], s2[64];
strncpy_P(s1, type, sizeof(s1));
strncpy_P(s2, string, sizeof(s2));
Serial.printf("METADATA(%s) '%s' = '%s'\n", ptr, s1, s2);

// Called when there's a warning or error (like a buffer underflow or decode hiccup)
void StatusCallback(void *cbData, int code, const char *string)
const char *ptr = reinterpret_cast<const char *>(cbData);
// Note that the string may be in PROGMEM, so copy it to RAM for printf
char s1[64];
strncpy_P(s1, string, sizeof(s1));
Serial.printf("STATUS(%s) '%d' = '%s'\n", ptr, code, s1);

void setup()
Serial.println("Connecting to WiFi");



// Try forever
while (WiFi.status() != WL_CONNECTED) {
Serial.println("...Connecting to WiFi");

audioLogger = &Serial;
file = new AudioFileSourceICYStream(URL);
file->RegisterMetadataCB(MDCallback, (void*)"ICY");
buff = new AudioFileSourceBuffer(file, 8192);
buff->RegisterStatusCB(StatusCallback, (void*)"buffer");
out = new AudioOutputI2SNoDAC();
mp3 = new AudioGeneratorMP3();
mp3->RegisterStatusCB(StatusCallback, (void*)"mp3");
mp3->begin(buff, out);

void loop()
static int lastms = 0;

if (mp3->isRunning()) {
if (millis()-lastms > 1000) {
lastms = millis();
Serial.printf("Running for %d ms...\n", lastms);
if (!mp3->loop()) mp3->stop();
} else {
Serial.printf("MP3 done\n");
Code Explanation:

Insert your wifi credential.

const char *SSID = "WiFi";
const char *PASSWORD = "Password";

I have added 6 radio streaming links, you can check each link by uncommenting each one by one. These streaming links are working flawlessly. You can add your favorite radio streaming link here.

//flawlessly working radio streaming link
const char *URL=""; //'N-JOY vom NDR -'
//const char *URL="";
//const char *URL="";

// It will work but buffer alot
//const char *URL="";
//const char *URL= "";
//const char *URL="";//Radio RST(German)
ESP8266 radio stream 35 minutes

streaming flawlessly

If radio contentiously shows you buffering or play for few seconds and again start buffering, To solve this problem, you can increase buffer size, play with this settings, 2048, 4096, 8192. Below image is example of buffering.

buff = new AudioFileSourceBuffer(file, 8192);
Errors & Buffering while streaming ESP8266 Radio


Radio continuously buffering:

1) This can happen, solution to this issue is increase buffer size 2048,4096, 8192. If this doesn’t solve the problem.

2) You can try a different streaming server, or if there is a lower bit rate they can stream at, try that. Because PC can buffer audio for many seconds, but the ESP only has ram for 1/4 of a second.

3) It’s probably network buffering issues between the server and your ESP8266.


If you like this kind of content please subscribe to my YouTube channel for latest updates. Till Then Keep Learning Keep Making.