DIY ESP32 with BH1750 / GY-302 sensor

I want to build some lux sensors to use in Home Assistant, but can’t find any good tutorial to do so. All I find is very old information or Ardino only.
Had anyone build a Lux sensor with a ESP32 board and a BH1750 lux sensor and know the steps? I find different explanations about wiring and also it seems how to add it to esphome and edit add/edit a yaml seems to have changed since all tutorials I can find

Have you tried reading the Esphome docs.

1 Like

Yes I did, but the information there is very minimal and and doesn’t really make anything clear to me how to even start

Did you worked with esphome before? If not the getting started guide might help :point_down:

yes i have a few bluetooth proxies. All i want now is this sensor and i am sure i am not the only an first one that want to build this module. That’s why I asked for a more specific tutorial instead of going through the whole manual

Did you use the ready made projects/builds for this? :thinking:

The getting started looks the thing you are looking for, it explains in a short way how building esphome devices work. The docs also shows you how to add components/features (like the bh1750 already linked for you) :raised_hands:

Yes I did use the pre made projects. I was just hoping someone had already build this one and there was a tutorial on all the wiring and how the yaml code works in the latest versions of HA. instead of going to the full manual

That information should all be linked in the thread already. :point_up:

The getting started guide is a rather short read which gets you (with no/little espHome knowledge) up to speed in no time - if you want. :person_shrugging:

Instead of posting here asking for a tutorial that fits your need you probably could have read the getting started guide already two times :wink:

And if you cant work out that sda needs to connect to sda, scl to scl etc, you probably are not going to get far.

I was hoping the HA community was a little more helpful instead of belittling to people who just started their HA journey

# i2c configuration entry for ESP8266
i2c:
  sda: 4
  scl: 5
  scan: true
  id: bus_a

# Example configuration entry
sensor:
  - platform: bme280_i2c
    i2c_id: bus_a
    temperature:
      name: "sensor-bme280-2-temp"
      oversampling: 16x
    pressure:
      name: "sensor-bme280-2-pres"
    humidity:
      name: "sensor-bme280-2-humi"
    address: 0x76
    update_interval: 60s  
  - platform: bh1750
    i2c_id: bus_a
    name: "sensor-bh1750-2-lux"
    address: 0x23
    update_interval: 60s    

This is the relevant yaml for my setup with a ESP8266.
It also depends on the type of breakout board, whether it has I2C termination implemented.
Do some research on I2C termination.

Things you need to know, not all esp32 boards are the same so we can’t supply a wiring diagram which will work for sure. The code you need to add to the yaml was linked, how to setup an esp32 from scratch was linked, short of coming over and plugging it in for you what more do you need.
I could take it you step by step through it (like the docs do) but there is no point in rewriting something that is already written.

We are not belittling you we are encouraging you to learn, there is a difference. You asked a very poor question in the first place which does not help, you suppllied no information about the type of esp32, or what you had already tried, but still we linked to all the info you needed as we know its sometimes difficult to find.

Good luck

1 Like

what, for instance, i can not find is how to start ESPHome seems to have changed since most of the online documentation. For example, there seems to have been added API key. I think I need to do the following, but do is this true:

  • wire the module to the esp32
  • connect the esp32 via USB to my computer
  • run epshome builder
  • click + new device
  • follow the initial setup steps
  • add the specific code for the module to the yaml

is it then automatically found by my HA as a sensor?

Yep pretty much, when asked click plugged into computer as the connection option. Then once complete click edit and add you extra bits of code at the bottom. click save and then install and wait. Then your device will show up in intergrations or / and notifications just follow the steps, it will ask for an API code this can be found in esphome under the 3 dot menu.

I still have some questions about the i2c and addresses. So I have a ESP32-Wroom. According to the I²C Bus manual SDA should be default connected to 21 and scl to 22

So I added to the yaml:

i2c:
  sda: GPIO21
  scl: GPIO22
  scan: true
  id: bus_a  

next is the sensor itself. When I look at the example above it says address: 0x23. Is this then 0x21 in my case? so:

sensor:
  - platform: bh1750
    name: "BH1750 Illuminance"
    address: 0x21
    update_interval: 60s

No it should be 0x23, what made you think it should be 0x21? If I remember correctly the address can be changed by pulling a pin to low, but in standard config they are always 0x23. But that is pretty much the code you need. If you read the logs it should detect the BH1750 and give its address.

The Home Assistant official documentation on the I²C Bus says it’s pin 21. That’s why I thought it was it. MAybe this shows a little bit how confusing things are when you just start with HA and the manuals arent really that transparant

I thought it might be that. Is it working?

That’s the default for SDA on Wroom32. You can use other pins as well, but I wouldn’t do it for no reason.
Address 0x23 has nothing to do with pins used. It’s for identifying the sensor. I2C is a bus, you can have many devices connected to same pins.

Hence we suggested you the getting started guide :wink: