From f42bbed1152a64a42c5553021cb6c7c981aa692b Mon Sep 17 00:00:00 2001 From: Vishal Kumar Singh Date: Sat, 16 May 2026 17:27:21 +0530 Subject: [PATCH] =?UTF-8?q?=EF=BB=BFAdd=20I2C=20Environmental=20Sensor=20M?= =?UTF-8?q?odule=20tutorial?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BME280-based environmental sensor module tutorial covering temperature, humidity, and pressure monitoring. Includes I2C pull-up resistor calculations, decoupling capacitor placement, and Arduino integration example. Fixes #602 --- .../building-i2c-environmental-sensor.mdx | 361 ++++++++++++++++++ 1 file changed, 361 insertions(+) create mode 100644 docs/tutorials/building-i2c-environmental-sensor.mdx diff --git a/docs/tutorials/building-i2c-environmental-sensor.mdx b/docs/tutorials/building-i2c-environmental-sensor.mdx new file mode 100644 index 0000000..0d7811d --- /dev/null +++ b/docs/tutorials/building-i2c-environmental-sensor.mdx @@ -0,0 +1,361 @@ +--- +title: Building an I2C Environmental Sensor Module +description: Learn how to build an I2C environmental sensor module with a BME280 sensor for temperature, humidity, and pressure monitoring using tscircuit. +--- + +## 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. + +import TscircuitIframe from "@site/src/components/TscircuitIframe" +import CircuitPreview from "@site/src/components/CircuitPreview" + + ( + + {/* BME280 Environmental Sensor */} + + + {/* I2C Pull-up Resistors */} + + + + {/* Decoupling Capacitor */} + + + {/* Pin Header for Connection */} + + + {/* Power connections */} + + + + + + + {/* I2C connections with pull-ups */} + + + + + + + + {/* Decoupling capacitor */} + + + + {/* Pin header connections */} + + + + + +) +`} /> + +## 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: `<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 + +```cpp +#include +#include + +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](/building-electronics/ordering-prototypes) for detailed instructions.