OC
OceanRemote
Low-code IoT platform
← Back to Tutorials
← Previous Next β†’

Tutorial 10: ESP8266 D1 Mini - Pinout and Wiring

πŸ“– What You'll Learn in This Tutorial:
  • βœ“ Understanding the ESP8266 D1 Mini pinout
  • βœ“ Wiring relays to the D1 Mini
  • βœ“ Connecting DHT22, DS18B20, and NTC sensors
  • βœ“ Power supply requirements
  • βœ“ Common wiring mistakes and fixes

ESP8266 D1 Mini Overview

The ESP8266 D1 Mini is the most popular board for OceanRemote. It's small, inexpensive ($3-5), and powerful enough for most home automation projects.

πŸ“ D1 Mini Specifications:
  • Microcontroller: ESP8266 (ESP-12E module)
  • Operating Voltage: 3.3V (5V tolerant on some pins)
  • Input Voltage: 5V (via USB) or 5-12V (via VIN pin)
  • Digital I/O Pins: 16 (D0-D8, D10-D16)
  • Analog Input: 1 (A0, 10-bit ADC, 0-3.3V)
  • Flash Memory: 4MB
  • RAM: 80 KB

Pinout Diagram

                    ESP8266 D1 Mini Pinout
            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
            β”‚  β”Œβ”€β”€β”€β”                              β”‚
            β”‚  β”‚USBβ”‚                              β”‚
            β”‚  β””β”€β”€β”€β”˜                              β”‚
            β”‚                                     β”‚
            β”‚  D0  ────┐  β”Œβ”€β”€β”€β”€  D8               β”‚
            β”‚  D1  ─────  β”œβ”€β”€β”€β”€  D7               β”‚
            β”‚  D2  ─────  β”œβ”€β”€β”€β”€  D6               β”‚
            β”‚  D3  ─────  β”œβ”€β”€β”€β”€  D5               β”‚
            β”‚  D4  β”€β”€β”€β”€β”˜  └────  D4 (LED)         β”‚
            β”‚  D5  ────┐  β”Œβ”€β”€β”€β”€  3.3V              β”‚
            β”‚  D6  ─────  β”œβ”€β”€β”€β”€  GND               β”‚
            β”‚  D7  ─────  β”œβ”€β”€β”€β”€  RST               β”‚
            β”‚  D8  β”€β”€β”€β”€β”˜  └────  A0               β”‚
            β”‚           3V3  GND  RST  TX  RX      β”‚
            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Pin to GPIO Mapping

Board Pin GPIO Function OceanRemote Use
D0 GPIO16 Wake from deep sleep Not used
D1 GPIO5 I2C SCL Relay 1
D2 GPIO4 I2C SDA / Sensor Relay 2 + Sensor
D3 GPIO0 FLASH button Relay 3 (⚠️ boot caution)
D4 GPIO2 Built-in LED Relay 4 (⚠️ boot caution)
D5 GPIO14 SPI CLK Relay 5
D6 GPIO12 SPI MISO Not used
D7 GPIO13 SPI MOSI Not used
D8 GPIO15 SPI CS Not used (⚠️ boot caution)
A0 ADC Analog input NTC Thermistor
⚠️ Critical Boot Pin Notes:
  • GPIO0 (D3) - Must be HIGH at boot. If pulled LOW, board enters flash mode.
  • GPIO2 (D4) - Must be HIGH at boot. Built-in LED is active LOW.
  • GPIO15 (D8) - Must be LOW at boot (connect to GND with 10k resistor if used).
  • GPIO1, GPIO3 (TX/RX) - Used for Serial communication. Avoid using.

OceanRemote's default pin selection avoids boot issues by not using GPIO15 and using D3/D4 with care.

Wiring Relays to D1 Mini

OceanRemote uses 5 relays by default. Here's the recommended wiring:

