Smart home

BME280 weather station ESP32 ESPHome

Temperature, humidity, pressure and light: BME280 + BH1750 on ESP32-C6 with ESPHome and Home Assistant. Parts list, GPIO wiring, ESPHome YAML and Home Assi

Updated · Emmanuel SAUVAGE

  • LevelIntermediate
  • Time2–3 h
  • Budgetabout $20–40 depending on the seller

Rough estimate, check with your seller: prices vary by shop and period.

Project goal

You will measure temperature, humidity, atmospheric pressure and light level with two small sensors, a BME280 and a BH1750, and send everything to Home Assistant, the software that gathers your connected devices. Both sensors share the same two wires, what is called an “I²C bus”, on an ESP32, a small electronic board with Wi-Fi. The build works indoors and, once sheltered from rain and sun, outdoors.

Why build it

Atmospheric pressure announces changes in the weather, light level can drive shutters and lighting, and the outdoor temperature feeds heating and watering. One ESP32 therefore replaces several off-the-shelf sensors, and every reading arrives in the same place.

Useful terms for this project: ESP32 (small Wi-Fi board) · ESPHome (prepares the board’s program) · GPIO (the board’s pins) · OTA (update without a USB cable)

Prerequisites

  • Home Assistant with ESPHome and Wi-Fi reaching the install spot.
  • A BME280 module (3.3 V, I²C) and a BH1750 module (“GY-302”). Beware of BMP280 boards that look the same: they do not measure humidity.
  • Outdoors: a rain-protected USB supply and a vented shelter such as a Stevenson screen.

Diagrams

Wiring diagram : BME280 + BH1750 weather station
Wiring diagram : BME280 + BH1750 weather station3V3 → BME280 VIN; GND → BME280 GND; GPIO6 → BME280 SDA; GPIO7 → BME280 SCL; 3V3 → BH1750 VCC; GND → BH1750 GND; GPIO6 → BH1750 SDA; GPIO7 → BH1750 SCLESP32-C6 DevKitC-1BME2803V3VINGNDGNDGPIO6SDAGPIO7SCLBH17503V3VCCGNDGNDGPIO6SDAGPIO7SCLPowerGround (GND)Data or signal
Principle diagram : BME280 + BH1750 weather station
Principle diagram : BME280 + BH1750 weather stationBME280 + BH1750 → ESP32-C6 + ESPHome → Home AssistantBME280 + BH1750BME280: temperature, humidity, pressureBH1750: light levelI²C bus: GPIO6 (SDA), GPIO7 (SCL)ESP32-C6 + ESPHomeReads both sensors every 60 s2.4 GHz Wi-Fi + encrypted APIHome Assistant4 entities: °C, %, hPa, lxHistory and automations

Parts list

This ESP32 board is the base for every project in the series. ESPHome also works with other ESP32 boards: the board-choice guide helps you compare them. Which ESP32 board to choose?

ESP32-C6-DevKitC-1

Suggested board

ESP32-C6-DevKitC-1

check with the seller
  • Wi-Fi 6, Bluetooth 5, Zigbee and Thread (at hardware level)
  • Supported by ESPHome (ESP-IDF framework)
  • USB-C for flashing and power

Watch-outs

  • 2.4 GHz Wi-Fi only
  • Use a USB cable that carries data

Main components

ItemQuantityRole and precautions
ESP32-C6-DevKitC-11Control board (see the box above).
BME280 I²C module (address 0x76 or 0x77)1Temperature, humidity and pressure. Check it is a BME280, not a BMP280. Main component: search for « BME280 I2C module pressure temperature humidity » at your seller (affiliate link, check price and availability).
BH1750 module (GY-302)1Measures light from 1 to 65,535 lx, which saturates in direct sun: use a diffuser outdoors. Main component: search for « BME280 I2C module pressure temperature humidity » at your seller (affiliate link, check price and availability).
Radiation shield (printed or commercial Stevenson screen)0–1Essential outdoors: without a shelter, the sun skews temperature by several degrees.

Small parts

