Introduction: Seven Segment Display and IR Remote With ESP32 Using Arduino IDE

About: Welcome to School Sur Seine !! Here, i offer step-by-step tutorials using the Arduino UNO, ESP32, Raspberry pi pico wh and other development boards. I also create small projects that combine multiple modules, …

This project involves using an infrared remote (IR Remote) to control a 7-segment display with an ESP32. The objective is simple: each time a numeric button on the remote is pressed, the corresponding digit is displayed on the 7-segment display.

Specifically:

  1. When the 0 button is pressed, the digit 0 appears on the display.
  2. When the 1 button is pressed, the digit 1 appears.
  3. And so on, up to the digit 9.

-------------------------------------------------------------------------------------------

Ce projet consiste à utiliser une télécommande infrarouge (IR Remote) pour contrôler un afficheur 7 segments à l’aide d’un ESP32. L’objectif est simple : chaque fois qu’on appuie sur un bouton numérique de la télécommande, le chiffre correspondant s’affiche sur l’afficheur 7 segments.

Plus précisément :

  1. Lorsque l’on appuie sur le bouton 0, le chiffre 0 apparaît sur l’afficheur.
  2. Lorsque l’on appuie sur le bouton 1, le chiffre 1 apparaît.
  3. Et ainsi de suite jusqu’au chiffre 9.

Supplies

-----------------------------------------------------------------------

  1. ESP32 development board
  2. 30 pin esp32 expansion board
  3. USB-A to Micro-USB cable
  4. IR Remote and Receiver (Kit HX1838)
  5. Juper wires
  6. Breadboard
  7. 5161BS Common Anode 7-Segment Display
  8. Seven 220 Ohm resistors

-----------------------------------------------------------------------

  1. Carte de développement ESP32
  2. Carte d'extension ESP32 à 30 broches
  3. Câble USB-A vers micro-USB
  4. Télécommande et Récepteur Infrarouge (Kit HX1838)
  5. Fils de connexion
  6. Platine d'essai
  7. Afficheur 7-segments à anode commune 5161BS
  8. Sept résistances de 220 Ohm

----------------------------------------------------------------------

Step 1: Common Anode 7-Segment Display / L’afficheur 7 Segments À Anode Commune

A common-anode 7-segment display is an electronic component made of seven LEDs (segments a, b, c, d, e, f, g) arranged in the shape of the digit “8”.

In a common-anode model, all LED anodes are connected together to the +3.3 V supply.

To turn on a segment, a LOW voltage level (0 V) must be applied to its cathode. This allows current to flow from +3.3 V through the LED, lighting it up.

In the wiring used here, each segment is represented by an individual LED.

The seven segments a to g are connected to the ESP32 pins as follows:

  1. a → pin 32
  2. b → pin 33
  3. c → pin 14
  4. d → pin 12
  5. e → pin 4
  6. f → pin 5
  7. g → pin 25

The ESP32 has many digital output pins, but some are better suited than others for controlling LEDs.

In this project, the selected pins (32, 33, 14, 12, 4, 5, 25) are all safe for digital output and can drive the display segments without issues.

Choosing proper pins ensures reliable operation and avoids unexpected behavior during startup or resets.

------------------------------------------------------------------------------------------

Un afficheur 7 segments à anode commune est un composant électronique composé de sept LED (segments a, b, c, d, e, f, g) disposées de manière à afficher les chiffres de 0 à 9.

Dans un modèle à anode commune, toutes les anodes des segments sont reliées ensemble au +3.3 V.

Pour allumer un segment, il faut appliquer un niveau bas (0 V) sur sa cathode : le courant circule du +3.3 V vers la broche du segment, ce qui éclaire la LED.

Dans le câblage utilisé ici, chaque segment est remplacé par une LED individuelle.

Les segments a à g sont connectés aux broches de l’ESP32 selon les correspondances suivantes :

  1. a → pin 32
  2. b → pin 33
  3. c → pin 14
  4. d → pin 12
  5. e → pin 4
  6. f → pin 5
  7. g → pin 25

L’ESP32 dispose de nombreuses broches numériques, mais certaines sont plus adaptées que d’autres pour piloter des LED.

Dans ce projet, les broches sélectionnées (32, 33, 14, 12, 4, 5, 25) sont toutes sûres pour la sortie numérique et permettent de piloter les segments de l’afficheur sans problème.

Bien choisir les broches garantit un fonctionnement fiable et évite des comportements inattendus au démarrage ou lors d’un reset.

Step 2: Circuit Diagram / Schéma

The circuit diagram is made using : thttps://www.wokwi.com/

------------------------------------------------------------------------------------------

Le schéma est réalisé via : thttps://www.wokwi.com/

Step 3: Powering the 7-segment Display / L'alimentation De L'afficheur Sept Segment

Why I Powered the Common Anode Display with 3.3V (ESP32)?

Since the ESP32’s GPIO pins operate only at 3.3V logic level, the safest and most reliable option is to power the common anode of the 7-segment display with 3.3V instead of 5V.

Using 5V directly on the display would force the ESP32 pins to drive the segments with a higher voltage than they can safely handle, which can cause unstable brightness or even damage the microcontroller.

By powering the display at 3.3V, the ESP32 can control each segment directly without using level-shifters, transistors, or driver ICs. The display will be slightly less bright than at 5V, but the setup becomes simpler, safer, and fully compatible with the 3.3V output of the ESP32.

