Sensor Wiring for ESP32, Arduino, and Pico: I2C, SPI, UART, and Analog Checks

Sensor Wiring for ESP32, Arduino, and Pico: I2C, SPI, UART, and Analog Checks

Sensor wiring fails on bus practice more often than on part choice. Pick the bus by pin count, device count, speed, and distance: I2C for several slow sensors on two wires, SPI for fast devices with one chip-select pin each, UART for point-to-point serial links, and analog for single voltage outputs. Then check pull-ups, shared-bus addresses, logic voltage, and ground before blaming code.

All prices in this guide were checked November 18, 2026. Prices can change, so check the listing before you order. Shipped fast and securely from our secure facility in New York, providing fast, high quality USA shipping.

Pick the bus before you pick the sensor

Most sensor trouble starts with a bus picked by habit. I2C is the default for sensor networks because two wires carry many devices, each answering at its own address. SPI is faster and full duplex, but each device needs its own chip-select pin, so pin count grows with device count. UART is simple and point-to-point: one transmitter, one receiver, no shared clock, and no native multi-device support. Analog wiring is the simplest of all and the most fragile: one voltage, one ADC pin, and every bit of noise on the wire lands in the reading.

Bus Wires Devices Speed feel Best fit in this guide
I2C 2 (SDA, SCL) plus power and ground Many, by address 100 kHz standard, 400 kHz fast mode Sensor networks, OLED readouts, IMU and environmental modules
SPI 4 plus one chip-select per device (MOSI, MISO, SCK, CS) One per chip-select pin Fast, MHz range TFT displays, fast sensors, SD cards
UART 2 (TX, RX) plus ground Point-to-point Baud-rate set, commonly 9600 to 115200 GPS-style serial modules, serial ranging output, debug links
Analog 1 signal wire plus power and ground One per ADC pin As fast as the ADC loop Single voltage outputs: light, moisture, level, gas threshold modules
Single-wire digital 1 data wire plus power and ground One per pin, or several on OneWire by address Slow, timing sensitive DHT modules, DS18B20 probes

Board choice is a separate decision and this guide does not repeat it. See Microcontroller Picker: Tables for ESP32, Arduino, Pico for wireless, voltage, size, and camera checks. The wiring rules below apply to all three board families, with the voltage notes in the logic section doing the heavy lifting.

I2C sensor wiring: addresses, pull-ups, and shared-bus checks

I2C uses two open-drain lines, SDA for data and SCL for clock. Devices can only pull a line LOW. Pull-up resistors pull each line back HIGH to the logic rail. Without pull-ups, the bus floats and nothing answers. With pull-ups to the wrong rail, the bus drives the wrong voltage into the low-side pins. With pull-ups stacked on every module plus the board plus a shifter, the total resistance drops too low and the edges distort. The standard starting value in published guidance is 4.7k ohm per line, with lower values such as 2.2k ohm used on faster or longer buses. Many breakout boards include pull-ups already. Count them before adding more: one pair per bus is the target.

Every I2C device answers at an address. Two devices at the same address collide and neither answers reliably. Run an I2C scanner sketch as the first test on any new bus: it lists every address that acknowledges. If a device does not appear, check power, ground, SDA and SCL not swapped, and pull-ups, in that order. If two devices share an address, check whether either offers an address pin, jumper, or solder bridge to move it. The 0.96 Inch OLED Display Module, SSD1306, I2C, 128×64, for Arduino / ESP32 / ESP8266 ($7.49) listing states its I2C address is selectable (0x3C / 0x3D) on the back of the board, which is exactly the escape hatch a shared bus needs. The HiLetgo GY-US42 Ultrasonic Distance Sensor Module, I2C UART PWM, for Pixhawk and APM Flight Controllers ($17.99, regular $21.99) listing states its I2C address can be changed so several modules share one bus.

I2C modules in this guide, all verified live: the GY-521 MPU6050 6-Axis Accelerometer and Gyroscope Module, I2C ($4.99) with 3-axis accelerometer plus 3-axis gyroscope and 16-bit digital output; the VL53L0X Time-of-Flight Laser Distance Sensor Breakout, 2M Range ($4.99); the TCS34725 RGB Color Sensor Module, I2C, with IR Blocking Filter ($8.99, regular $10.99); the GY-271 QMC5883L Triple Axis Compass Magnetometer Module, I2C ($2.99); the BME280 Temperature, Humidity and Barometric Pressure Sensor Module, 5V, I2C and SPI ($8.99, regular $10.99); and the 1 Pack 0.91 Inch I2C IIC OLED Display Module 128×32 Pixel, White ($9.99). Keep I2C wires short. Published guidance notes total bus capacitance near 400 pF as the practical limit, and every wire, breadboard row, and sensor pin adds to it. Long I2C runs fail first at higher clock speeds, so slow the clock for the first test and raise it only after reads are stable.

SPI sensor wiring: chip-select discipline

