ESP32 Per Sensor: Stop Buying New Boards
In this article
You don't need a new ESP32 for every sensor. A single ESP32 can handle multiple sensors through its GPIO pins, I2C, SPI, or 1-Wire buses, and for many projects, one board is enough to read 5–10 sensors simultaneously. The idea that each sensor needs its own microcontroller is a common misconception that leads to unnecessary cost and wiring complexity.
Why This Misconception Exists
The confusion often comes from beginner tutorials that pair one sensor with one board. When you follow a guide for a DHT22 temperature sensor, it shows a single ESP32 connected to that one sensor. It's easy to assume that's the only way to do it. In reality, those tutorials are simplified for clarity, not because the hardware requires it. Another source of confusion is the ESP32's pin limitations—some pins are input-only, some are used for flash memory, and others are strapping pins that affect boot mode. This makes it look like you have fewer usable pins than you actually do, pushing people to buy another board instead of learning which pins are free.
How One ESP32 Handles Multiple Sensors
The ESP32 has 34 GPIO pins, though not all are freely usable. After accounting for flash, strapping pins, and the default UART, you typically have around 20–25 usable pins for sensors and actuators. Here's how you can connect many sensors without extra boards:
- I2C bus: Uses two pins (SDA, SCL) and supports up to 127 devices with unique addresses. Most digital sensors—BME280, MPU6050, OLED displays—use I2C.
- SPI bus: Uses four pins (MOSI, MISO, SCK, CS) and can handle many devices, each with its own chip-select pin. Great for high-speed sensors like SD cards or displays.
- 1-Wire bus: Uses a single pin for multiple DS18B20 temperature sensors. You can put dozens on one wire, each with a unique ROM address.
- Analog inputs: The ESP32 has two ADCs with multiple channels, so you can read several analog sensors (like LDRs or potentiometers) on separate pins.
- Digital pins: Simple sensors like PIR motion detectors or reed switches just need one GPIO each.
For example, a weather station could use one ESP32 to read a BME280 (I2C), a DS18B20 (1-Wire), a rain gauge (digital input), and an anemometer (digital input with interrupt)—all on one board.
When You Actually Need a Second ESP32
There are legitimate reasons to add another board, but they're about architecture, not sensor count:
- Distance: If sensors are spread across a building, it's often easier to run a short wire to a nearby ESP32 and send data over Wi-Fi than to run long analog wires that pick up noise.
- Isolation: A sensor that might fail (e.g., water sensor) shouldn't take down your main controller. A separate board can handle it and report status.
- Processing load: If you're doing heavy computation like video processing or FFT on audio, a second ESP32 can offload sensor polling.
- Power budget: In battery-powered projects, a dedicated ESP32 in deep sleep can wake only to read a sensor, while the main board stays off.
In most home automation or hobby projects, none of these apply—you're better off with one board and a multiplexer if you run out of pins.
How to Choose Between One or Multiple Boards
Ask yourself these questions before buying another ESP32:
- How many sensors do I have? Count the total. If it's under 15, one board likely suffices.
- Do my sensors use different buses? If they're all I2C, you only need two pins. If they're all analog, you may need to check the ADC channels.
- Are the sensors physically close to the board? If yes, one board is fine. If no, consider a second board near the remote cluster.
- Do I need real-time response for each sensor? If you're polling at 1 Hz, one board can handle dozens. If you need microsecond timing, you might need dedicated pins.
- Do I have enough power? Each ESP32 draws about 100–200 mA when active. One board is cheaper and simpler to power.
If you run out of pins on one board, consider an I2C multiplexer (like TCA9548A) or a shift register instead of a second ESP32. These cost under $2 and expand your I/O without adding a whole microcontroller.
Common Problems and How to Avoid Them
When connecting multiple sensors to one ESP32, you'll hit a few typical issues:
- I2C address conflicts: Two sensors with the same address (e.g., two BMP280s) won't work on the same bus. Fix: use an I2C multiplexer or change the address jumper if the sensor supports it.
- Pin conflicts: Some pins are used by the ESP32's flash (GPIO6-11) and shouldn't be used for sensors. Also, GPIO0, GPIO2, GPIO15 are strapping pins—they affect boot mode. Avoid them or be careful.
- Analog noise: Long wires to analog sensors pick up interference. Keep wires short and twisted, or use a digital sensor instead.
- Power brownouts: Running many sensors from the ESP32's 3.3V pin can cause voltage drops. Use a separate 3.3V regulator or power sensors from 5V if they support it.
- Pull-up resistors: I2C and 1-Wire need pull-ups. Many breakout boards have them, but if you're wiring raw sensors, add 4.7kΩ resistors to VCC.
If you follow these guidelines, you'll rarely need a second board.
Cost and Environmental Impact
An ESP32 development board costs around $5–10. Buying one for each sensor means you're spending $5–10 per sensor, plus the cost of a power supply and enclosure for each. For a 10-sensor project, that's $50–100 just for microcontrollers. In contrast, a single ESP32 plus a few multiplexers and pull-up resistors costs under $15. You also save on wiring, soldering, and troubleshooting. Environmentally, you're reducing e-waste—each board contains a PCB, chips, and connectors that require resources to manufacture. Using fewer boards is greener and cheaper, with no performance loss for most projects.
Alternatives to Buying Another ESP32
If you genuinely need more inputs, consider these before buying a second board:
- I2C multiplexer (TCA9548A): Gives you 8 I2C buses, each with its own address range. Perfect for many identical sensors.
- Shift register (74HC595): Adds 8 digital outputs using only 3 pins. Useful for LEDs or relays, not for reading sensors.
- Analog multiplexer (CD74HC4067): Expands one analog pin to 16 analog inputs. Great for multiple analog sensors.
- ESP32 with more pins: The ESP32-WROVER has more GPIOs, or you can use an ESP32-S3 which has more ADC channels.
- Use a different microcontroller: If you need many analog inputs, an Arduino Mega (54 digital I/O, 16 analog) might be cheaper than multiple ESP32s.
These options keep your project simple and cost-effective while still using one main controller.
Frequently Asked Questions
Can I connect 10 sensors to one ESP32?
Yes, if they use different buses or have unique addresses. For example, 10 DS18B20 temperature sensors can all go on one 1-Wire pin. For I2C sensors, you'd need a multiplexer if they share addresses, but many have configurable address pins.
How many I2C sensors can I connect to an ESP32?
Technically up to 127 on one bus, but in practice, the capacitance of long wires and the pull-up strength limit you to about 10–20 devices. Use a multiplexer to add more buses if needed.
Do I need a separate ESP32 for each sensor if I want to read them at the same time?
No. The ESP32 can read multiple sensors in the same loop, and even on different cores using FreeRTOS. You can read them sequentially or in parallel tasks, depending on your code.
What's the easiest way to add more sensors without a new board?
Use an I2C multiplexer like the TCA9548A. It costs about $2, uses only two pins, and gives you 8 separate I2C buses. You can then connect up to 8 sensors with the same address on each bus.
Is it bad to use all GPIO pins on an ESP32?
Not necessarily, but avoid GPIO6-11 (flash), GPIO0, GPIO2, GPIO15 (strapping), and be careful with GPIO34-39 (input-only). If you need more, use a multiplexer.
Can I use one ESP32 for sensors in different rooms?
Yes, if you run wires. But for long distances, it's often easier to place a second ESP32 near the remote sensors and have it send data over Wi-Fi to the main board. That's a valid reason to buy another.