Sensor Interfaces: the short answer
Common interfaces include analog voltage, I²C, SPI, and UART. Wiring, bus addressing, pull-ups and electrical levels must be validated. Example: Plan pins by interface first: ADC pins for analog, any GPIO for digital, and one shared pair for all I²C parts.
- Level
- Beginner
- Time
- About 5 min
- Topic
- Sensors and actuators
Recognise analog, digital, I2C and SPI sensor outputs.
Common interfaces include analog voltage, I²C, SPI, and UART. Wiring, bus addressing, pull-ups and electrical levels must be validated.
An analog interface transfers a quantity as voltage or current; digital buses transfer encoded information. A sensor breakout may include its own regulator or level shifters, or it may expose raw chip pins with stricter limits.
For an I²C breakout, identify supply limits, SDA/SCL electrical levels, addressing and required pull-ups. A successful library call is not proof the interface is within its electrical ratings.
Four ways a sensor talks
Analog sensors, such as a thermistor divider or a light-dependent resistor, give a voltage that changes with the quantity. You read it with the ADC, and the quality of the reading depends on your reference voltage, wiring and noise. Digital sensors, like a PIR motion sensor or a limit switch, give just high or low on one pin.
Bus sensors send numbers over a few wires. I²C uses two shared lines (SDA and SCL) and gives each device an address. SPI uses four lines (clock, data in, data out and one chip-select per device), and runs faster. UART sends data in framed bytes at an agreed baud rate. Some sensors, like the DHT22, use their own one-wire timing that a library handles.
Reading an analog sensor properly
A 12-bit ADC at 3.3 V resolves about 0.8 mV a step, but real readings on an ESP32 are noisy and bend near the ends of the range. Average 8 to 16 samples, keep analog wires short and away from motors and Wi-Fi antennas, add a 100 nF capacitor from the input to ground, and avoid the ADC2 pins when Wi-Fi is on, since they are used by the radio.
Sensors that behave as variable resistors (thermistors, LDRs) need a fixed resistor to turn resistance into a voltage. Choose the fixed resistor close to the sensor's resistance in the middle of the range you care about, so the output moves as much as possible.
I²C in practice
Devices sit on the same two wires and answer to a 7-bit address. A BME280 uses 0x76 or 0x77, an SSD1306 OLED 0x3C or 0x3D, an MPU6050 0x68 or 0x69. Two devices with the same address clash, and some breakouts have a jumper to change it.
Both lines need pull-up resistors to the supply, usually 4.7 kΩ at 100 kHz. Most breakout boards already include them. Many boards on one bus mean many pull-ups in parallel, and the total can get low enough to overload the pins. An I²C scanner sketch that lists every address it sees is the first tool to use when a sensor doesn't respond.
Voltage and breakout boards
A bare sensor chip often has a narrow supply window, for example 1.7 to 3.6 V. A breakout board may add a regulator and level shifters so you can use 5 V, or may not. Read the board's listing, not just the chip's datasheet, and note the pin names, which differ between makers (VCC, VIN, 3V3).
A library call that works doesn't prove the wiring is within ratings. A 3.3 V-only chip can respond for days on 5 V signals and then fail.
- Skipping the I²C scan and guessing the address.
- Powering a sensor from 5 V and connecting its output to a 3.3 V pin without checking the board.
- Reading an analog sensor once and trusting the number instead of averaging.
Which interface does each sensor use?
- LDR with a resistor: analog, one ADC pin.
- PIR motion: digital, one GPIO HIGH or LOW.
- BME280: I²C, shares SDA and SCL with other parts.
- DHT22: its own one-wire protocol on one GPIO.
Result. Plan pins by interface first: ADC pins for analog, any GPIO for digital, and one shared pair for all I²C parts.
3 quick questions
An LDR with a fixed resistor gives a changing voltage. Which pin type reads it?
A PIR motion sensor output is…
You add a second I²C sensor. How many extra data pins do you need?