SPI shares MOSI, MISO, and SCK across devices and gives each device its own chip-select (CS) pin. The controller pulls one CS line LOW to talk to that device and keeps the rest HIGH. The classic wiring fault is a CS pin left floating or shared between two devices: both answer at once and the data corrupts. Give every SPI device its own CS pin, drive unused CS pins HIGH in setup, and keep the shared lines short. SPI has no addressing and no pull-up requirement of the I2C kind, which removes one failure mode and adds the CS discipline requirement in its place.

The TFT displays in this guide are SPI devices. The 2.4 Inch SPI TFT LCD Touch Display Module, 240×320, ILI9341 driver ($20.99, regular $25.99) listing states a 4-wire SPI interface and notes level shifting is needed on 5V boards, because the display logic is 3.3V. The same note appears on the 2.8 Inch SPI TFT LCD Touch Display Module, 240×320, ILI9341 driver ($22.49, regular $26.99) and 3.2 Inch SPI TFT LCD Touch Display Module, 240×320, ILI9341 driver ($25.49, regular $30.99). The BME280 also offers SPI as an alternative to I2C, and its listing advises SPI when several sensors share a bus and I2C address collisions are a concern. That is the right trade: spend a CS pin to remove an address collision.

UART sensor wiring: cross TX and RX, match the baud rate

UART wiring has two classic faults. First, TX to TX and RX to RX: the transmitter must connect to the receiver, so TX on one side goes to RX on the other, and RX goes to TX. Second, mismatched baud rates: both sides must agree on the rate, or the receiver reads garbage. Share ground between the two sides. Without a shared ground reference, the signal voltages float and the link fails or corrupts.

The GY-US42 module ($17.99) is the UART example in this guide: its listing states serial UART at TTL level with a configurable baud rate of 9600 or 115200 bps, continuous or on-request output, and settings saved on the module. Set the baud rate on the module, match it in code, cross TX and RX, share ground, and confirm the signal voltage matches the receiving board. UART has no clock line and no multi-device addressing, so keep it point-to-point. A second UART device needs a second UART port, not a shared pair of wires.

Analog and digital sensor wiring: ADC ranges, thresholds, and noise

Analog modules output a voltage that the board ADC converts to a number. The ADC range depends on the board: published guidance puts the Arduino UNO at 10-bit (0 to 1023) with a 5V reference, the ESP32 at 12-bit, and the Raspberry Pi Pico at 12-bit with a 3.3V reference. The same sensor voltage reads as a different number on each board, so calibration constants do not transfer between board families. Never feed an analog voltage above the ADC reference into the pin. A 5V analog output into a 3.3V ADC pin exceeds the pin rating and clips the reading. Size a divider for the ADC range, or power the module from the board logic rail where the listing range allows it.

Analog and dual-output modules in this guide: the Capacitive Soil Moisture Sensor Module V1.2, 3.3V to 5.5V ($2.99) with analog voltage output of 0 to 3.0V; the Water Level Sensor Module, 3.3V to 5V, Analog Output ($2.99) whose analog output rises with contacted water area; the MQ-135 Air Quality Gas Sensor Module, Analog and Digital Output, 5V ($2.99) with analog and digital threshold outputs and a preheating recommendation; the MQ-3 Alcohol Gas Sensor Module, Analog and Digital Output, 5V ($2.99) with the same dual-output pattern; the Rain Drops Sensor Module with Control Board, LM393, 3.3V to 5V ($2.99); and the TCRT5000 Mini IR Reflective Sensor Module, 3-Pin, Analog + Digital, 10-Pack ($9.99, regular $11.99) with analog plus digital output and an adjustable 2 to 15mm range. The TCRT5000 Infrared Reflective Sensor Module IR Barrier Line Track Photoelectric Switch ($2.29) listing states a digital switch output with 1 to 25mm adjustable detection and an LM393 comparator.

Digital-only modules trade the ADC for a threshold. The LDR Light Sensor Module, 5516 Photoresistor, LM393, 3V to 5V ($2.99) uses an LM393 comparator and a potentiometer to switch its digital output at a set brightness. The KY-003 Hall Effect Magnetic Sensor Module, A3144, 5V ($2.99) outputs a digital signal when a magnet approaches. The SW-420 Vibration Sensor Module, Digital Output, 3.3V to 5V ($2.99) switches its digital output on vibration. The TTP223 Capacitive Touch Sensor Module, Self-Locking and Momentary, 2.5V to 5.5V ($2.99) switches on touch. For all of them, the wiring check is the same: power inside the listing range, ground shared, signal pin at board logic level, and the threshold or mode set on the module before trusting the output. Note the KY-003 listing states 5V operation, so check its digital output level against a 3.3V board input before wiring it directly.

Single-wire digital sensors sit between analog and bus wiring. The DHT modules and the DS18B20 probe use one data wire with timing-sensitive protocols and a pull-up resistor requirement. The DHT22 / AM2302 Digital Temperature & Humidity Sensor Module ($6.99, regular $8.99) and DHT11 Temperature and Humidity Sensor Module, 3.3V to 5V ($2.99) are covered in depth in DHT11 vs DHT22 Temperature Humidity Sensor Choice: Accuracy, Wiring, and Limits. The DS18B20 Waterproof Temperature Sensor Probe, 1M Cable, with Resistor ($2.99) listing states its 4.7k ohm pull-up resistor is included, which removes the pull-up question for that part.

