ESP32 Internet Radio
This project turns an ESP32 into an Internet Radio that streams online radio stations over Wi-Fi.
Optional features:
- OLED display to show station info
- Push buttons to switch stations
Hardware Required
- ESP32 (Wi-Fi enabled)
- I2S DAC (MAX98357A) or built-in DAC
- Speaker (8Ω–3W)
- OLED SSD1306 (optional)
- Push buttons (optional) for station control
- Jumper wires, breadboard
Connections
I2S DAC (Recommended for High Quality)
| Device | ESP32 Pin | Notes |
|---|---|---|
| BCLK | GPIO 26 | Bit clock |
| LRC | GPIO 25 | Word select |
| DIN | GPIO 22 | Audio data |
| VCC | 3.3V | Power |
| GND | GND | Ground |
| Speaker | DAC output | Connect via DAC |
OLED Display (I²C)
| Device | ESP32 Pin |
|---|---|
| SDA | GPIO 21 |
| SCL | GPIO 22 |
| VCC | 3.3V |
| GND | GND |
Optional Buttons connected to GPIO pins with pull-up resistors.
Full Code Example
c
#include <WiFi.h>
#include <Audio.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// Wi-Fi
const char* ssid = "YOUR_WIFI";
const char* password = "YOUR_PASS";
// Radio stations
const char* radioURLs[] = {
"http://stream.live.vc.bbcmedia.co.uk/bbc_radio_fourlw_online_nonuk",
"http://icecast.omroep.nl/radio1-bb-mp3",
"http://streaming.radionomy.com/JamendoLounge"
};
const char* stationNames[] = {
"BBC Radio 4",
"Radio 1 NL",
"Jamendo Lounge"
};
int stationIndex = 0;
// Audio
Audio audio;
// OLED
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void setup() {
Serial.begin(115200);
// Wi-Fi
WiFi.begin(ssid,password);
while(WiFi.status()!=WL_CONNECTED){
delay(500);
Serial.print(".");
}
Serial.println("Wi-Fi connected");
// Audio
audio.setPinout(26, 25, 22); // I2S BCLK, LRC, DIN
audio.begin();
audio.connecttohost(radioURLs[stationIndex]);
// OLED
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0,0);
display.println("Now Playing:");
display.setTextSize(2);
display.println(stationNames[stationIndex]);
display.display();
}
void loop() {
audio.loop();
// Example: change station every 60 seconds
static unsigned long lastSwitch = 0;
if(millis() - lastSwitch > 60000){
stationIndex = (stationIndex + 1) % 3;
audio.connecttohost(radioURLs[stationIndex]);
lastSwitch = millis();
// Update OLED
display.clearDisplay();
display.setTextSize(1);
display.setCursor(0,0);
display.println("Now Playing:");
display.setTextSize(2);
display.println(stationNames[stationIndex]);
display.display();
Serial.print("Switched to: ");
Serial.println(stationNames[stationIndex]);
}
}