Building an I2C Environmental Sensor Module
Overview
This tutorial will walk you through building an I2C environmental sensor module using tscircuit. The module features a BME280 sensor that measures temperature, humidity, and atmospheric pressure, connected via I2C to any microcontroller.
Objectives
Building an I2C environmental sensor module teaches fundamental concepts:
- I2C Communication - Understanding the two-wire serial protocol
- Pull-up Resistors - Why I2C requires pull-ups and how to size them
- Power Filtering - Using decoupling capacitors for stable operation
- Sensor Integration - Connecting precision sensors to microcontrollers
Practical Applications
- Weather Stations - Monitor local atmospheric conditions
- Indoor Air Quality - Track humidity and temperature for comfort
- Altitude Estimation - Use pressure readings for elevation data
- HVAC Monitoring - Integration with climate control systems
Bill of Materials
| Component | Value | Footprint | Purpose |
|---|---|---|---|
| BME280 | - | LGA-8 (2.5x2.5mm) | Environmental sensor |
| R1, R2 | 4.7kΩ | 0402 | I2C pull-up resistors |
| C1 | 100nF | 0402 | Power decoupling |
| J1 | 4-pin | 2.54mm pitch | External connection |
Understanding the BME280
The BME280 is a precision environmental sensor that measures:
- Temperature: -40°C to +85°C with ±1°C accuracy
- Humidity: 0-100% RH with ±3% accuracy
- Pressure: 300-1100 hPa with ±1 hPa accuracy
The sensor communicates via I2C (or SPI) and operates at 1.8-3.6V.
Circuit Design
Step 1: BME280 Sensor Connections
The BME280 in I2C mode requires these connections:
- VDD/VDDIO: Power supply (3.3V recommended)
- GND: Ground connections
- SDI: I2C data (SDA)
- SCK: I2C clock (SCL)
- CSB: Tie HIGH for I2C mode (LOW enables SPI)
- SDO: I2C address select (GND=0x76, VDD=0x77)
Step 2: I2C Pull-up Resistors
I2C is an open-drain bus requiring pull-up resistors. For 3.3V operation with standard-mode I2C (100kHz):
Pull-up calculation:
- Bus capacitance: ~10pF (short traces)
- Rise time requirement: less than 1µs
- Typical value: 4.7kΩ works for most applications
Step 3: Power Decoupling
A 100nF ceramic capacitor close to the sensor filters high-frequency noise:
Step 4: Complete Schematic
PCB Layout
Layout considerations for this sensor module:
- Place decoupling capacitor close to sensor VDD pins
- Keep I2C traces short and parallel
- Avoid routing noisy signals near the sensor
- Provide adequate ground plane for stability
Microcontroller Integration
Connect the module to any microcontroller with I2C support:
| Module Pin | Microcontroller | Function |
|---|---|---|
| VCC | 3.3V | Power supply |
| GND | GND | Ground |
| SDA | I2C SDA | Data line |
| SCL | I2C SCL | Clock line |
Arduino Example
#include <Wire.h>
#include <Adafruit_BME280.h>
Adafruit_BME280 bme;
void setup() {
Serial.begin(9600);
Wire.begin();
if (!bme.begin(0x76)) {
Serial.println("BME280 not found!");
while (1);
}
}
void loop() {
Serial.print("Temperature: ");
Serial.print(bme.readTemperature());
Serial.println(" °C");
Serial.print("Humidity: ");
Serial.print(bme.readHumidity());
Serial.println(" %");
Serial.print("Pressure: ");
Serial.print(bme.readPressure() / 100.0F);
Serial.println(" hPa");
delay(2000);
}
Ordering the PCB
Export the fabrication files and upload to JLCPCB. See Ordering Prototypes for detailed instructions.