Logic voltage and ground: the two checks that fix most buses

Every bus in this guide crosses the 5V and 3.3V line somewhere. The ELEGOO UNO R3 Microcontroller Board, ATmega328P + ATmega16U2, with USB Cable ($21.99, regular $26.99) and Nano V3.0 Development Board, ATmega328P, CH340G, USB-C, Single ($8.49, regular $10.99) are 5V logic boards. The ESP32 DevKit V1 Development Board, 30-Pin WROOM-32, WiFi + Bluetooth, Dual-Core ($13.99, regular $16.99), ESP32-S2 Mini Development Board, WiFi, 4MB Flash, 2MB PSRAM, USB-C ($7.99, regular $9.99), and RP2040-Zero Microcontroller Board, Pico-Compatible, USB-C, 2MB Flash, 1-Pack / 3-Pack (1-pack $4.99, 3-pack $14.99) are 3.3V logic boards. A 5V signal into a 3.3V input must be shifted. Full method detail, including shifter modules, resistor dividers, and what breaks without shifting, is in Logic Level Shifting 5V to 3.3V: Safe Wiring for ESP32, Arduino, Sensors, and Displays.

Ground is the other half of every bus. Every device on a bus must share one ground reference with the controller. A sensor powered from a separate supply with no ground connection to the board will read erratically or not at all, even when every signal wire is correct. Tie grounds together at one point, keep the ground wire as short as practical, and never route sensor ground through a motor driver ground path. Motor current in a shared ground wire lifts the ground reference and injects noise into every sensor on the bus.

Sensor wiring troubleshooting table

Symptom Check first Check second
I2C device never appears in scanner Power and ground, SDA/SCL not swapped Pull-up resistors present, one pair, correct rail
I2C works with one device, fails with two Address collision; run scanner with each device alone Stacked pull-ups, bus length, clock speed
SPI data corrupt CS pin per device, unused CS driven HIGH Logic voltage match, clock speed, wire length
UART garbage TX/RX crossed, baud rate matched Shared ground, signal voltage at receiver
Analog reading stuck at max Sensor voltage above ADC reference Divider sizing, module supply voltage
Analog reading noisy Wire length, routing near motors Ground path, averaging in code, decoupling
Digital threshold never switches Potentiometer setting on module Supply voltage, signal level at board pin
Single-wire reads fail Pull-up resistor, wire length Read interval, interrupt-heavy code

Sensor wiring checklist

  • Pick the bus by device count, speed, and distance before wiring anything.
  • List every device address on an I2C bus and run a scanner sketch first.
  • Count pull-up resistors. One pair per I2C bus, to the correct rail.
  • Give every SPI device its own CS pin and drive unused CS pins HIGH.
  • Cross UART TX and RX, match baud rates, and share ground.
  • Check analog voltages against the ADC reference before connecting the signal pin.
  • Shift any 5V signal that reaches a 3.3V input. Check the listing for explicit logic statements.
  • Share one ground reference across the whole bus. Keep sensor ground out of motor current paths.
  • Keep bus wires short. Slow the clock for the first test, then raise speed after stable reads.
  • Test one sensor at a time, then add devices one by one and re-run the scanner after each addition.

Products in this guide, checked November 18, 2026

Prices are the effective listing prices checked November 18, 2026. Check the listing before you order. Shipped fast and securely from our secure facility in New York, providing fast, high quality USA shipping.

Browse related categories: Sensor Modules, Robot Sensors, Microcontrollers & Development, Displays & Screens, Electronics.

Frequently asked questions

How many devices can share one I2C bus?

As many as have distinct addresses and fit the bus capacitance budget. In practice, a handful of modules on short wires works well. Run a scanner sketch after each addition, watch for address collisions, and slow the clock if reads turn flaky as devices are added.

Do I need pull-up resistors if my module already has them?

Usually not. Many breakout boards include pull-ups. Count the pairs on the bus: one pair total is the target. Adding external pull-ups on top of module pull-ups lowers the total resistance and can distort the bus.

Can two SPI devices share a chip-select pin?

No. Each SPI device needs its own CS pin. Sharing a CS pin makes both devices answer at once and corrupts the data. Drive unused CS pins HIGH in setup.

Why does my UART link print garbage?

Check TX and RX crossed, baud rates matched, ground shared, and signal voltage at the receiver, in that order. Most UART garbage is one of those four, not a code fault.

Can I use a 5V analog sensor on a 3.3V board?

Only with the voltage handled: power the module from the board logic rail where the listing range allows it, or size a divider so the ADC pin never sees more than its reference. Never feed 5V straight into a 3.3V ADC pin.

Should I use I2C or SPI for a BME280?

Use I2C for simple wiring. Use SPI when several sensors share a bus and I2C address collisions are a concern, per the BME280 listing guidance. SPI costs one CS pin and removes the address question.

Sources