ESP32 Internet Radio: Build It With MAX98357A, Buttons and OLED
Build an ESP32 internet radio: MAX98357A I2S amp wiring, the ESP32-audioI2S library, stream URLs, station and volume buttons, OLED, PSRAM and fixing dropouts.
An ESP32 internet radio is a small device that pulls a live radio stream over Wi-Fi, decodes the MP3 or AAC data on its own processor and plays the sound through an I2S amplifier and a speaker. All you need is an ESP32, a MAX98357A amplifier module that costs a few dollars, a 4–8 Ω speaker and some wires. No transmitter or antenna is involved; you just put the stream address of any station in the world into the code. In this guide you will build a complete radio that changes station and volume with buttons, shows the station name and the current song on an OLED display and resumes the last station after a power cycle.
The tricky part is not the sound but the continuity: if the stream stutters every few seconds or goes silent after a few minutes, the cause is almost always memory, Wi-Fi or power. So first we will work out which boards and which version of the ESP32-audioI2S library work, why PSRAM matters and how many seconds of reserve the buffer gives you. Then come the wiring table, the code, how to find stream URLs and a symptom-cause-fix table for dropouts.

How does an ESP32 internet radio work?
Internet radio stations send their programme from Icecast or Shoutcast servers as an endless file stream over HTTP. The ESP32 connects to that stream, first fills a buffer with the incoming bytes, then turns them into audio samples (PCM) with its MP3 or AAC decoder and sends them over the I2S bus to the MAX98357A. The MAX98357A is a digital-to-analog converter (DAC) and a class D amplifier in one, so a single module drives the speaker directly. A 128 kbps MP3 stream means 16 KB of data per second. The buffer covers every short pause in Wi-Fi; when it runs dry, the sound cuts out.
| Part | Job | Note |
|---|---|---|
| ESP32 (with PSRAM) | Wi-Fi, streaming, MP3/AAC decoding | ESP32-WROVER or ESP32-S3 (N8R2, N16R8) |
| MAX98357A | I2S DAC and 3.2 W class D amplifier | Runs on 2.5–5.5 V, mono output |
| Speaker | Plays the sound | 4–8 Ω, at least 3 W |
| 0.96 inch OLED (SSD1306) | Station name, song, volume | I2C, 128×64 pixels |
| 3 push buttons | Station, volume up, volume down | To GND with internal pull-ups |
| 5 V adapter | Powers the whole circuit | At least 2 A recommended |
Why PSRAM? Choosing the board and library version
The current 4.x version of the ESP32-audioI2S library only runs with ESP32 Arduino core 3.x and on boards with PSRAM; if it finds no PSRAM it prints "PSRAM not found" to the Serial Monitor and stays silent. On classic ESP32 boards without PSRAM the only option is core 2.x with the old 2.0.0 version of the library. The buffer shows the difference clearly: version 2.0.0 allocates an input buffer of about 8000 bytes without PSRAM and 300000 bytes with PSRAM. On a 128 kbps stream, 8000 bytes is only half a second of reserve, while 300000 bytes is about 19 seconds. Even a brief hiccup from your router causes a dropout on a board without PSRAM, whereas a board with PSRAM rides it out unnoticed.
| Board | PSRAM | Arduino IDE setting (Tools > PSRAM) | For the radio |
|---|---|---|---|
| ESP32 DevKit (WROOM-32) | None | None | Only with version 2.0.0 and a tiny buffer |
| ESP32-WROVER DevKit | Yes (usually 8 MB) | Enabled | Suitable |
| ESP32-S3 DevKitC-1 N8R2 | 2 MB | QSPI PSRAM | Suitable |
| ESP32-S3 DevKitC-1 N16R8 | 8 MB | OPI PSRAM | The most comfortable choice |
| ESP32-C3 / ESP32-S2 | Varies | None | Not supported by the library |
Wiring diagram: MAX98357A, buttons and OLED
| Connection | ESP32 (WROVER) | ESP32-S3 | Note |
|---|---|---|---|
| MAX98357A BCLK | GPIO 27 | GPIO 12 | Bit clock |
| MAX98357A LRC | GPIO 26 | GPIO 13 | Left/right channel clock (WS) |
| MAX98357A DIN | GPIO 25 | GPIO 11 | Audio data |
| MAX98357A VIN / GND | 5V (VIN) / GND | 5V / GND | Do not power from the 3.3 V pin |
| MAX98357A GAIN / SD | Unconnected | Unconnected | 9 dB gain, mix of both channels |
| OLED SDA / SCL | GPIO 21 / GPIO 22 | GPIO 8 / GPIO 9 | VCC to 3V3 |
| Button: next station | GPIO 32 | GPIO 4 | Other leg to GND |
| Button: volume up | GPIO 33 | GPIO 5 | Other leg to GND |
| Button: volume down | GPIO 4 | GPIO 6 | Other leg to GND |
The MAX98357A's GAIN pin sets the gain: left unconnected it gives 9 dB, tied to GND 12 dB and tied to VIN 6 dB; through a 100 kΩ resistor to GND you get 15 dB and to VIN 3 dB. For a small desk speaker 9 dB is plenty; if the sound distorts, lower the gain. With the SD pin unconnected the module plays a mix of the left and right channels; pull it to GND and the amplifier shuts down. For stereo you connect two MAX98357A boards to the same I2S bus and use the SD pin to set one to the left and the other to the right channel. The buttons use the internal pull-up resistors, so no external resistors are needed.
Installing the libraries
- In the Arduino IDE pick your board under Tools > Board: ESP32 Dev Module or ESP32 Wrover Module for a classic WROVER, ESP32S3 Dev Module for an S3.
- Set Tools > PSRAM to Enabled, QSPI PSRAM or OPI PSRAM depending on your board.
- Search the Library Manager for "ESP32-audioI2S" and install the library by schreibfaul1. With ESP32 core 3.x take the latest version; with core 2.x choose 2.0.0 from the version list.
- Install the U8g2 library for the OLED from the same place; it displays accented letters correctly, which is why we use it here instead of Adafruit SSD1306.
- If compiling fails with "Sketch too big", set Tools > Partition Scheme to Huge APP (3MB No OTA).
The code: a radio with station and volume buttons
The code starts with a list of five stations; add as many as you like or swap the addresses for stations from your own country. The pins are chosen automatically for the board type: compile for an ESP32-S3 and the pins from the S3 column are used, compile for a classic ESP32 and the WROVER column applies. Because the way the library reports the station name and song changed between versions, the code has two separate sections, and the compiler picks the right one for your core version.
1// ESP32 internet radyosu: MAX98357A + 3 buton + SSD1306 OLED
2// ESP32 internet radio: MAX98357A + 3 buttons + SSD1306 OLED
3// Çekirdek 3.x: ESP32-audioI2S 4.x (PSRAM şart) / core 3.x: ESP32-audioI2S 4.x (PSRAM required)
4// Çekirdek 2.x: ESP32-audioI2S 2.0.0 / core 2.x: ESP32-audioI2S 2.0.0
5#include <WiFi.h>
6#include <Preferences.h>
7#include <U8g2lib.h>
8#include "Audio.h"
9
10const char* WIFI_SSID = "WIFI_ADIN"; // Wi-Fi adı / Wi-Fi name
11const char* WIFI_PASS = "WIFI_SIFRESI"; // Wi-Fi şifresi / Wi-Fi password
12
13#if defined(CONFIG_IDF_TARGET_ESP32S3)
14 #define I2S_BCLK 12
15 #define I2S_LRC 13
16 #define I2S_DOUT 11
17 #define OLED_SDA 8
18 #define OLED_SCL 9
19 #define BTN_NEXT 4
20 #define BTN_UP 5
21 #define BTN_DOWN 6
22#else // klasik ESP32 (WROVER) / classic ESP32 (WROVER)
23 #define I2S_BCLK 27
24 #define I2S_LRC 26
25 #define I2S_DOUT 25
26 #define OLED_SDA 21
27 #define OLED_SCL 22
28 #define BTN_NEXT 32
29 #define BTN_UP 33
30 #define BTN_DOWN 4
31#endif
32
33struct Station { const char* name; const char* url; };
34const Station stations[] = { // kendi istasyonlarını ekle / add your own stations
35 {"Deutschlandfunk", "http://st01.sslstream.dlf.de/dlf/01/128/mp3/stream.mp3"},
36 {"SWR3", "http://liveradio.swr.de/sw282p3/swr3/play.mp3"},
37 {"1LIVE", "http://wdr-1live-live.icecast.wdr.de/wdr/1live/live/mp3/128/stream.mp3"},
38 {"Bayern 3", "http://dispatcher.rndfnk.com/br/br3/live/mp3/mid"},
39 {"Radio Paradise", "http://stream.radioparadise.com/mp3-128"},
40};
41const uint8_t STATION_COUNT = sizeof(stations) / sizeof(stations[0]);
42
43Audio audio;
44Preferences prefs;
45U8G2_SSD1306_128X64_NONAME_F_HW_I2C oled(U8G2_R0, U8X8_PIN_NONE, OLED_SCL, OLED_SDA);
46
47uint8_t station = 0, volume = 10; // ses 0-21 / volume 0-21
48char stationName[48] = "";
49char streamTitle[96] = "";
50volatile bool screenDirty = true;
51uint8_t lastFill = 0;
52unsigned long lastFillCheck = 0, lastRetry = 0;
53
54const uint8_t BTN_PINS[3] = {BTN_NEXT, BTN_UP, BTN_DOWN};
55bool btnState[3] = {HIGH, HIGH, HIGH};
56unsigned long btnTime[3] = {0, 0, 0};
57
58// Kütüphaneden gelen istasyon adı ve şarkı bilgisi / station name and song info from the library
59#if ESP_ARDUINO_VERSION_MAJOR >= 3
60void onAudioInfo(Audio::msg_t m) {
61 if (!m.msg) return;
62 if (m.e == Audio::evt_name) { strlcpy(stationName, m.msg, sizeof(stationName)); screenDirty = true; }
63 else if (m.e == Audio::evt_streamtitle) { strlcpy(streamTitle, m.msg, sizeof(streamTitle)); screenDirty = true; }
64 else if (m.e == Audio::evt_info) Serial.printf("info: %s\n", m.msg);
65}
66#else
67void audio_showstation(const char* info) { strlcpy(stationName, info, sizeof(stationName)); screenDirty = true; }
68void audio_showstreamtitle(const char* info) { strlcpy(streamTitle, info, sizeof(streamTitle)); screenDirty = true; }
69void audio_info(const char* info) { Serial.printf("info: %s\n", info); }
70#endif
71
72void playStation() {
73 strlcpy(stationName, stations[station].name, sizeof(stationName)); // yayın adı gelene kadar / until the stream sends its name
74 streamTitle[0] = '\0';
75 screenDirty = true;
76 audio.connecttohost(stations[station].url);
77}
78
79void drawScreen() {
80 screenDirty = false;
81 oled.clearBuffer();
82 oled.setFont(u8g2_font_6x13_te); // ä ö ü ß ve ş ğ ı içerir / includes umlauts and Turkish letters
83 char top[24];
84 snprintf(top, sizeof(top), "%u/%u Vol %u", station + 1, STATION_COUNT, volume);
85 oled.drawStr(0, 11, top);
86 oled.drawUTF8(0, 28, stationName);
87 oled.drawUTF8(0, 44, streamTitle);
88 oled.drawFrame(0, 54, 128, 10); // tampon doluluğu / buffer fill level
89 oled.drawBox(2, 56, lastFill * 124 / 100, 6);
90 oled.sendBuffer();
91}
92
93void onPress(uint8_t i) {
94 if (i == 0) {
95 station = (station + 1) % STATION_COUNT;
96 prefs.putUChar("st", station); // son istasyonu hatırla / remember the last station
97 playStation();
98 }
99 else if (i == 1 && volume < 21) volume++;
100 else if (i == 2 && volume > 0) volume--;
101 if (i > 0) { audio.setVolume(volume); prefs.putUChar("vol", volume); }
102 screenDirty = true;
103}
104
105void handleButtons() {
106 for (uint8_t i = 0; i < 3; i++) {
107 bool s = digitalRead(BTN_PINS[i]);
108 if (s != btnState[i] && millis() - btnTime[i] > 40) { // 40 ms debounce
109 btnTime[i] = millis();
110 btnState[i] = s;
111 if (s == LOW) onPress(i);
112 }
113 }
114}
115
116void setup() {
117 Serial.begin(115200);
118 for (uint8_t i = 0; i < 3; i++) pinMode(BTN_PINS[i], INPUT_PULLUP); // buton GPIO ile GND arası / button between GPIO and GND
119 oled.begin();
120 oled.enableUTF8Print();
121 prefs.begin("radio", false);
122 station = prefs.getUChar("st", 0) % STATION_COUNT;
123 volume = prefs.getUChar("vol", 10);
124
125 WiFi.mode(WIFI_STA);
126 WiFi.setSleep(false); // Wi-Fi güç tasarrufu kesintiye yol açar / power save causes dropouts
127 WiFi.begin(WIFI_SSID, WIFI_PASS);
128 while (WiFi.status() != WL_CONNECTED) delay(300);
129
130#if ESP_ARDUINO_VERSION_MAJOR >= 3
131 Audio::audio_info_callback = onAudioInfo;
132#endif
133 audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
134 audio.setVolume(volume);
135 audio.setConnectionTimeout(1000, 3000); // yavaş sunucular için / for slow servers (http, https)
136 playStation();
137}
138
139void loop() {
140 audio.loop(); // akışı çözer ve I2S'e yollar / decodes the stream to I2S
141 handleButtons();
142 if (millis() - lastFillCheck > 1000) { // saniyede bir tampon doluluğu / buffer fill once a second
143 lastFillCheck = millis();
144 uint32_t used = audio.inBufferFilled(), total = used + audio.inBufferFree();
145 uint8_t fill = total ? used * 100 / total : 0;
146 if (fill != lastFill) { lastFill = fill; screenDirty = true; }
147 }
148 if (screenDirty) drawScreen(); // ekranı yalnızca değişince çiz / redraw only on change
149 if (!audio.isRunning() && millis() - lastRetry > 10000) { // yayın durduysa 10 s'de bir dene / retry every 10 s if the stream stopped
150 lastRetry = millis();
151 playStation();
152 }
153#if ESP_ARDUINO_VERSION_MAJOR >= 3
154 vTaskDelay(1);
155#endif
156}In the core 3.x section, the onAudioInfo() function of version 4.x catches the station name (evt_name) and the song information (evt_streamtitle) by event type; in the core 2.x section audio_showstation() and audio_showstreamtitle() do the same job. The volume runs from 0 to 21 and is saved, together with the last station, in the ESP32's non-volatile storage (NVS) with the Preferences library, so after unplugging the radio you carry on where you left off. The WiFi.setSleep(false) line turns off Wi-Fi power saving; with it on, the ESP32 naps at short intervals and the stream arrives unevenly. The display is only redrawn when something changes, because pushing 1 KB of image data to the OLED on every loop delays audio.loop(). The bar at the bottom shows how full the buffer is; if the stream stops, the code tries to reconnect every 10 seconds.
| Function | What it does |
|---|---|
| audio.setPinout(BCLK, LRC, DOUT) | Sets the I2S pins |
| audio.setVolume(0–21) | Sets the volume |
| audio.connecttohost(url) | Connects to the stream and starts playing |
| audio.loop() | Decodes the data and feeds the amplifier; call it as often as possible |
| audio.isRunning() | Returns true while a stream is playing |
| audio.inBufferFilled() / inBufferFree() | Bytes used and bytes still available in the buffer |
| audio.setConnectionTimeout(http, https) | Connection timeout (ms) |
| audio.setBufsize(ram, psram) | Version 2.0.0 only: buffer size, call before connecting |
How do you find a radio station's stream URL?
The "listen live" page on a station's website is usually a player, not a stream address. The easiest way to find the real address is to download the station's .m3u or .pls file and open it in a text editor; the line starting with http is the stream URL. Open station databases such as Radio Browser also list the direct address, format and bitrate of tens of thousands of stations. Before you put an address in the code, test it in VLC with Open Network Stream: an MP3 or AAC address that plays in VLC will also play on the ESP32. The library follows redirects (302) by itself, which is why the German public radio addresses in the code work without trouble.
| Format | Bitrate | Data per second | Note |
|---|---|---|---|
| MP3 | 128 kbps | 16 KB | The most compatible option |
| MP3 | 320 kbps | 40 KB | Drops out often without PSRAM |
| AAC / HE-AAC | 48–64 kbps | 6–8 KB | Ideal for weak Wi-Fi, sounds surprisingly good |
| FLAC | 700–1000 kbps | 90–125 KB | Needs PSRAM and strong Wi-Fi |
| HTTPS stream | Varies | Same | Encryption costs about 40 KB of extra RAM |
Station name and song info on the OLED
Most stations announce their name in the icy-name header at the start of the connection and embed the current song at regular intervals in the stream as a StreamTitle in the form "Artist - Title". The library picks out this information and passes it to the functions in our code. Since song titles often contain accented letters, the code uses U8g2's drawUTF8() function with the u8g2_font_6x13_te font, which has an extended character set. The default font of Adafruit GFX cannot show these letters. Some stations send no song information; in that case only the station name stays on the screen.

