ESP32: OLED Screen and PWM w/ LED

Agung Ahsary
3 min readMar 6, 2022

This time, in this blog, I’m going to explain how to do 2 things: 1. Display something on your OLED 128x64 0.96 inch screen, and 2. PWM (Pulse Modulation Width) with LED lamp.

ESP32 OLED Screen

In this section we’re going to make our OLED screen show several animations.

Requirements:

  1. ESP32 board
  2. Micro-USB to USB cable
  3. Arduino IDE software
  4. PC/Laptop
  5. Jumper wires
  6. 128x64 OLED I2C screen

Steps:

  1. Open your Arduino IDE software on yout PC/laptop.

2. Connect your ESP32 to your PC/laptop using your Micro-USB to USB cable.

3. Do an initial setup for your ESP32 board shown in this article (step 3 and step 4 only) https://agungahsary255.medium.com/how-to-make-esp32-built-in-led-blink-b16b7cb4c6fa.

4. Go to Sketch > Include Library > Manage Libraries and type “ssd1306” in the search box and install “Adafruit SSD1306”. Also type in ‘GFX’ and install “Adafruit GFX Library”.

5. Do this schematics.

This what mine looks like (with breadboard).

6. To write the code automatically, go to File > Examples > Adafruit SSD1306 > ssd1306_128x64_i2c . Or just paste from https://raw.githubusercontent.com/RuiSantosdotme/Random-Nerd-Tutorials/master/Projects/OLED/oled_adafruit_demo.ino. You will get the code like this.

And etc. etc…

7. Upload the code and it will do this.

Now let’s get straight into the PWM project!

ESP32 PWM with LED Lamp

In this section we’re going to make our LED lamp change brightness (increase and decrease) slowly with PWM.

Requirements:

  1. ESP32 Board
  2. Arduino IDE Software
  3. PC/Laptop
  4. LED Lamp
  5. Jumper Wires
  6. 330 Ohm Resistor
  7. Breadboard

Steps:

  1. Open your Arduino IDE software on yout PC/laptop.

2. Connect your ESP32 to your PC/laptop using your Micro-USB to USB cable.

3. Do an initial setup for your ESP32 board shown in this article (step 3 and step 4 only) https://agungahsary255.medium.com/how-to-make-esp32-built-in-led-blink-b16b7cb4c6fa.

4. Do this schematics.

5. Write this code https://raw.githubusercontent.com/RuiSantosdotme/ESP32-Course/master/code/LED_PWM_Example_1/LED_PWM_Example_1.ino.

Taken from my Arduino IDE Software

6. Upload the code and you should see the LED doing this.

Aand we’re done! Thanks for reading!

--

--