-------------------------------------------------------------------------------------------

Pourquoi j’alimente l’afficheur à anode commune en 3,3 V (ESP32)?

Comme les broches GPIO de l’ESP32 fonctionnent uniquement en logique 3,3 V, la solution la plus sûre et fiable est d’alimenter l’anode commune de l’afficheur 7 segments en 3,3 V plutôt qu’en 5 V.

Utiliser du 5 V directement risquerait de forcer les broches de l’ESP32 à piloter les segments avec une tension plus élevée que ce qu’elles peuvent supporter, ce qui peut provoquer une luminosité instable ou même endommager la carte.

En alimentant l’afficheur en 3,3 V, l’ESP32 peut contrôler chaque segment directement, sans avoir besoin de convertisseurs de niveau, transistors ou circuits pilotes. L’afficheur sera légèrement moins lumineux qu’avec du 5 V, mais le montage reste plus simple, sûr et totalement compatible avec la sortie 3,3 V de l’ESP32.

Step 4: Installing ESP32 in Arduino IDE / Installation De L'ESP32 Dans L'IDE De L'Arduino

1- Open Arduino IDE, then go to File> Preferences

2- Enter the following into the “Additional Board Manager URLs” field:

https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json

Then, click the “OK” button.

-------------------------------------------------------------------------------------------

1- Ouvrir l’Arduino IDE, puis va dans File> Preferences.

2- Dans le champ “Additional Board Manager URLs”, saisir l’adresse suivante :

https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json

Ensuite, cliquer sur le bouton "OK".

Step 5: Libraries / Bibliothèques

1- Open Arduino IDE, then go to the Board Manager. In the search bar, install the “ESP32 by Espressif Systems” library.

2- Once the installation is complete, add and select the ESP32 board you are using from the Tools > Boards menu.

3- On your computer, open the Device Manager to check which COM port your ESP32 board is connected to.

4- Go back to Arduino IDE, navigate to Tools > Port, and select the COM port corresponding to your board.

-------------------------------------------------------------------------------------------

1- Ouvrir Arduino IDE, puis accéder au Gestionnaire de cartes (Board Manager). Dans la barre de recherche, installer la bibliothèque “ESP32 by Espressif Systems”.

2- Une fois l’installation terminée, ajouter et sélectionner la carte ESP32 que vous utilisez dans le menu Tools > Boards

3- Sur l’ordinateur, ouvrir le Gestionnaire de périphériques (Device Manager) pour vérifier sur quel port COM est connectée la carte ESP32.

4- Revenir dans Arduino IDE, aller dans Tools > Port et sélectionner le port COM correspondant à la carte.

Step 6: Source Code / Code Source

You can find the full source code below, and you also have the option to simulate your program directly here. This allows you to test and understand how it works before running it on your actual ESP32.

https://wokwi.com/projects/449256210147349505

-------------------------------------------------------------------------------------------

Vous trouverez le code source complet ci-dessous, et vous avez également la possibilité de simuler votre programme directement ici. Cela vous permet de tester et de comprendre son fonctionnement avant de l’exécuter sur votre réel ESP32.

https://wokwi.com/projects/449256210147349505

Step 7: IR Codes: Wokwi Vs Real Remote / Codes IR : Wokwi Vs Télécommande Réelle

It is important to note that the IR codes used on Wokwi do not always match those of a real remote.

The remote used in the simulation is not the same as the one you use in real life, which leads to differences in the received codes.

Therefore, you need to adjust the codes according to your own remote.

-------------------------------------------------------------------------------------------

Il est important de préciser que les codes IR utilisés sur Wokwi ne correspondent pas toujours à ceux d’une télécommande réelle.

En effet, la télécommande simulée et celle que vous utilisez physiquement ne sont pas identiques, ce qui entraîne des différences dans les codes reçus.

Il est donc nécessaire d’adapter les codes en fonction de votre propre télécommande.

Step 8: Erreur : “Wrong Boot Mode Detected (0x13)! the Chip Needs to Be in Download Mode.”

When you compile your program to upload it, you might encounter the error:

“A fatal error occurred: Failed to connect to ESP32: Wrong boot mode detected (0x13)! The chip needs to be in download mode.”

The solution is simple:

1- Click Upload in the Arduino IDE.

2- When you see:


Connecting...

3- Hold down the BOOT button on your ESP32.

4- Release the BOOT button when your program is uploaded successfully to the board.

Important note: even after fixing this error, the program may still fail to start immediately. If that happens, simply press the RESET button on the ESP32 to get it working properly.

-------------------------------------------------------------------------------------------

Lorsque vous compilez votre programme pour le téléverser, vous pouvez rencontrer l’erreur :

“A fatal error occurred: Failed to connect to ESP32: Wrong boot mode detected (0x13)! The chip needs to be in download mode.”

La solution est simple :

1- Cliquez sur Upload dans Arduino IDE.

2- Lorsque vous voyez :


Connecting...

3- Maintenez le bouton BOOT de votre ESP32.

4- Relâchez le bouton BOOT quand votre programme est téléversé correctement sur la carte.

Remarque importante : même lorsque cette erreur est résolue, il peut arriver que le programme ne démarre pas directement. Dans ce cas, il suffit d’appuyer sur le bouton RESET de l’ESP32 pour que tout fonctionne correctement.