Stream dropouts: causes and fixes
| Symptom | Likely cause | Fix |
|---|---|---|
| Short stutters every few seconds | No PSRAM, buffer holds half a second | Use a board with PSRAM; in 2.0.0 enlarge the RAM buffer with setBufsize |
| Stutters change from room to room | Weak Wi-Fi (RSSI worse than -70 dBm) | Move closer to the router, use a board with an external antenna or a 64 kbps AAC station |
| The board resets when you turn it up | Brownout: the amplifier draws current peaks | An adapter of at least 2 A and 470–1000 µF on VIN |
| Sound breaks up when a button is pressed or the screen refreshes | Something in loop() is waiting | Avoid delay(), redraw the screen only on changes |
| The stream goes silent after minutes or hours | The server closed the connection or Wi-Fi dropped | Reconnect with isRunning(), use WiFi.setSleep(false) |
| Info scrolls in the Serial Monitor but there is no sound | BCLK and LRC swapped or SD pin on GND | Check the wiring table, leave SD unconnected |
| "PSRAM not found" appears | PSRAM disabled in the IDE or no PSRAM on the board | Enable Tools > PSRAM or switch to version 2.0.0 |
| Constant crackling and hum | Long wires, no common ground, weak supply | Shorten wires, join all grounds, add a capacitor |
Project ideas for your ESP32 internet radio
- Retro radio: fit the ESP32 into the case of an old valve radio from a flea market and replace the original knob with a rotary encoder for volume and station selection.
- Clock radio: get the time from the internet with NTP and start your favourite station in the morning with slowly rising volume.
- Stereo radio: connect two MAX98357A boards to the same I2S bus and use the SD pins to set one to left and one to right.
- Radio with a web interface: control stations and volume from a page on your phone and store the station list in the ESP32's memory instead of the code.
- Remote-controlled radio: with an IR receiver, map the buttons of an old TV remote to your stations.
- Offline music: for places without Wi-Fi, add a second mode that plays MP3 files from a microSD card with the DFPlayer Mini.
An ESP32 internet radio brings Wi-Fi, audio and a display together in one project; it is fun to build and gets used every day afterwards, and a board with PSRAM plus a solid power supply is half the battle. If you want to try the Wi-Fi connection, OLED and button parts of this project on their own first, the BlueGrays app has projects such as the ESP32 Wi-Fi connection, the weather display on an OLED and playing a melody with a buzzer, step by step with circuit diagrams and ready-to-use code.
Frequently asked questions
What parts do you need for an ESP32 internet radio?
An ESP32 with PSRAM (WROVER or ESP32-S3), a MAX98357A I2S amplifier module, a 4–8 Ω 3 W speaker and a 5 V adapter that delivers at least 2 A are enough. Add push buttons to change stations and a 0.96 inch OLED to show the station name.
Does an ESP32 internet radio need PSRAM?
The current version of the ESP32-audioI2S library does not work without PSRAM at all. On a board without PSRAM the radio plays with the old 2.0.0 version, but because the buffer only bridges half a second, every short Wi-Fi pause interrupts the sound.
Why does my ESP32 radio stream keep cutting out?
The most common causes are a tiny buffer without PSRAM, a weak Wi-Fi signal, the supply voltage sagging when the amplifier draws current, and waiting code in loop(). Using WiFi.setSleep(false), a board with PSRAM, a strong adapter and a capacitor on VIN fixes most dropouts.
What speaker works with the MAX98357A?
The MAX98357A works with speakers between 4 and 8 Ω and delivers about 3.2 W into 4 Ω at 5 V. Connect the speaker directly to the module's + and − outputs; neither of these outputs may be connected to GND.
Can you build a stereo internet radio with an ESP32?
Yes. Connect two MAX98357A modules to the same BCLK, LRC and DIN lines and set their SD pins with resistors so that one plays the left and the other the right channel. Alternatively, use a stereo I2S DAC such as the PCM5102A and feed its output to a ready-made amplifier.
How do I find a radio station's stream URL?
Download the station's .m3u or .pls file and open it in a text editor; the http address inside is the stream URL. Open databases such as Radio Browser also list direct addresses, and the safest approach is to test an address in VLC before adding it to the code.
Projects to build after reading this
See all projects
ESP32 Wi-Fi STA Connection (with LCD Screen)
In this project, we connect the ESP32 to the home Wi-Fi network in Station (STA) mode in a secure, fault-tolerant manner. We store the SSID and password in a separate secrets.h file to prevent leaking to Git, set up an auto-reconnect mechanism, and display the RSSI signal level and IP address on an I2C LCD screen. The internal LED works as a status indicator. It is a production-grade connection manager.

