← Back to list

How to connect to simple digital modules using an ESP32

So you blinked the light and are ready to tackle on more projects? You have some sort of module that you are ready to connect but have no…

Alejandro Garcia · 2026-06-30 17:01 · 0 claps · 1.9 min read
#embedded-systems #esp32-tutorial #iot #embedded
Open on Medium ↗
Wiki topics: 📟 · Gadgets & IoT

How to connect to simple digital modules using an ESP32

So you blinked the light and are ready to tackle on more projects? You have some sort of module that you are ready to connect but have no idea where to start? Well look no further, in this guide we will go through how to wire and interact with different simple digital modules.

Before we dive into the code and wires though, lets go over what a simple digital module is. A digital module is any add on that normally only contains 3 pins; Ground (GND), VCC, and S. If you happen to have SCK, SDA, or any other sort of letters and more pins than the module most likely interfaces the ESP on some sort of data bus which will not be covered here.

The Pins

As noted, the three main pins will be as follows:

Ground (GND): This can be connected to any common ground such as the ESP’s dedicated GND pin. This pin can show up as GND or a “-”.

Voltage Common Connector (VCC): Depending on the module, this is the main power pin which can be 3.3V which can connect to the ESP’s matching VCC pin.

Signal (S, OUT, SIG): This pin is utilized for communication or control which will be connected to a GPIO port of the ESP.

The Wiring

Module GND  → ESP32 GND
Module VCC  → ESP32 3V3 
Module S    → ESP32 GPIO4

The Code

The following code will be for ESP32 devices utilizing PlatformIO’s ESP-IDF.

GPIO Pin Selection:

#define OUTPUT_PIN    GPIO_NUM_4 //Please select the pin where Signal wire is
#define BUTTON_PIN GPIO_NUM_0 //Default button pin

GPIO Initialization:

gpio_set_direction(OUTPUT_PIN, GPIO_MODE_OUTPUT);
gpio_set_direction(BUTTON_PIN, GPIO_MODE_INPUT);
gpio_set_pull_mode(BUTTON_PIN, GPIO_PULLUP_ONLY);

Main Loop

The main loop is fairly simple; while running if the button is pressed then the MCU will set the Signal pin to 1 which activates whatever module is here.

while (1){
  if (gpio_get_level(BUTTON_PIN) == 0) {  
    gpio_set_level(OUTPUT_PIN, 1);
   } else {
     gpio_set_level(OUTPUT_PIN, 0);
      }
      vTaskDelay(pdMS_TO_TICKS(10));  
  }
}

Conclusion

Thats about it, just 3 pins and a few lines of code gets you a working digital module with an ESP32. This same pattern applies whether you’re switching a relay, triggering a buzzer, or firing off an LED strip.

Once you’re comfortable with this, the natural next step is modules that use a data bus instead of a single signal pin — I2C and SPI devices like sensors and displays. While those need a bit more setup, but the core idea is the same: power it, ground it, and talk to it. I’ll cover I2C and SPI modules in a future post as I work through them on my own builds.

→ GitHub: github.com/AGBaltazar

→ Portfolio: alejandrobaltazar.dev

→ LinkedIn: linkedin.com/in/alejandrobaltazar

Full Code

#include "driver/gpio.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

#define OUTPUT_PIN    GPIO_NUM_4
#define BUTTON_PIN GPIO_NUM_0 

void app_main(void) {
    gpio_set_direction(OUTPUT_PIN, GPIO_MODE_OUTPUT);

    // Button input with pull-up
    gpio_set_direction(BUTTON_PIN, GPIO_MODE_INPUT);
    gpio_set_pull_mode(BUTTON_PIN, GPIO_PULLUP_ONLY);

    while (1) {
        if (gpio_get_level(BUTTON_PIN) == 0) {  
            gpio_set_level(OUTPUT_PIN, 1);
        } else {
            gpio_set_level(OUTPUT_PIN, 0);
        }
        vTaskDelay(pdMS_TO_TICKS(10));  
    }
}

메타데이터
post_id
5fe19952da19
slug
how-to-connect-to-simple-digital-modules-using-an-esp32-5fe19952da19
url
https://medium.com/@agee.baltazar/how-to-connect-to-simple-digital-modules-using-an-esp32-5fe19952da19
canonical_url
https://medium.com/@agee.baltazar/how-to-connect-to-simple-digital-modules-using-an-esp32-5fe19952da19
author_url
https://medium.com/@agee.baltazar
status
ok
fetched_at
2026-08-06 02:49:13