ESP32 WROOM – Pinout, Wi-Fi and Bluetooth

FunduinoLast updated on

Pinbelegung, WiFi, Bluetooth und Einrichtung in der Arduino IDE

You need this

0.96-inch OLED display - 128x64 pixels, I2C, SSD1306 0.96-inch OLED display - 128x64 pixels, I2C, SSD1306 4,19 € *Item no. FUN-1010561About the product — 0.96-inch OLED display - 128x64 pixels, I2C, SSD1306
LCD Module 20x4 - I2C, Blue Backlight, 3.3-5 V LCD Module 20x4 - I2C, Blue Backlight, 3.3-5 V 6,21 € *Item no. F23107181About the product — LCD Module 20x4 - I2C, Blue Backlight, 3.3-5 V
DS3231 RTC module - real-time clock with I2C, 3.3-5.5 V DS3231 RTC module - real-time clock with I2C, 3.3-5.5 V 5,10 € *Item no. F23106657About the product — DS3231 RTC module - real-time clock with I2C, 3.3-5.5 V

All 3 parts together 15,50 € *

* All prices include statutory VAT, plus shipping costs.

What can the ESP32-Wroom do?

The ESP32-Wroom has:

  • digital inputs and outputs
  • analog inputs
  • touch-sensitive pins
  • Bus systems: I2C and SPI
  • WiFi and Bluetooth BLE
ESP32-Wroom development board, top view
The ESP32-Wroom at a glance

I2C pins

The I²C bus (Inter Integrated Circuit) was originally developed by Philips. A controller (here, the ESP32-Wroom) should be able to communicate with various peripherals. The connections are labeled SDA and SCL.

Some components are controlled via I2C:

Example: Displaying random numbers on a 20x4 LCD.

I2C pins: 22 = SCL, 21 = SDA

You can find the LCDIC2 library under Sketch → Include Library → Manage Libraries.

ESP32-Wroom pinout, with I2C pins highlighted
The I2C pins of the ESP32-Wroom
LCD display shows six random numbers
Six random numbers on the 20x4 LCD
Circuit diagram of the LCD display connected to the ESP32-Wroom
Schematic: 20x4 LCD with ESP32-Wroom
Library Manager of the Arduino IDE with LCDIC2
The LCDIC2 library in the Library Manager
1 / 4
Random numbers on the 20x4 LCD
# include "LCDIC2.h"

// 4-zeiliges LCD
LCDIC2 lcd(0x27, 20, 4);

// 2-zeiliges LCD
// LCDIC2 lcd(0x3f, 16, 2);

void setup()
{
  // Zufallsgenerator starten
  randomSeed(analogRead(0));

  // LCD starten
  lcd.begin();

  // Cursor verbergen
  lcd.setCursor(false);

  // Ausgabe auf dem LCD
  // Cursor auf Position 0 in Zeile 0 setzen
  lcd.setCursor(0, 0);
  lcd.print("Zufallszahlen:");

  // Cursor auf Position 0 in Zeile 0 setzen
  lcd.setCursor(0, 1);

  // // 6 Zufallszahlen anzeigen
  for (int i = 1; i <= 6; i++)
  {
    int Zahl =  random(1, 7);
    lcd.print(String(Zahl));
    lcd.print(" ");
  }
}

void loop()
{
  // bleibt leer, Programm läuft nur einmal
}

SPI pins

The SPI bus (Serial Peripheral Interface) is also used for communication between the controller and peripheral devices. The SPI bus requires two data lines and two control lines:

  • COPI (Controller Out Peripheral In) communication sent from the controller to a peripheral device
  • CIPO (Controller In Peripheral Out) communication sent from a peripheral device to the controller
  • CS (Chip Select) the controller activates and starts communication with the peripheral device
  • SCK (Serial Clock) clock frequency generated by the controller for the SPI bus

Note: There are several initiatives to replace the old, but still widely used names MOSI (Master Out Slave In → COPI) and MISO (Master In Slave Out → CIPO):

sparkfun.com/spi_signal_names

oshwa.org – A Resolution to Redefine SPI Signal Names

docs.arduino.cc – SPI

SPI pins: 23 = COPI/SDO, 19 = CIPO/SDI, 18 = CLK, 5 = CS

ESP32-Wroom pinout, SPI pins highlighted
The SPI pins of the ESP32-Wroom

Touch pins

The human body and electrically conductive objects can store electrical charge. Touching one of the touch pins changes the measured value.

Example: Connect a wire to touch pin 32.

Touch pins: 32, 33, 27, 14, 12, 13, 4, 2, 15

ESP32-Wroom pinout, touch pins highlighted
The touch pins of the ESP32-Wroom
Wire to touch pin 32 of the ESP32-Wroom
Example: a cable on touch pin 32
Serial monitor with touch pin readings
Output in the Serial Monitor when touched
1 / 3
Read touch pin 32
void setup()
{
  // Serielle Kommunikation starten
  Serial.begin(9600);
  delay(1000);
}