ESP32 Melody Playback with Buzzer
Playing a simple melody (Twinkle Twinkle Little Star) with a passive buzzer. We play notes with tone() and noTone() functions like in Arduino - ESP32 works with the same syntax as Arduino Core 3.0+. Passive buzzer must be used (active buzzer does not play melody).

ESP32 HTTPClient + Weather API (with SSD1306 OLED Display)
In this project the ESP32 makes a REST API call over the internet to a weather API (wttr.in) using HTTPClient.h. Unlike the I2C LCD version, it uses an SSD1306 OLED (128×64) display, with large text and vector icons for a richer look. Seven weather icons (sunny, rainy, snowy and more) are drawn on the fly, with no bitmap files.

Real-Time Clock from the Internet via ESP32 NTP
The ESP32 connects to Wi-Fi and fetches the real time from NTP (Network Time Protocol) servers with millisecond precision. configTzTime() applies the Turkey time zone (TRT, UTC+3) automatically, and in countries with daylight saving time the DST switch is handled by a POSIX TZ string. The time is printed both to the Serial Monitor and to an optional I2C LCD.

ESP32 Asynchronous Web Server (with IP Display on LCD)
In this project, we’re turning the ESP32 into an asynchronous web server that you can control from your phone or computer on the same Wi-Fi network. Thanks to the ESPAsyncWebServer library, the server can process multiple requests simultaneously (unlike the classic WebServer.h, which blocks on a single request). You’ll be able to open the ESP32’s IP address in a browser and click the ON/OFF buttons (the /on and /off routes) to turn the LED connected to GPIO 5 on and off.