Relay D1 Mini Pin GPIO Relay Module Connection
Relay 1 D1 GPIO5 IN1 β†’ D1, VCC β†’ 5V, GND β†’ GND
Relay 2 D2 GPIO4 IN2 β†’ D2, VCC β†’ 5V, GND β†’ GND
Relay 3 D3 GPIO0 IN3 β†’ D3, VCC β†’ 5V, GND β†’ GND
Relay 4 D4 GPIO2 IN4 β†’ D4, VCC β†’ 5V, GND β†’ GND
Relay 5 D5 GPIO14 IN5 β†’ D5, VCC β†’ 5V, GND β†’ GND
πŸ’‘ Relay Logic:

Positive Logic (πŸ”Ί) - Relay turns ON when pin is HIGH (3.3V). Default for most relay modules.
Negative Logic (πŸ”») - Relay turns ON when pin is LOW (0V). Use if your relay module is active LOW.

Most cheap relay modules use Negative Logic (LOW = ON). You can change this in the device configuration page.

Wiring Sensors

DHT22 Temperature & Humidity Sensor

DHT22 Pin Connect to D1 Mini
VCC (Pin 1) 3.3V or 5V
DATA (Pin 2) D2 (GPIO4)
GND (Pin 4) GND
DHT22 Wiring:
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ D1 Mini β”‚                    β”‚  DHT22   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€                    β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚   3.3V  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ VDD (1)  β”‚
β”‚    D2   β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ DATA (2) β”‚
β”‚   GND   β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ GND (4)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

DS18B20 Digital Temperature Sensor

DS18B20 Pin Connect to D1 Mini
VDD (Pin 3) 3.3V
DATA (Pin 2) D2 (GPIO4)
GND (Pin 1) GND
⚠️ DS18B20 Requires Pull-up Resistor!

A 4.7kΞ© resistor must be connected between DATA (D2) and 3.3V. Without it, readings will fail.

DS18B20 Wiring (with pull-up):
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ D1 Mini β”‚                    β”‚ DS18B20  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€                    β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚   3.3V  β”œβ”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ VDD (3)  β”‚
β”‚         β”‚    β”‚               β”‚          β”‚
β”‚    D2   β”œβ”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ DATA (2) β”‚
β”‚         β”‚    β”‚    4.7kΞ©      β”‚          β”‚
β”‚   GND   β”œβ”€β”€β”€β”€β”Όβ”€β”€β”€β”€[====]────── GND (1)  β”‚
β”‚         β”‚    β”‚               β”‚          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚               β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

NTC 10kΞ© Thermistor (Analog)

The NTC thermistor requires a voltage divider circuit to work with the D1 Mini's ADC.

Component Connect to D1 Mini
NTC Thermistor Between 3.3V and A0
10kΞ© Resistor (R_series) Between A0 and GND
NTC Thermistor Voltage Divider:
         3.3V
          β”‚
          β–Ό
        β”Œβ”€β”€β”€β”
        β”‚NTCβ”‚  ← 10kΞ© NTC (resistance changes with temperature)
        β””β”€β”€β”€β”˜
          β”‚
          β”œβ”€β”€β”€β”€β”€β”€β–Ί A0 (ADC)  ← Voltage measured here
          β”‚
        β”Œβ”€β”€β”€β”
        β”‚10kβ”‚  ← Fixed 10kΞ© resistor (R_series)
        β”‚Ξ©  β”‚
        β””β”€β”€β”€β”˜
          β”‚
         GND

Power Supply Requirements

USB Power (Recommended for Testing)

  • Use a quality USB cable (not charge-only)
  • 5V, 500mA minimum (1A recommended with relays)
  • Phone charger works well
  • Computer USB port works (but may be limited to 500mA)

External Power (For Permanent Installation)

  • Connect 5-12V DC to the 5V pin (regulated power)
  • Or use the VIN pin for unregulated 5-12V (board has voltage regulator)
  • Relay modules should share the same power supply
  • Total current: ~200mA (D1 Mini) + 70mA per active relay
⚠️ Power Warning:

Do NOT power relays from the D1 Mini's 3.3V pin! Relays need 5V. Use the 5V pin or an external power supply.

Complete Wiring Diagram

Here's a complete wiring diagram for a D1 Mini with 5 relays and a DHT22 sensor:

                    COMPLETE D1 MINI WIRING
            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
            β”‚                                                     β”‚
            β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
            β”‚  β”‚ D1 Mini β”‚      β”‚      5-Channel Relay Module  β”‚  β”‚
            β”‚  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€      β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€  β”‚
            β”‚  β”‚   USB   β”‚      β”‚  IN1 β”‚ D1 β”‚ GPIO5           β”‚  β”‚
            β”‚  β”‚   5V    β”œβ”€β”€β”€β”€β”€β”€β”€  IN2 β”‚ D2 β”‚ GPIO4           β”‚  β”‚
            β”‚  β”‚   GND   β”œβ”€β”€β”€β”€β”€β”€β”€  IN3 β”‚ D3 β”‚ GPIO0           β”‚  β”‚
            β”‚  β”‚   3.3V  β”œβ”€β”€β”€β”€β” β”‚  IN4 β”‚ D4 β”‚ GPIO2           β”‚  β”‚
            β”‚  β”‚   D1    β”œβ”€β”€β”€β”€β”€ β”‚  IN5 β”‚ D5 β”‚ GPIO14          β”‚  β”‚
            β”‚  β”‚   D2    β”œβ”€β”€β”€β”€β”€ β”‚  VCC β”‚ 5V β”‚                 β”‚  β”‚
            β”‚  β”‚   D3    β”œβ”€β”€β”€β”€β”€ β”‚  GND β”‚ GNDβ”‚                 β”‚  β”‚
            β”‚  β”‚   D4    β”œβ”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
            β”‚  β”‚   D5    β”œβ”€β”€β”€β”€β”€β”€β”                                β”‚
            β”‚  β”‚   A0    β”‚      β”‚    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚
            β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β”‚    β”‚      DHT22 Sensor    β”‚     β”‚
            β”‚                   β”‚    β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€     β”‚
            β”‚                   └───── DATA β”‚ D2            β”‚     β”‚
            β”‚                        β”‚ VCC  β”‚ 3.3V          β”‚     β”‚
            β”‚                        β”‚ GND  β”‚ GND           β”‚     β”‚
            β”‚                        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚
            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Common Wiring Mistakes

Mistake 1: Relay Module Powered from 3.3V

  • Problem: Relays don't click or work intermittently
  • Fix: Connect relay VCC to 5V (not 3.3V)

Mistake 2: Missing Pull-up on DS18B20

  • Problem: Sensor reads -127Β°C or fails
  • Fix: Add 4.7kΞ© resistor between DATA and 3.3V

Mistake 3: Wrong GPIO for Relay

  • Problem: Board doesn't boot or relay behaves strangely
  • Fix: Avoid GPIO0, GPIO2, GPIO15 for relays if possible (OceanRemote uses them but they're safe with proper logic)

Mistake 4: Floating Sensor Pins

  • Problem: Random temperature readings
  • Fix: Ensure all sensor pins are connected properly

Mistake 5: Power Supply Too Weak

  • Problem: Device resets when turning on relays
  • Fix: Use a stronger power supply (2A recommended for multiple relays)
πŸ’‘ Testing Before Wiring:

Start with just the D1 Mini connected via USB. Get the firmware working first, then add relays one at a time, then sensors. This makes troubleshooting much easier.

Next Steps

Now that you understand the wiring, continue with:

  • Tutorial 11: ESP8266 D1 Large Pinout and Wiring
  • Tutorial 12: ESP32 Pinout and Wiring Guide
  • Tutorial 13: Raspberry Pi Pico W Pinout and Wiring
  • Return to Tutorial 02: Generate and flash your firmware!
🎯 You're Ready!

Your D1 Mini is now properly wired. You can now generate firmware from the OceanRemote dashboard and flash your device!