void loop()
{
  Serial.print("Wert: ");

  // gemessenen Wert am Touch-Pin 32 anzeigen
  Serial.print(touchRead(32));

  // wenn der Wert < 20 -> Pin wurde berührt
  if (touchRead(32) < 20) Serial.println(" -> Pin berührt");

  // bei größeren Werten wurde der Pin nicht berührt
  else Serial.println(" -> Pin nicht berührt");
  delay(1000);
}

Digital pins

Digital pins (INPUT and OUTPUT). The example program makes an LED on pin 33 blink.

Digital pins on the left: 33, 25, 26, 27, 14, 12, 13

Digital pins on the right: 23, 22, 21, 19, 18, 5, 17, 16, 4, 2, 15

ESP32-WROOM pinout, digital pins highlighted
The digital pins of the ESP32-Wroom
LED connected to pin 33 of the ESP32-Wroom
The LED blinking program on pin 33
1 / 2
Make the LED on pin 33 blink
int LED = 33;
void setup()
{
  pinMode(LED, OUTPUT);
}

void loop()
{
  digitalWrite(LED, HIGH);
  delay(1000);
  digitalWrite(LED, LOW);
  delay(1000);
}

Analog pins

Two 12-bit ADC (analog-to-digital converter) channels are available. When using Wi-Fi, only pins 32 to 39 can be used as analog inputs. The signal has a range of values from 0 to 4095.

Example: potentiometer on pin 35.

Analog pins: 36, 39, 34, 35, 32, 33

ESP32-WROOM pinout, analog pins highlighted
The analog pins of the ESP32-Wroom
Potentiometer on analog pin 35 of the ESP32-Wroom
Potentiometer on Pin 35
Serial plotter with a curve of potentiometer values
Serial Plotter output when turning the potentiometer
1 / 3
Read potentiometer on pin 35
// Potentiometer an Pin 35
int Potentiometer = 35;

// Variable für den gelesenen Wert
int GelesenerWert = 0;

void setup()
{
  Serial.begin(9600);
  delay(1000);
}

void loop()
{
  // analogen Wert lesen
  GelesenerWert = analogRead(Potentiometer);
  Serial.println(GelesenerWert);
  delay(500);
}

DAC pins

There is no analogWrite() for the ESP32-Wroom. Instead, pins 25 and 26 can be controlled with dacWrite. The program increases the LED's brightness in increments of 5, then dims the LED.

DAC pins: 25, 26

ESP32-Wroom pinout, DAC pins highlighted
The DAC pins of the ESP32-Wroom
Dim the LED on pin 25 (DAC)
void setup()
{
  // no setup required
}

void loop()
{
  // Increase brightness in steps of 5
  for (int i = 50; i < 255; i+=5)
  {
    dacWrite(25, i);
    delay(20);
  }

  // Decrease brightness in steps of 5
  for (int i = 255; i > 50; i-=5)
  {
    dacWrite(25, i);
    delay(20);
  }
}

WiFi

Example: The program displays 6 random numbers in the browser. The IP address of the ESP32-Wroom obtained via DHCP is displayed in the Serial Monitor.

Enter this address in a browser of your choice.

Browser window with six random numbers from the ESP32-Wroom
Six random numbers in the browser
The serial monitor displays the IP address of the ESP32-Wroom
The IP address assigned via DHCP in the Serial Monitor
1 / 2
Display random numbers in the browser (WiFi)
#include "WiFi.h"
// Router SSID and password
char Router[] = "Router_SSID";
char Passwort[] = "xxxxxxxx";
WiFiServer Server(80);
WiFiClient Client;
// Minimum and maximum random numbers
int Minimum = 1;
int Maximum = 49;
void setup()
{
 Serial.begin(9600);
 // Wait for serial connection
 while (!Serial);
 // Start WiFi
 WiFi.begin(Router, Passwort);
 // Establish connection
 while (WiFi.status() != WL_CONNECTED)
 {
 delay(200);
 Serial.print(".");
 }
 Server.begin();
 // Display router SSID
 Serial.println();
 Serial.print("Connected to ");
 Serial.println(WiFi.SSID());
 // Display IP
 Serial.println(WiFi.localIP());
 // Initialize random number generator with the signal on A0
 randomSeed(analogRead(0));
}
void loop()
{
 Client = Server.available();
 if (Client)
 {
 // Build page if SeiteAufbauen is true
 boolean SeiteAufbauen = true;
 // While the client is connected ...
 while (Client.connected())
 {
 if (Client.available())
 {
 // Read request from client ...
 char Zeichen = Client.read();
 // return (\n) sent
 if (Zeichen == '\n')
 {
 // If SeiteAufbauen has the value true
 if (SeiteAufbauen)
 {
 /*
 Build HTML page
 the following instructions must
 be sent with print or println
 println "beautifies" the source code
 (creates a line break in the source code)
 */
 // Build HTML page
 Client.println("HTTP/1.1 200 OK");
 Client.println("Content-type:text/html");
 // Blank line is required
 Client.println();
 Client.println("<!doctype html>");
 Client.println("<html>");
 Client.println("<body>");
 // Refresh every 60 seconds with a meta tag
 Client.println("<meta http-equiv=\"refresh\" content=\"60\">");
 // <h2> H2 heading
 Client.println("<h2>Random numbers</h2>");
 // <hr> horizontal line
 Client.println("<hr>");
 // Display random numbers
 for (int i = 0; i < 7; i++ )
 {
 int Zahl = random(Minimum, Maximum);
 Client.println(Zahl);
 Client.println(" ");
 }
 Client.print("<hr>");
 // Display IPs
 Client.print("Own IP (server): ");
 Client.print(Client.remoteIP());
 // <br> break = newline
 Client.print("<br>Client DHCP IP address ");
 Client.print(WiFi.localIP());
 // Close the page
 Client.println("</h2></body>");
 Client.println("</html>");
 // The HTTP response ends with a newline
 Client.println();
 // Page fully loaded -> exit loop
 break;
 }
 // If a newline (\n) was sent -> build the page
 if (Zeichen == '\n') SeiteAufbauen = true;
 else if (Zeichen != '\r') SeiteAufbauen = false;
 delay(1);
 Client.stop();
 }
 }
 }
 }
}