ESP32 IR Universal Remote (IR Receiver + Remote Control + 3 LEDs + Buzzer + OLED)
Read a ready-made IR remote with the ESP32 and control your own device! The infrared receiver (NEC protocol, 38kHz) captures the signals of a 20-key remote: keys 1/2/3 toggle three separate LEDs and PWR turns them all off. Press an unknown key and the OLED shows its HEX code, so you can easily add your own remote's buttons to the code.

ESP32 LED Brightness Control with a Potentiometer (Analog → PWM)
In this project, we control the brightness of an LED analogically using a potentiometer. The ESP32's ADC pin reads the 0-3.3V voltage from the potentiometer, and this value is then converted into a PWM (Pulse Width Modulation) signal and sent to the LED. As a result, as you turn the potentiometer, the LED gradually brightens and dims. With Arduino Core 3.0+, analogWrite() can be used directly; on the ESP32-S2/S3, the ADC resolution is fixed at 12-bit.

ESP32 LED Control with Push Button (Push)
The LED lights up when the button is pressed and turns off when released. Shows how the ESP32's digital input pin and internal pull-up resistor are used. The INPUT_PULLUP mode eliminates the need for an external resistor.
More articles
BlueGrays app
Build this circuit step by step on your phone
Wiring diagram, code and parts list on one screen. 500+ Arduino, ESP32, ESP8266, Pico, mBot and micro:bit projects ready to build.
Scan with your phone
Point your camera at the code and your phone's app store opens.
or open the store