ItemQuantityRole and precautions
USB-C data cable1For flashing and power. Charge-only cables do not carry data.
USB 5 V power supply (CE/UKCA-marked charger)1At least 1 A for the board alone; more if peripherals draw power from it.
Dupont jumper wires (male-female and female-female)1One mixed pack covers every prototype.
Breadboard1To test without soldering; replace with a soldered build if you need it permanent.
Soldering iron and solder (optional)1Only for a permanent build; the prototype works without.
Heat-shrink tubing1Insulates solder joints and splices; avoid tape in a permanent build.
Vented plastic or 3D-printed enclosure1Protects the board; leave a cable gland and vents if the sensor measures air.

Amazon links are affiliate links: the site may earn a commission at no extra cost to you.

Step-by-step build

Step 1. Prepare ESPHome and create the device

  1. In Home Assistant, open the ESPHome Device Builder add-on (see the tutorial “Install ESPHome in Home Assistant (Device Builder)”). ESPHome is the software that turns a simple settings file into the program for your ESP32 board, without you having to write any code.
  2. Open “Secrets” (top right): this file keeps your passwords apart, so you can share your configurations without revealing them. Check that wifi_ssid (the name of your Wi-Fi network), wifi_password, api_encryption_key (the key that encrypts the link with Home Assistant), ota_password (for updates without a cable) and ap_password (for the board’s fallback Wi-Fi network) exist, and add any missing line. A valid API key is a long 32-byte string encoded in base64, which you can generate with “openssl rand -base64 32”.
  3. Click “New device”, name it “station-meteo”, pick ESP32-C6, skip the flash for now, then replace the file content with the YAML from this page (“Edit”). YAML is a configuration file written in plain text: it describes, line by line, what the board must do.

What you should see: The file opens in the editor with syntax highlighting and no red underline.

Check: The “Validate” action (⋮ menu) answers “Configuration is valid”.

Step 2. Wire both sensors on the I²C bus

  1. With the USB power unplugged, connect the board’s 3V3 pin to the BME280’s VIN pin and the BH1750’s VCC pin, then a GND pin of the board to the GND pins of both sensors: 3V3 is the 3.3-volt power supply and GND is the ground.
  2. Connect SDA of both modules to GPIO6 and SCL of both modules to GPIO7: SDA carries the data and SCL the rhythm (the clock) of the exchange, two wires shared by both sensors, which the board tells apart by their address. GPIO refers to the metal pins lined up along the edge of the board.
  3. Leave the BH1750 ADDR pin unconnected (address 0x23) and the BME280 SDO pin at GND or free depending on your module (address 0x76).

What you should see: Nothing gets hot; the modules run on 3.3 V.

Check: Every wire is on the right pin: SDA to SDA and SCL to SCL, never crossed.

Step 3. Flash the board and add it to Home Assistant

  1. Connect the board to your computer with the USB-C data cable: “flashing” means writing the program into the board’s memory, and this first write must be done over a cable. The board can already be wired or sitting on the breadboard, but any external peripheral with its own power supply must stay switched off.
  2. In ESPHome click “Install”, then “Plug into this computer” (Chrome or Edge over HTTPS) or “Manual download” and upload the file with ESPHome Web (web.esphome.io). If the port is missing, follow the flashing tutorial.
  3. After the reboot open Settings → Devices & services: the ESPHome device is discovered; click “Configure” and paste the API encryption key.

What you should see: The “Logs” show the Wi-Fi connection and then “Successfully connected to Home Assistant”.

Check: The device appears under Devices & services → ESPHome with its entities; later updates need no cable and go over Wi-Fi (this is OTA, “Over The Air”).

Step 4. Check that both addresses are detected

  1. Install the YAML, the configuration file from this page, on the board: the “scan: true” option lists the I²C addresses found in the log, that is the “number plate” of each sensor on the bus.
  2. Open the device logs in ESPHome.
  3. Look for the lines “Found i2c device at address 0x23” and “0x76” (or 0x77).

What you should see: Both addresses appear in the log.

Check: If 0x77 appears instead of 0x76, fix “address” in the YAML.

Step 5. Check the readings in Home Assistant

  1. In Home Assistant, open the ESPHome device: four readings have been created there, “Temperature”, “Humidity”, “Pressure” and “Illuminance” (the light level).
  2. Compare the temperature with a reliable thermometer in the same room.
  3. Cover the BH1750 with your hand: the value drops.

