Internet Radio Based on ESP32

Publisher:科技舞者Latest update time:2022-08-03 Source: elecfansKeywords:ESP32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Analog radio is fading away in this digital world, as today everything from movies to songs is streamed directly from the internet. Let's see how you can make internet radio by utilizing some simple digital electronics, coding, and a working internet connection.


Internet radios can be created as standalone devices that run over the internet, or as software that runs through a computer connected to the internet. Here, we will make a standalone device that will connect to Wi-Fi, access the internet, and finally play audio. To build our ESP32 internet radio, we chose the ESP32 development board (obviously) and the MAX98357A I2S amplifier. If you are looking for a simple FM radio that can work offline, then you should check out the linked article.


Components needed to build an ESP32 Internet Radio

You will need the following components to build our Internet Radio using the ESP32. Most of the parts should be easily available.


ESP32 Development Kit

MAX98357A

8 ohm speakers rated at 0.5W to 1W.

USB cable

5V 1A charger

An active Internet connection

ESP32 and I2S Communication

As most of us know, ESP32 is an extremely low-cost, low-power system-on-chip microcontroller with integrated Wi-Fi and dual-mode Bluetooth. We have built many ESP32 projects before, and you can check them out if you are interested. However, we will not use the Bluetooth function of ESP32 here, but we still chose ESP32 for the reasons listed below.


It has Wi-Fi module

Low cost

It has I2S peripheral support.

Now, why is I2S important?

The Inter-IC Sound bus (I2S) is a serial bus interface standard for connecting digital audio devices. It is manufactured by Philips Semiconductors. This interface is most commonly used with audio ADC and DAC components.

Since to run the radio we need to use a speaker and need to produce an analog output, we need some kind of digital to analog converter. This is the interesting part of this project. The MAX98357A module. It provides a digital Class D amplifier that communicates with the microcontroller unit using a digital audio interface or I2S.


The advantages of the MAX98357A I2S module are as follows:

Efficiency up to 92%

Delivers 3.2W output power into 4 ohms at 5V

Click and pop noise reduction

Short circuit and thermal protection

Support left, right or (left/2 + right/2) output

The operating voltage is 2.5V to 5.5V.

The MAX98357A I2S module we are using in this project is shown in the image below.

poYBAGLo6DuAMMWRAAV0KPSxdVA487.png

Circuit diagram of MAX98357A I2S module interfacing with ESP32

pYYBAGLo6DeANb2JAACc0LTzDVI677.png

The schematic is very simple. The MAX98357 connections are shown in the table below.

pYYBAGLo6DSAM31nAAAg1rErJdY510.png

Since the gain pin is connected to GND, the gain is 12dB.

ESP32 Internet Radio Code

Well, this project uses the ESP32-audioI2S library available on GitHub. Before we get into the code, make sure you download the library from the following link and add it to your Arduino IDE.

ESP32 Audio I2S Library

The full code is provided at the bottom of this page, you can directly copy and use the code, but if you need its explanation, please read further.

First, include the libraries required for the project, as shown below.

#include "Arduino.h" 
#include "WiFi.h" 
#include "Audio.h"

Then, specify the pinout of the MAX98357A. If you are using the exact same module as shown above, you can leave it as shown below.

#define MAX98357A_I2S_DOUT 25 
#define MAX98357A_I2S_BCLK 27 
#define MAX98357A_I2S_LRC 26
Audio Audio;

Enter your Wi-Fi SSID and password, which allows the ESP32 to connect to the Internet.

String ssid = "your username"; 
String password = "your password";

In the settings, the WiFi password and SSID are being set, and WiFi is started. After connecting to Wi-Fi, the audio pin is selected and the volume is also set to maximum.

  audio.setPinout(MAX98357A_I2S_BCLK, MAX98357A_I2S_LRC, MAX98357A_I2S_DOUT); 
  audio.setVolume(100);

Set the streaming URL here, you can choose any streaming URL of your choice, you can also introduce a potentiometer to switch between multiple streaming channels if needed.

  audio.connecttohost("http://vis.media-ice.musicradio.com/CapitalMP3"); 
}

After all of this, use the following code to play the audio continuously in a void loop.

void loop()
{
  audio.loop();
}

Testing our ESP32 web radio player

The circuit is properly connected as per the schematic diagram and connected with Wi-Fi. Once the setup is started, it connects to the internet and starts streaming audio from the URL mentioned in the program.

poYBAGLo6C-AWm2yAAaVvrzKY28892.png

#include "Arduino.h"

#include "WiFi.h"

#include "Audio.h"

#define I2S_DOUT 25

#define I2S_BCLK 27

#define I2S_LRC 26

audio audio;

string ssid = "Sourav";

string password = "87654321";

void setup() {

WiFi.disconnect();

WiFi.mode(WIFI_STA);

WiFi.begin(ssid.c_str(), password.c_str());

while (WiFi.status() != WL_CONNECTED)

delay(1500);

audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);

audio.setVolume(100);

audio.connectToHost(" http://vis.media-ice.musicradio.com/CapitalMP3 ");

}


Keywords:ESP32 Reference address:Internet Radio Based on ESP32

Previous article:Build a simple musical doorbell using the UM66T melody generator
Next article:How to use Raspberry Pi to implement a Jarvis themed speaking alarm clock

Latest Embedded Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号