NodeMCU ≡ Detecting I2C Devices
NodeMCU I2C address detector circuit
#include <Wire.h>

void setup() {
  Wire.begin();
  Serial.begin(115200);
}

void loop() {
  scanI2CDevices();
  delay(5000);  
}

void scanI2CDevices() {
  for (byte address = 1; address < 127; ++address) {
    Wire.beginTransmission(address);
    if (Wire.endTransmission() == 0) 
      Serial.println("Device found at 0x" + String(address < 16 ? "0" : "") + String(address, HEX));
  }
}

 

By default, NodeMCU uses D1 (SCL) and D2 (SDA) pins for I2C communication.
When you call Wire.begin() without any parameters, it automatically assumes these default pins.

If you want to use different pins for I2C, you can specify them in the Wire.begin(SDA, SCL) function,
where SDA and SCL are the new pins you choose.
For example, if you want to use D2 (SDA) and D5 (SCL), you would write:

Wire.begin(D2, D5);

 


Here’s a list of recommended I2C pins for NodeMCU:

  • SDA: D2, D3, D4, D5
  • SCL: D1, D2, D3, D5

NodeMCU


19 Nov. 2024 | Last Updated: 22 Nov. 2025 | jaimedcsilva

Related
  • How to Set Up Arduino IDE for ESP8266 Development
  • Blink the Built-in LED
  • Connecting the ESP8266 to Wi-Fi
  • Measuring Wi-Fi Signal Strength (RSSI) with ESP8266
  • ESP-01 ≡ How to program an ESP-01?
  • ESP-01 ≡ Detecting I2C Devices
  • ESP-01 ≡ TX button and an RX LED
  • ESP-01 ≡ Blink external LED on GPIO0
  • NodeMCU ≡ Blink external LED on D0
  • NodeMCU ≡ Detecting I2C Devices

  • Buy Me a Coffee