What you should see: Values are plausible: pressure around 1,000 hPa, indoor humidity between 20 and 80 %.

Check: The temperature gap stays under about 1 °C; otherwise move the sensor away from the warm board.

Step 6. Install outdoors (optional)

  1. Place the BME280 in the ventilated shelter, in the shade and away from a wall exposed to the sun, about 1.5 m above the ground: at that height and out of direct sun, the reading reflects the real air temperature rather than that of a hot wall.
  2. Put the BH1750 in open air under a translucent diffuser, sensor facing up.
  3. Protect the board and supply in a waterproof enclosure; let only the sensor wires leave it.

What you should see: Outdoor temperature follows a nearby reference station with a small offset.

Check: Check for condensation inside the enclosure after a cold night.

ESPHome code (YAML)

YAML is a configuration file written in plain text: it tells ESPHome what the board must do. Paste this one into ESPHome after creating the device. It targets an ESP32-C6 board; values to personalise are marked with “CHANGE” comments.

esphome:
  name: station-meteo
  friendly_name: Weather station

esp32:
  board: esp32-c6-devkitc-1   # XIAO ESP32C6: use board: seeed_xiao_esp32c6
  framework:
    type: esp-idf             # required for ESP32-C6

logger:                       # serial logs, also visible over Wi-Fi

api:
  encryption:
    key: !secret api_encryption_key

ota:
  - platform: esphome
    password: !secret ota_password

wifi:
  ssid: !secret wifi_ssid       # 2.4 GHz network only
  password: !secret wifi_password
  ap:                           # fallback hotspot if the Wi-Fi is unreachable
    ssid: "station-meteo fallback"
    password: !secret ap_password

captive_portal:

i2c:
  sda: GPIO6                     # I2C bus shared by both sensors
  scl: GPIO7
  scan: true                     # lists detected addresses in the log
  frequency: 100kHz

sensor:
  - platform: bme280_i2c
    address: 0x76                # 0x77 if the SDO pin is tied to 3.3 V
    update_interval: 60s
    temperature:
      name: "Temperature"
      oversampling: 16x
    pressure:
      name: "Pressure"
    humidity:
      name: "Humidity"

  - platform: bh1750
    name: "Illuminance"
    address: 0x23                # 0x5C if the ADDR pin is tied to 3.3 V
    update_interval: 60s

  - platform: wifi_signal
    name: "WiFi signal"
    update_interval: 120s
    entity_category: diagnostic

YAML comments are in English, as in the ESPHome documentation. This code has not been run on your hardware: use “Validate” before flashing and adjust pins and names.

Home Assistant integration

  • The four entities appear as one device; Home Assistant keeps their history and plots them on the dashboard (history card or gauge).
  • Measured pressure is absolute, at your altitude. To compare with a forecast, convert it to sea level (roughly 12 hPa more per 100 m of altitude near sea level).
  • Useful automations: close blinds when light passes a threshold, or start ventilation when indoor humidity exceeds 65 %.

Common problems and troubleshooting

SymptomFix
No address detected in the logSDA and SCL are swapped, a module is not powered or a pin solder joint is bad. Check the wires one by one.
Humidity at 0 % or missingYou probably have a BMP280 (no humidity). Check the reference printed on the chip; you need a BME280.
Temperature several degrees too highThe sensor is too close to the board or in direct sun. Move it away with a longer wire and shelter it.
Light stuck at 65,535The BH1750 is saturated in direct sun. Add a translucent diffuser in front of the sensor.

FAQ

Can I add more sensors on the same bus?

Yes, as long as addresses differ; the I²C bus can host several modules on the same two wires.

Do I need a BME280 or a BMP280?

A BME280 if you want humidity; the BMP280 only measures temperature and pressure.

Are the sensors accurate?

Values are good enough for home automation; for a reference value compare with a calibrated instrument, as accuracy depends on the module and its self-heating.

Related tutorials

These step-by-step guides explain the gestures common to every project in the series.

Other ESP32 projects

Sources and documentation

Cette page vous a-t-elle été utile ?

Have a question about this guide or need advice? Ask us here

Torn between two models or stuck on a build? Drop us a line and we will get back to you by email.