Playback of sound from an SD card through a speaker based on ESP8266 and a Telegram bot

6 August 2024 3 minutes Author: Cyber Witcher
The article describes how to create an ESP8266-based device that plays sound from an SD card through a speaker controlled by commands from a Telegram bot. The necessary components, Telegram bot settings, ESP8266 programming, connecting hardware components, recording audio files to an SD card, and testing the finished device are considered.

Necessary components

  1. ESP8266 (NodeMCU)

  2. Module for reading SD cards (microSD module)

  3. A speaker (for example, a small speaker with an amplifier)

  4. Audio amplifier (eg PAM8403)

  5. Breadboard and wires for connection

  6. SD card with recorded audio file in WAV format

  7. USB cable for ESP8266 programming

  8. A computer with the Arduino IDE installed

  9. A Telegram account to create a bot

Telegram bot settings

Step 1: Creating a Telegram bot

  1. Open Telegram and search for “BotFather”.

  2. Use the /newbot command to create a new bot.

  3. Get an API token that will be used to interact with the bot.

Step 2: Programming the ESP8266

  1. Installing the required libraries: In the Arduino IDE, add the libraries for working with Wi-Fi (`ESP8266WiFi`), Telegram (UniversalTelegramBot), SD card (`SD`) and audio playback (TMRpcm). To do this, go to “Sketch” > “Include Library” > “Manage Libraries” and find and install the appropriate libraries.

  1. Writing code for ESP8266: https://pastebin.com/RuB8kmns

Step 3: Connecting components

  1. SD card connection: Connect the SD card module to the ESP8266 (for example, using the D2 pin for the CS pin).

  2. Speaker Connection: Connect the speaker to the audio amplifier and the amplifier to the ESP8266 (eg pin D1 for audio signal and GND for ground).

Step 4: Record the audio file to the SD card

Take the SD card and load a WAV file named `sound.wav` onto it.

Step 5: Uploading the code to the ESP8266

  1. Connect the ESP8266 to the computer via a USB cable.

  2. Select the appropriate board and port in the Arduino IDE.

  3. Upload the code to the ESP8266.

Step 6: Testing the device

  1. Open Telegram and find your bot.

  2. Send the /play command

  3. The ESP8266 should play the sound from the SD card through the connected speaker.

Conclusion

With this project, we will be able to place our device and reproduce interesting sounds, surprising our friends. Note – this project must be repeated with an understanding of the Arduino and knowledge of the properties of electric current.

Disclaimer. This article is created for informational purposes only. All advice and instructions are provided for educational purposes and we are not responsible for any possible consequences related to the implementation of this project. Always use safety precautions when working with electronic components.

Other related articles
Found an error?
If you find an error, take a screenshot and send it to the bot.