Beeper with telegram bot and esp32
More info and updates in https://rogerbit.com/wprb/2024/06/beeper/
In this tutorial, you will learn how to configure and use an ESP32 device to receive Telegram messages and display them on an SH1106 display. We will also include the functionality of a button and a buzzer to interact with the system
Requirements
An ESP32.
An SH1106 display (128×64) with I2C interface.
A buzzer.
A button.
Connection cables.
Arduino IDE library installed.
Step 1: Installing the Necessary Libraries
Open the Arduino IDE and make sure you have the following libraries installed:
WiFi.h for WiFi connection.
WiFiClientSecure.h for the secure connection.
UniversalTelegramBot.h to interact with the Telegram bot.
U8g2lib.h to manage the SH1106 display.
You can install them from the Arduino IDE Library Manager by searching for the library names.
Step 2: Hardware Connection
Connect the components according to the following diagram:
Display SH1106:
VCC a 5V del ESP32.
GND a GND del ESP32.
SCL a GPIO 22 del ESP32.
SDA a GPIO 21 del ESP32.
Buzzer:
Positive terminal to GPIO 12 of the ESP32.
Negative terminal to GND of the ESP32.
Button :
A terminal to GPIO 23 of the ESP32.
Another terminal to GND of the ESP32.
Step 3: Telegram Bot Configuration
Create a bot on Telegram using BotFather and get the Bot Token.
Replace TOKEN_BOT in the code with the obtained token.
Replace ssid and password with your WiFi network name and password.
Step 4: Load the Code into the ESP32
Connect the ESP32 to your computer.
Select the ESP32 Dev Module board from the Tools -> Board menu.
Select the correct port from the Tools -> Port menu.
Click Upload to upload the code to the ESP32.
Step 5: System Test
Once the code is loaded, open the Serial Monitor in the Arduino IDE to see the debugging messages.
On the SH1106 display, the message “Waiting for message!” should appear.
Send a message to your Telegram bot. The message should appear on the display and the buzzer should sound.
Electronic components
An Esp32
Features of the ESP32-T module
Connectivity
The ESP32 module has all WiFi variants :
802.11 b/g/n/e/i/n
Wi-Fi Direct (P2P), P2P Discovery, P2P Group Owner mode and P2P Power Management
This new version includes connectivity through low-power Bluetooth
Bluetooth v4.2 BR/EDR and BLE
BLE Beacon
In addition, it can communicate using the SPI, I2C, UART, MAC Ethernet, Host SD protocols.
Microcontroller features
The CPU is made up of a Tensilica LX6 model SoC with the following features and memory
Dual 32-bit core with 160MHz speed
Memoria ROM de 448 kBytes
520kBytes SRAM memory
Dyspnea at 48 Pines
18 ADC de 12 bits
2 DAC de 8 bits
10 pin contact sensors
16 PWM
20 digital inputs/outputs
Food and consumption modes
For correct operation of the ESP32, it is necessary to supply a voltage between 2.8V and 3.6V. The energy it consumes depends on the operating mode. It contains a mode, the Ultra Low Power Solution (ULP) , in which basic tasks (ADC, RTC...) continue to be performed in Sleep mode.
female pins
Male female dupont cables
Display oled sh1106
It is a 128x64 dot monochrome OLED display module with I2C interface. It has several advantages compared to LCD screens, and we can highlight its high brightness, very good contrast, a wider viewing angle, and low consumption. of energy. It is compatible with Arduino Rasberry Pi and PIC microcontrollers among others. It works with logic levels from 3.3V to 5V and has a viewing angle greater than 160 degrees. Screen Size is 1.3 inches. It is powered with a voltage of 3.3V to 5V. It can be used in applications such as smart watches, MP3s, thermometers, instruments, and various projects, etc.
Characteristics
Interface: I2C(3.3V / 5V logic level)
Resolution: 128 x 64
Angle of view: >160 degree
Display color: Blue
Display size: 1.3 inch
Driver IC: SH1106
Power supply: DC 3.3V~5V
Operating temperature: -20~70’C
Application: smart watch, MP3, thermometer, instruments, DIY projects, etc.
Buzzer Module
Module ky-004
PCB
Circuit
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>
#include <U8g2lib.h>
// Configuración del display SH1106 usando U8g2
U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ 22, /* data=*/ 21);
// Configuración WiFi
const char* ssid = "Tu-red-WiFi";
const char* contrasena = "Tu-Clave-WiFi";
// Token del bot de Telegram
#define TOKEN_BOT "Tu-Token-Telegram"
// Configuración del buzzer
const int pinBuzzer = 12;
const int duracionBuzzer = 100; // Duración del sonido en milisegundos
// Configuración del botón
const int pinBoton = 23;
bool botonPresionado = false;
WiFiClientSecure cliente;
UniversalTelegramBot bot(TOKEN_BOT, cliente);
unsigned long ultimaVezBotCorrio;
// ID del último chat para enviar respuestas
String idUltimoChat;
void setup() {
Serial.begin(115200);
// Conexión WiFi
WiFi.begin(ssid, contrasena);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Conectando al WiFi...");
}
Serial.println("Conectado al WiFi");
// Configuración del display
u8g2.begin();
// Mostrar mensaje inicial en el display
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_unifont_t_symbols);
u8g2.drawUTF8(0, 10, "Esp. mensaje:");
u8g2.sendBuffer();
// Configuración del buzzer
pinMode(pinBuzzer, OUTPUT);
digitalWrite(pinBuzzer, LOW);
// Configuración del botón
pinMode(pinBoton, INPUT_PULLUP);
// Configuración de cliente seguro
cliente.setCACert(TELEGRAM_CERTIFICATE_ROOT);
}
// Función para dividir el mensaje en líneas que se ajusten al ancho del display
void mostrarTextoLargo(const String &texto) {
const int alturaLinea = 10; // Altura de cada línea
const int maxLineas = 6; // Máximo número de líneas que caben en el display
int indiceInicio = 0;
int indiceFin;
int linea = 0;
while (indiceInicio < texto.length()) {
indiceFin = indiceInicio;
int anchoLinea = 0;
// Encuentra el punto de corte para la línea
while (indiceFin < texto.length() && anchoLinea < u8g2.getDisplayWidth()) {
indiceFin++;
anchoLinea = u8g2.getStrWidth(texto.substring(indiceInicio, indiceFin).c_str());
}
// Ajusta el punto de corte para evitar dividir palabras
if (indiceFin < texto.length()) {
while (indiceFin > indiceInicio && texto[indiceFin] != ' ') {
indiceFin--;
}
}
// Muestra la línea en el display
u8g2.drawUTF8(0, (linea + 1) * alturaLinea, texto.substring(indiceInicio, indiceFin).c_str());
indiceInicio = indiceFin + 1;
linea++;
// Si el texto es más largo que el display, desplaza el texto
if (linea >= maxLineas) {
delay(3000); // Pausa para leer la página actual
linea = 0;
u8g2.clearBuffer();
}
}
u8g2.sendBuffer();
}
void loop() {
// Verificar si el botón ha sido presionado
if (digitalRead(pinBoton) == LOW) {
if (!botonPresionado) {
// Envía un mensaje a Telegram
bot.sendMessage(idUltimoChat, "He leído tu mensaje, puedes enviar otro", "");
// Sonar el buzzer
digitalWrite(pinBuzzer, HIGH);
delay(duracionBuzzer);
digitalWrite(pinBuzzer, LOW);
// Mostrar mensaje en el display
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_unifont_t_symbols);
u8g2.drawUTF8(0, 10, "Mens. enviado!");
u8g2.sendBuffer();
botonPresionado = true;
}
} else {
botonPresionado = false;
}
// Verificar si hay nuevos mensajes de Telegram
if (millis() - ultimaVezBotCorrio > 1000) {
int numNuevosMensajes = bot.getUpdates(bot.last_message_received + 1);
while (numNuevosMensajes) {
Serial.println("Nuevo mensaje recibido");
for (int i = 0; i < numNuevosMensajes; i++) {
String idChat = bot.messages[i].chat_id;
String texto = bot.messages[i].text;
// Guardar el ID del último chat para enviar respuestas
idUltimoChat = idChat;
// Mostrar mensaje en el display
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_unifont_t_symbols); // Selecciona la fuente compatible con Unicode
mostrarTextoLargo(texto);
// Sonar el buzzer
digitalWrite(pinBuzzer, HIGH);
delay(duracionBuzzer);
digitalWrite(pinBuzzer, LOW);
bot.sendMessage(idChat, "Mensaje recibido: " + texto, "");
}
numNuevosMensajes = bot.getUpdates(bot.last_message_received + 1);
}
ultimaVezBotCorrio = millis();
}
}
Beeper with telegram bot and esp32
*PCBWay community is a shared platform and we are not responsible for any design issues.
- Comments(0)
- Likes(0)
- 0 USER VOTES
- YOUR VOTE 0.00 0.00
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
More by CarlosVolt Tutoriales
-
Robot with WiFi control and servos driven by ESP32 More info and updates in https://rogerbit.com/wprb/2023/07/robot-wifi/A robot controlled by Wi-Fi, s...
-
How to make a water level meter with uln2803 In this tutorial we will see how to make a water level meter circuit with the built-in uln2803.The p...
-
Beeper with telegram bot and esp32 More info and updates in https://rogerbit.com/wprb/2024/06/beeper/In this tutorial, you will learn h...
-
8-channel light control with ps/2 keyboard and arduino The 8-Channel Lighting Control System with PS/2 Keyboard and Arduino is a project that combines the ...
-
Electronic scale with Arduino with HX711 module and tare function More info and updates in https://rogerbit.com/wprb/2024/03/balanza-electronica/In this tutorial, you...
-
Capacimeter with Arduino A Capacimeter is an instrument used to measure the capacitance of a capacitor. In this tutorial, we ...
-
Start of section with fingerprint module and arduino micro Project descriptionMore info and update in $ https://rogerbit.com/wprb/2023/08/inicio-seccion-finger...
-
Frequency meter with alarm A frequency meter is a device that measures the frequency of a periodic signal. In combination with ...
-
Emular mouse y teclado con arduino muy fácil En este tutorial, aprenderemos cómo utilizar un Arduino para emular tanto un mouse como un teclado e...
-
Control of apc220 modules with smartphone and app Controlling APC220 modules using a smartphone and an app involves connecting via a serial USB adapte...
-
Exploring the potential of the SI5351 module in electronic projects In this tutorial, you will dive into the depths of this amazing device and discover its limitless po...
-
Gas leak detector alarm system with arduino nano In this tutorial we will see how to assemble a gas leak detector alarm system with arduino nano. We ...
-
Build your own long-range weather station with Lora GPS anemometer module In this tutorial we will see how to create a weather station, for places where there is no internet ...
-
Dual Synchronized Radio Frequency Control for Motor Lights and more In this tutorial we will see how to do a synchronized radio frequency control, since one control can...
-
Object lifter with servo and Arduino Nano Does your waist or back hurt when you bend down? So this invention, it's for you and it can help you...
-
8-channel dual light ignition system, infrared and pushbuttons In this tutorial we will put together a dual light ignition system, since we can control the ignitio...
-
How to turn on lights with telegram and esp32 from anywhere in the world In this tutorial we will see how to make a system that allows us to turn on lights with telegram, fr...
-
Motion detector with light, esp32 and telegram notifications In this tutorial we will see how to make a motion detector system, with a PIR sensor, a relay module...
-
-
TrackSenger - Standalone - Armachat - Meshtastic WiFi-LoRa-BT-GPS
106 0 0 -
MechSenger - Meshtastic / Armachat - with mechanical keyboard
125 0 0 -
-
-
PCB Rule with resistor color code, full color printed with the UV technology
294 0 3 -
Robot with WiFi control and servos driven by ESP32
164 0 1 -
Commodore 1551 Drive Cartridge Replacement
528 0 2 -
RCMHardwareByte-v2.3
350 0 0