# Read BH1750 Sensor

**URL:** <https://discourse.nodered.org/t/read-bh1750-sensor/3378>\
**Category:** Hardware\
**Created:** [23 September 2018 14:00 UTC](https://discourse.nodered.org/t/read-bh1750-sensor/3378 "2018-09-23T14:00:32Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![b35b5dad43ea282b65d0](https://avatars.discourse-cdn.com/v4/letter/b/c68b51/32.png) [@b35b5dad43ea282b65d0](https://discourse.nodered.org/u/b35b5dad43ea282b65d0)\
**Post date:** [23 September 2018 14:00 UTC](https://discourse.nodered.org/t/read-bh1750-sensor/3378/1 "2018-09-23T14:00:32Z")

</div>

Hi

You know a way how to read the sensor data from the BH1750 sensor?

---

<div class="post-metadata">

**Author:** ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)\
**Post date:** [23 September 2018 16:08 UTC](https://discourse.nodered.org/t/read-bh1750-sensor/3378/2 "2018-09-23T16:08:34Z")

</div>

One simple way is to use an ESP8266:

[https://www.letscontrolit.com/wiki/index.php/BH1750](https://www.letscontrolit.com/wiki/index.php/BH1750)

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [23 September 2018 16:44 UTC](https://discourse.nodered.org/t/read-bh1750-sensor/3378/3 "2018-09-23T16:44:28Z")

</div>

I have a working BH1750 on a raspberry pi using the following:  
Node **node-red-contrib-i2c**

![Screenshot_2018-09-23_17-33-24](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/a/a871d38a4c4fd7bae9a47ccd0a405b6853dc5350.png)  
35 is the address of the sensor, 16 is the command to get the lux value.

Followed by a change node:  
 ![Screenshot_2018-09-23_17-34-40](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/68a8484a5cc0f05bc25459ad37bb466f9b621e08.png)

The JSONata expression is:  
 ![Screenshot_2018-09-23_17-35-39](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/4/4b8f9b734fd0f1f1a6e826f10205e13f9d6375a8.png)

Which is converting the two byte value returned by the i2c node to a decimal value and dividing the result by 1.2 as described in the datasheet (the sensor returns values that are typically 20% too high), and rounding to 2 decimal places.

msg.lux contains the result.

---

<div class="post-metadata">

**Author:** ![tarbax](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tarbax/32/3212_2.png) [@tarbax](https://discourse.nodered.org/u/tarbax)\
**Post date:** [19 October 2018 20:00 UTC](https://discourse.nodered.org/t/read-bh1750-sensor/3378/4 "2018-10-19T20:00:02Z")

</div>

Thanks for sharing my output is sadly : [9,213]  
i did exactly like you said. what did i do wrong ?

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/a/ac89cf07fbb9194cbeb4ffcc67d13bddfb1c5839.png)  
JSONata:  
`$round((payload."1" + (265 * payload."0"))/1.2,2)`

my output:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/c/c85f74b791833e64e6f43e6ac5ae11971e9fa43c.jpeg)

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [19 October 2018 20:31 UTC](https://discourse.nodered.org/t/read-bh1750-sensor/3378/5 "2018-10-19T20:31:33Z")

</div>

you are setting msg.lux to be the value, but your debug is set to display msg.payload

Double click on the debug to change it to display the correct part of the message object or the entire message

---

<div class="post-metadata">

**Author:** ![tarbax](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tarbax/32/3212_2.png) [@tarbax](https://discourse.nodered.org/u/tarbax)\
**Post date:** [19 October 2018 20:38 UTC](https://discourse.nodered.org/t/read-bh1750-sensor/3378/6 "2018-10-19T20:38:04Z")

</div>

oh lol i am just getting started with node-red and overlooked that part 😅

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [19 October 2018 20:39 UTC](https://discourse.nodered.org/t/read-bh1750-sensor/3378/7 "2018-10-19T20:39:37Z")

</div>

Worth reading  
[https://nodered.org/docs/user-guide/messages](https://nodered.org/docs/user-guide/messages) for some tips on how to use debug nodes to help navigate the message object

---

<div class="post-metadata">

**Author:** ![smarties](https://avatars.discourse-cdn.com/v4/letter/s/e5b9ba/32.png) [@smarties](https://discourse.nodered.org/u/smarties)\
**Post date:** [6 November 2018 20:49 UTC](https://discourse.nodered.org/t/read-bh1750-sensor/3378/8 "2018-11-06T20:49:57Z")

</div>

Hello,  
I hope anybody can help me.  
I use node-Red over ioBroker and I want to use the BH1750 sensor connected on my raspberry. I've followed the instructions from ghayne but unfortunately I don't get any message from the sensor. Not from "I2C in" and not from "I2C Scan". The sensor works fine with a phyton script.  
I connected the sensor like the description on the following site [www.raspberrypi-spy.co.uk](https://www.raspberrypi-spy.co.uk/2015/03/bh1750fvi-i2c-digital-light-intensity-sensor/)  
Here is also a picture from the flow. Any tips?

 ![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/ba6a08d38f3e3a1a53d014a3f3e116f96e4d0923.jpeg)

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [6 November 2018 21:00 UTC](https://discourse.nodered.org/t/read-bh1750-sensor/3378/9 "2018-11-06T21:00:47Z")

</div>

You need an inject mode before the i2c node!

```auto
[{"id":"6e0dfdec.2f6c74","type":"inject","z":"9dcf23c2.6c9ca","name":"","topic":"","payload":"","payloadType":"date","repeat":"60","crontab":"","once":false,"x":110,"y":60,"wires":[["f9655f1b.ef3c1"]]},{"id":"f9655f1b.ef3c1","type":"i2c in","z":"9dcf23c2.6c9ca","name":"Read BH1750","address":"35","command":"16","count":"2","x":300,"y":20,"wires":[["69f7be89.9e122"]]},{"id":"69f7be89.9e122","type":"change","z":"9dcf23c2.6c9ca","name":"Lux","rules":[{"t":"set","p":"lux","pt":"msg","to":"$round((payload.\"1\" + (256 * payload.\"0\"))/1.2,2)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":60,"wires":[["5714a6d3.d06238","a7aae33a.77a05"]]}]

```

---

<div class="post-metadata">

**Author:** ![smarties](https://avatars.discourse-cdn.com/v4/letter/s/e5b9ba/32.png) [@smarties](https://discourse.nodered.org/u/smarties)\
**Post date:** [6 November 2018 21:37 UTC](https://discourse.nodered.org/t/read-bh1750-sensor/3378/10 "2018-11-06T21:37:00Z")

</div>

Hello ghayne, thank you so much, now all is working fine.Have a nice day!

---

<div class="post-metadata">

**Author:** ![Nodi.Rubrum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodi.rubrum/32/107482_2.png) [@Nodi.Rubrum](https://discourse.nodered.org/u/Nodi.Rubrum)\
**Post date:** [20 July 2020 04:52 UTC](https://discourse.nodered.org/t/read-bh1750-sensor/3378/11 "2020-07-20T04:52:22Z")

</div>

Really nice example of how to use i2c in node. I wish there were more like this!

---

<div class="post-metadata">

**Author:** ![markus2121212](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@markus2121212](https://discourse.nodered.org/u/markus2121212)\
**Post date:** [12 November 2021 00:18 UTC](https://discourse.nodered.org/t/read-bh1750-sensor/3378/12 "2021-11-12T00:18:15Z")

</div>

Hi, can You help me with MCP9808 sensor? I found address of the sensor but I dont know where I can get this command, and then how to calculate results. I did BH1750 sam as You and its working.

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [12 November 2021 09:37 UTC](https://discourse.nodered.org/t/read-bh1750-sensor/3378/13 "2021-11-12T09:37:20Z")

</div>

There is a node for that sensor here:

> **[node-red-contrib-brads-i2c-nodes](https://flows.nodered.org/node/node-red-contrib-brads-i2c-nodes)**
>
> Brad's Node RED i2c sensor modules.

---

<div class="post-metadata">

**Author:** ![markus2121212](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@markus2121212](https://discourse.nodered.org/u/markus2121212)\
**Post date:** [12 November 2021 12:54 UTC](https://discourse.nodered.org/t/read-bh1750-sensor/3378/15 "2021-11-12T12:54:36Z")

</div>

> [@markus2121212](#):
>
> I saw this but I cant install this. But the main problem is that I have 3 more sensors on I2C. I just want to know from where in documentation I can get this command address so I can connect them all through i2c node

I saw this but I cant install this. But the main problem is that I have 3 more sensors on I2C. I just want to know from where in documentation I can get this command address so I can connect them all through i2c node

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [12 November 2021 13:32 UTC](https://discourse.nodered.org/t/read-bh1750-sensor/3378/16 "2021-11-12T13:32:11Z")

</div>

node-red-contrib-i2c includes an i2c-scan node to find device addresses

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [12 November 2021 17:31 UTC](https://discourse.nodered.org/t/read-bh1750-sensor/3378/17 "2021-11-12T17:31:19Z")

</div>

> [@markus2121212](#):
>
> I just want to know from where in documentation I can get this command address so I can connect them all through i2c node

Look at the datasheet for the MCP9808.

---

<div class="post-metadata">

**Author:** ![markus2121212](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@markus2121212](https://discourse.nodered.org/u/markus2121212)\
**Post date:** [12 November 2021 18:18 UTC](https://discourse.nodered.org/t/read-bh1750-sensor/3378/18 "2021-11-12T18:18:49Z")

</div>

I looked but I don't know where to look for a "command".  
I have address of the device  
Here it is how it looks now:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/1/d18b60dafe7b834bcbc8bdc7fd3b600e5aa1fd12.png)

datasheet for MCP9808:  
[https://botland.com.pl/index.php?controller=attachment&id\_attachment=981](https://botland.com.pl/index.php?controller=attachment&id_attachment=981)