Bluetooth BLE

First install the ArduinoBLE library via Sketch → Include Library → Manage Libraries, then search for ArduinoBLE.

The program switches an LED on pin 18: 1 turns it on, 0 turns it off.

The LightBlue app, available for iOS and Android, controls the LED (screenshots from iOS).

Arduino IDE Library Manager with ArduinoBLE
The ArduinoBLE library in the Library Manager
Switch LED via Bluetooth BLE
# include "ArduinoBLE.h"
/*
  determine unique UUID:
  https://www.guidgenerator.com/online-guid-generator.aspx
  https://www.uuidgenerator.net/
  BLERead | BLEWrite | BLENotify
  -> write, read, info
*/

// BLE service name
BLEService LEDSchalten("19b10000-e8f2-537e-4f6c-d104768a1214");

BLEUnsignedCharCharacteristic Auswahl("19b10000-e8f2-537e-4f6c-d104768a1214", BLERead | BLEWrite | BLENotify);

// LED on pin 18
int LED = 18;

void setup()
{
  Serial.begin(9600);

  // wait for serial connection
  while (!Serial);
  delay(1000);

  // set pinMode
  pinMode(LED, OUTPUT);

  // start BLE
  if (!BLE.begin()) Serial.println("Bluetooth module could not be started!");
  else Serial.println("Bluetooth module started successfully!");

  // set name (displayed in the app) and assign the service (LEDSchalten)
  BLE.setLocalName("Switch LED");
  BLE.setAdvertisedService(LEDSchalten);

  // Auswahl as a placeholder for the value selected in the app
  LEDSchalten.addCharacteristic(Auswahl);

  // add service LEDSchalten
  BLE.addService(LEDSchalten);

  // write initial value for communication
  Auswahl.writeValue(0);

  // start advertising
  BLE.advertise();
}

void loop()
{
  // wait for connection to devices
  BLEDevice Verbindung = BLE.central();

  // if the ESP32 is connected to a device ...
  if (Verbindung)
  {
    Serial.println("Connected ... ");

    // while the controller is connected to a device ...
    while (Verbindung.connected())
    {

      if (Auswahl.written())
      {
        // turn on LED
        if (Auswahl.value() == '1')
        {
          Serial.print(char(Auswahl.value()));
          Serial.println(" -> LED on");
          digitalWrite(LED, HIGH);
        }

        // turn off LED
        if (Auswahl.value() == '0')
        {
          Serial.print(char(Auswahl.value()));
          Serial.println(F(" -> LED off"));
          digitalWrite(LED, LOW);
        }
      }
    }
  }
}

Install board

Under File → Preferences, enter an additional Boards Manager URL: https://dl.espressif.com/dl/package_esp32_index.json

  • Click the Boards Manager icon or go to Tools → Board → Boards Manager
  • Search for ESP32
  • Install the board
Arduino IDE settings with an additional Board Manager URL
Enter an additional board manager URL
Board Manager in the Arduino IDE with ESP32 package
Install ESP32 in the Board Manager
1 / 2

Select board

If the ESP32-WROOM was not detected automatically, click “Select another board and port” and search for esp32-wroom. Depending on your operating system, the USB port will have a different name.

Arduino IDE dialog for board and port selection
Select a different board and a different port
Arduino IDE selection list with ESP32-WROOM
Select the ESP32-WROOM
1 / 2
Rate the instructions

Comments

Ask a question or share an experience

Contact us if something doesn’t work. Please include your board and the error message.

We review every comment before publication. Your email address remains with us.