Seven Segment Display With ESP32 Using Arduino IDE
by sss2022 in Circuits > Electronics
76 Views, 1 Favorites, 0 Comments
Seven Segment Display With ESP32 Using Arduino IDE
In this project, a simple display circuit was built using an ESP32 board, a common anode 7-segment display, and a few electronic components. The display shows the digits from 0 to 9 in sequence, changing the value every second.
This setup allows beginners to understand how to control multiple digital output pins on the ESP32 and how to activate the different segments of the display.
-------------------------------------------------------------------------------------------
Dans ce projet, un circuit d’affichage simple a été réalisé en utilisant une carte ESP32, un afficheur 7 segments à anode commune et quelques composants électroniques. L’afficheur montre successivement les chiffres de 0 à 9, en changeant de valeur chaque seconde.
Ce fonctionnement permet aux débutants de comprendre comment contrôler plusieurs sorties numériques de l’ESP32 et comment activer les différents segments de l’afficheur.
Supplies
-----------------------------------------------------------------------
- ESP32 development board
- 30 pin esp32 expansion board
- USB-A to Micro-USB cable
- Breadboard
- 5161BS Common Anode 7-Segment Display
- Seven 220 Ohm resistors
- Jumper wires
-----------------------------------------------------------------------
- Carte de développement ESP32
- Carte d'extension ESP32 à 30 broches
- Câble USB-A vers micro-USB
- Platine d'essai
- Afficheur 7-segments à anode commune 5161BS
- Sept résistances de 220 Ohm
- Câbles
----------------------------------------------------------------------
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:
- a → pin 32
- b → pin 33
- c → pin 14
- d → pin 12
- e → pin 4
- f → pin 5
- 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 :
- a → pin 32
- b → pin 33
- c → pin 14
- d → pin 12
- e → pin 4
- f → pin 5
- 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.
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/
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.
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".
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.
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/449230086660324353
-------------------------------------------------------------------------------------------
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.
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:
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 :
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.