CJMCU-101 Light Analog Light Intensity Sensor

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Copitano
Normal user
Posts: 17
Joined: 18 Oct 2019, 21:11
Location: NL

CJMCU-101 Light Analog Light Intensity Sensor

#1 Post by Copitano » 06 Jul 2021, 15:40

I have an OPT101 sensor coupled to the analog pin (A0) of a Wemos D1 mini. On the Wemos I have ESP_Easy_mega_20210503_normal_ESP8266_4M1M running.
I also get values ​​on the Analog input - internal. If I have understood correctly, the Wemos itself has built-in resistors so that the A0 pin can handle 3.3 volts. The sensor is powered with 3.3 volts from the Wemos D1. As soon as I cover the sensor the value goes (as might be expected almost) to 0. As soon as I remove the cover it goes in in normal daylight to value 840. I then measure 2.5 volts on the data line to the Wemos. That level is already reached at about 250 lux (measured with an app on my iPhone). If I place the LED of my iPhone over the sensor and turn it on, the value of 840 does not increase any further. That also seems to be the maximum. I already tried putting a 10k potentiometer between pins 1M + OUT and the A0 of the Wemos. However, that makes very little difference. (the voltage only drops to 2.43 volts) In this setup, the maximum seems to be reached at about 250 Lux. Because I want to use the sensor to have an indication of the global radiation of the sun on my solar panels (full sun up to 100,000 lux), this will not work yet. The maximum should then only be reached at 100,000 lux.
How could I fix that. I'm not very good at calculating resistors that might be needed and where they should be. Valuable tips are highly appreciated.
My plan is attached below.
Attachments
IMG_7967 klein.jpg
IMG_7967 klein.jpg (93.74 KiB) Viewed 1071 times
IMG_7966 klein.jpg
IMG_7966 klein.jpg (113.75 KiB) Viewed 1071 times

TD-er
Core team member
Posts: 5094
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: CJMCU-101 Light Analog Light Intensity Sensor

#2 Post by TD-er » 06 Jul 2021, 15:54

The sensor can be fed (according to the datasheet) with a voltage upto 36V.
See: https://www.ti.com/lit/ds/symlink/opt101.pdf

Just based on the block diagram, I can see the output voltage will never be higher than the input voltage as it is just an opamp and a photo cell.

Thus if you're hitting the max voltage at a low light level, you can do 2 things:
- Increase the voltage to the sensor (warning!)
- decrease the feedback resistor value as can be seen in the datasheet on page 7.

It seems the "feedback" resistor is by default 1M between pin 2 and 4.
So based on the chart on page 7, I would connect a 50k resistor between pin 4 & 2 (assuming you have connected pin 5 & 4)
If pins 5&4 are not connected, you can add the resistor between pin 5 & 2

When the sensor keeps clipping at roughly the same voltage as it does now, then you can increase the voltage to the sensor, but make sure you're not exceeding the 3v3 over the analog input pin.
So you may want to add some extra resistors to divide the voltage from the sensor.

Copitano
Normal user
Posts: 17
Joined: 18 Oct 2019, 21:11
Location: NL

Re: CJMCU-101 Light Analog Light Intensity Sensor

#3 Post by Copitano » 06 Jul 2021, 21:03

I first tested the first suggestion with 3.3 volt power supply. No luck. Then I ramped up the power supply to 5 volts and reduced the initial analog output with R1 = 100k and R2 = 470k back to 3.2 volts. The analog was not yet connected to the A0 pin of the Wemos. The moment it was connected, the analog voltage dropped to 2.55 volts. Apparently I somehow also have to take into account the internal resistances between the A0 pin and the 8266 chip that reduce the voltage from 3.3 volts to 1 volt???
The sensor does indeed seem super sensitive!
In the meantime, I'm starting to wonder whether the sensor is suitable for measuring sunlight. :roll: With 1024 steps and assuming 100,000 lux in full sunlight, that is about 100 lux per step. 3 steps is then all the level in the house not too far from a window on a cloudy day like today in the Netherlands.

TD-er
Core team member
Posts: 5094
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: CJMCU-101 Light Analog Light Intensity Sensor

#4 Post by TD-er » 06 Jul 2021, 21:17

Depends on what you want to use it for.

Another option is to use the TSL2561 or TSL2591.
The first one can loose precision on a sunny day in the Netherlands as it has a max. of 65k lux.
The IR part of the sensor is clipping long before, so I had to add some tricks to get some reasonable value out of it on really sunny days.

As a work-around to hide it from direct sunlight, but still get a good idea of "daylight" you can point the sensor more to the north.

Copitano
Normal user
Posts: 17
Joined: 18 Oct 2019, 21:11
Location: NL

Re: CJMCU-101 Light Analog Light Intensity Sensor

#5 Post by Copitano » 07 Jul 2021, 00:05

Until today I use the data from a KNMI weather station 5 km as the crow flies from my house to determine a ratio between global radiation (10 minutes) and the yield of my solar panels. Because that is not always accurate (especially with changing clouds and wind direction) I want to try to build a meter myself (read on an Rpi in domoticz => Grafana). So north is possible, but then I probably measure more diffuse sunlight and not the direct sunlight And really just because I like learning about electronics :ugeek: and taking on these kinds of challenges (without much knowledge of electronics at the moment) with a little help on different forums. Another type of sensor (BH1750 ) is on order but won't arrive until August ;)
I still had the OPT101 lying around.

EDIT: Also tried this: https://www.domoticz.com/forum/viewtopi ... 09#p277009 No luck!

Copitano
Normal user
Posts: 17
Joined: 18 Oct 2019, 21:11
Location: NL

Re: CJMCU-101 Light Analog Light Intensity Sensor

#6 Post by Copitano » 08 Jul 2021, 18:28

@TD-er I don't think I will be able to get the OPT101 in the correct measuring range (up to approx. 100,000 lux) I have now ordered an adafruit TSL2591. However, it does not (yet?) appear in the device list of ESP_Easy_mega_20210503_normal_ESP8266_4M1M. I did find this: https://github.com/letscontrolit/ESPEas ... SL2591.ino. Only I have no idea how to install that plugin on the Wemos D1 mini and can't really find a very clear manual for it anywhere.

TD-er
Core team member
Posts: 5094
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: CJMCU-101 Light Analog Light Intensity Sensor

#7 Post by TD-er » 08 Jul 2021, 20:03

Should be supported in P074: https://github.com/letscontrolit/ESPEas ... SL2591.ino
It is included in "testing A": https://espeasy.readthedocs.io/en/lates ... al-plugins

And please try to use the builds from https://td-er.nl/ESPEasy/ as the builds there do have some WiFi issues fixed.

Copitano
Normal user
Posts: 17
Joined: 18 Oct 2019, 21:11
Location: NL

Re: CJMCU-101 Light Analog Light Intensity Sensor

#8 Post by Copitano » 08 Jul 2021, 22:39

@TD-er Super! I used the latter option and installed ESP-Easy_mega_20210615_TEST_A_ESP8266_4M1M. That really went like clockwork. The Wemos D1 mini is now preconfigured. :D Now waiting for the sensor to arrive. Bring it on (tomorrow or Monday). Many many thanks for your help ;) . This way it remains fun to add new parts all the time, even without having in-depth knowledge of scripting and such. Stay curious if anyone ever comes up with a nice solution for the OPT101. It works quite well at low light levels (0-300 to 400 lux) :lol: .

Copitano
Normal user
Posts: 17
Joined: 18 Oct 2019, 21:11
Location: NL

Re: CJMCU-101 Light Analog Light Intensity Sensor

#9 Post by Copitano » 19 Jul 2021, 16:54

@TD-er. Do you appreciate feedback with data form SL2591 for further testing/development?

TD-er
Core team member
Posts: 5094
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: CJMCU-101 Light Analog Light Intensity Sensor

#10 Post by TD-er » 19 Jul 2021, 19:30

Copitano wrote: 19 Jul 2021, 16:54 @TD-er. Do you appreciate feedback with data form SL2591 for further testing/development?
Sure if you have some indication something can be improved...

Copitano
Normal user
Posts: 17
Joined: 18 Oct 2019, 21:11
Location: NL

Re: CJMCU-101 Light Analog Light Intensity Sensor

#11 Post by Copitano » 20 Jul 2021, 11:39

I'm trying to find a formula to convert the output of the TSL2591 from Lux to W/m². I have found some clues for that, such as https://www.hoogendoorn.nl/wp-content/u ... 312090.pdf. However, I don't really get close to the Global radiation of a KNMI station 5 km from here as the crow flies. On average that should be a reasonable indication on beautiful clear days such as yesterday and the day before yesterday. However, the pattern roughly follows the production of my solar panels.
Any idea about this? keep on digging. :geek:

Image
Image

After working fine this morning, for some reason, the values suddenly drop at prime time while the sensor has a clear view and the sun is shining. Although the presented figures (<65,000 lux) do not seem to give rise to this thought, possibly the sensor is reaching its max. of 88,000 lux??? From 3 p.m., plausible values will come through again :?:
Image
Attachments
Schermafbeelding 2021-07-20 153152.jpg
Schermafbeelding 2021-07-20 153152.jpg (227.43 KiB) Viewed 723 times
Schermafbeelding 2021-07-20 141646.jpg
Schermafbeelding 2021-07-20 141646.jpg (81 KiB) Viewed 728 times
Schermafbeelding 2021-07-20 141053.jpg
Schermafbeelding 2021-07-20 141053.jpg (127.11 KiB) Viewed 729 times
Schermafbeelding 2021-07-20 120802.jpg
Schermafbeelding 2021-07-20 120802.jpg (122.85 KiB) Viewed 735 times
Schermafbeelding 2021-07-20 120621.jpg
Schermafbeelding 2021-07-20 120621.jpg (132.37 KiB) Viewed 735 times
Last edited by Copitano on 20 Jul 2021, 15:44, edited 3 times in total.

TD-er
Core team member
Posts: 5094
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: CJMCU-101 Light Analog Light Intensity Sensor

#12 Post by TD-er » 20 Jul 2021, 15:35

Not 10% sure about the 2591, but the 2561 does have issues with high lux values as the IR sensor gets saturated.
For the 2561 I have written some "extrapolation" which assumes the last non-clipped IR value (or at least the ratio between the 2 sensor values) to extrapolate the used formula to compute the Lux values. (typically the ratio is 1:3)
The Lux is a computed value, which essentially uses the ratio between the 2 optical sensors inside.
But as soon as the IR sensitive sensor clips to its max. the ratio is no longer making sense and thus the computed value no longer makes sense.

I think that's what is happening here.

Copitano
Normal user
Posts: 17
Joined: 18 Oct 2019, 21:11
Location: NL

Re: CJMCU-101 Light Analog Light Intensity Sensor

#13 Post by Copitano » 20 Jul 2021, 17:54

Hmmm, unfortunately I only get the Lux value in domoticz. So I can't log the other values. But if the ratio is 1:3 would the IR sensor become saturated at about 88,000/3 is about 30,000? I don't think I've seen it that high before. I'll pay special attention to it tomorrow. The sensor seems to get confused for a few hours at the highest sun position for the past 3 sunny days and then just pick up the thread again.

According to the specifications of the TSL2591, you can set that maximum yourself. However, I don't master scripting myself and I don't see that possibility in ESPeasy either. How can I fix that?
Attachments
Schermafbeelding 2021-07-20 180119.jpg
Schermafbeelding 2021-07-20 180119.jpg (139.16 KiB) Viewed 713 times
Schermafbeelding 2021-07-20 180004.jpg
Schermafbeelding 2021-07-20 180004.jpg (76.89 KiB) Viewed 713 times
Schermafbeelding 2021-07-20 175458.jpg
Schermafbeelding 2021-07-20 175458.jpg (197.9 KiB) Viewed 714 times

TD-er
Core team member
Posts: 5094
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: CJMCU-101 Light Analog Light Intensity Sensor

#14 Post by TD-er » 20 Jul 2021, 19:43

Just based on the chart, it looks like the computed Lux hits 65535.
So it could also be the conversion hits some kind of overflow. (e.g. value stored in 16 bit unsigned int)

TD-er
Core team member
Posts: 5094
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: CJMCU-101 Light Analog Light Intensity Sensor

#15 Post by TD-er » 20 Jul 2021, 19:50

Ah found the issue.

Should be:
const float lux = P074_data->tsl.calculateLuxf(full, ir); // get LUX

TD-er
Core team member
Posts: 5094
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: CJMCU-101 Light Analog Light Intensity Sensor

#16 Post by TD-er » 20 Jul 2021, 19:54

Already fixed it: https://github.com/letscontrolit/ESPEas ... 1787ee1c8c
I can make a test build for you, for tomorrow to test.
Which one do you need?

Copitano
Normal user
Posts: 17
Joined: 18 Oct 2019, 21:11
Location: NL

Re: CJMCU-101 Light Analog Light Intensity Sensor

#17 Post by Copitano » 20 Jul 2021, 23:14

I have ESP-Easy_mega_20210615_TEST_A_ESP8266_4M1M installed now. Would be nice tot have the test build :D
I build a twin sensor that I want to test side by side tomorrow to compare the results.

TD-er
Core team member
Posts: 5094
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: CJMCU-101 Light Analog Light Intensity Sensor

#18 Post by TD-er » 21 Jul 2021, 00:04

You cannot use 2 devices on the same I2C bus with the same address.
And I think you are running into some WiFi bug which I'm also working on.
In the test build I will make for you it has improved, but tomorrow I will try to fix another issue which I found out today regarding WiFi.

So in a few minutes I will make a test build for the light sensor.

TD-er
Core team member
Posts: 5094
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: CJMCU-101 Light Analog Light Intensity Sensor

#19 Post by TD-er » 21 Jul 2021, 00:10

A test build: https://www.dropbox.com/s/knvq3ejr34m6l ... M.bin?dl=0
I have also included the external RTC support I'm working on.
Not sure if you also have those chips laying around.

At least it should now allow for a higher range in Lux values.

Copitano
Normal user
Posts: 17
Joined: 18 Oct 2019, 21:11
Location: NL

Re: CJMCU-101 Light Analog Light Intensity Sensor

#20 Post by Copitano » 21 Jul 2021, 00:40

thx again. I will flash tomorrow and tape de sensor on the chimney again and wait for bright Sunshine 8-) .
No RTC chips laying around.
EDIT: I now have two TSL2591's working, each on its own Wemos D1.
EDIT2: First impression: It seems to work. Just peaked at 66,250 lux without the sensor collapsing. Unfortunately some thin clouds approaching prime time. To be continued.......
Attachments
Schermafbeelding 2021-07-21 094120.jpg
Schermafbeelding 2021-07-21 094120.jpg (29.73 KiB) Viewed 648 times

Copitano
Normal user
Posts: 17
Joined: 18 Oct 2019, 21:11
Location: NL

Re: CJMCU-101 Light Analog Light Intensity Sensor

#21 Post by Copitano » 22 Jul 2021, 00:32

@DT-er: It looks a lot better although there is still something strange in the measurement. This is the sensor output compared to the yield of 6 panels that are almost flat on the west (slope 7 degrees) on the roof.
EDIT: This morning I also mounted the second sensor on top of the chimney. The first now with the new build and the second with the previous build of the TEST_A. I am now analyzing the data from last day from sensor 1 to see if an algorithm can be made for conversion from Lux to W/m². Linear as I sometimes come across via Google, it is not (for this sensor) in any case. I can already see that.
Attachments
IMG_8033.jpg
IMG_8033.jpg (2 MiB) Viewed 598 times
Schermafbeelding 2021-07-22 002405.jpg
Schermafbeelding 2021-07-22 002405.jpg (200.1 KiB) Viewed 598 times

TD-er
Core team member
Posts: 5094
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: CJMCU-101 Light Analog Light Intensity Sensor

#22 Post by TD-er » 22 Jul 2021, 11:39

Maybe it is possible you are seeing some internal reflection in the sensor?
Or maybe your panels (some of them) reach a critical angle where most of the sunlight is not bent inside the panel glass, but reflects?
The same can of course happen to the sensor as it does have a flat window if I remember correctly.

Copitano
Normal user
Posts: 17
Joined: 18 Oct 2019, 21:11
Location: NL

Re: CJMCU-101 Light Analog Light Intensity Sensor

#23 Post by Copitano » 22 Jul 2021, 12:45

@TD-er: I don't think it's the panels. As you can see in the graph, the yield goes up for all 6 panels. However, the value displayed by the sensor decreases in the same time period.
The surface of the sensor is indeed horizontal. This is deliberate because I am looking for the relationship between the measured Lux and the global radiation in W/m².
I just noticed that the sensor on the new test build you sent me also has an inexplicable drop in value when approaching prime time. It is almost cloudless here during that time period. The production of the solar panels also continues (red line). The dark blue line is the sensor on the new test build and the light blue line is the sensor on the previous build. The Wifi is now no problem in both cases. Today I will continue to test with the given setup. Tonight I will also flash the modified build on the second Wemos D1 so that tomorrow I can continue testing with two exactly identically configured sensors. I'll keep you posted on the results.
Attachments
Schermafbeelding 2021-07-22 123247.jpg
Schermafbeelding 2021-07-22 123247.jpg (222.98 KiB) Viewed 575 times

TD-er
Core team member
Posts: 5094
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: CJMCU-101 Light Analog Light Intensity Sensor

#24 Post by TD-er » 22 Jul 2021, 21:59

Maybe you should also log the other values of that sensor, so we can see what happens with the IR part.

A lot of unknowns and possible causes here
- Sensor heats up, causing an offset in the IR reading
- Sunlight approaching critical angle where light may cause internal reflections -> amplifying itself
- Sunlight approaching critical angle where all sunlight is absorbed in the solar panels heating them a lot (typical 0.5% loss per degree C)
- IR sensor gets saturated (thus need for logging all values)

Copitano
Normal user
Posts: 17
Joined: 18 Oct 2019, 21:11
Location: NL

Re: CJMCU-101 Light Analog Light Intensity Sensor

#25 Post by Copitano » 23 Jul 2021, 00:42

I would love to also log the other values, but I don't have the ability/sufficient knowledge to log the other values as well :( . They are not forwarded to Domoticz as far as I can see. The (complicated) route I follow is as follows: ESPEasy=>Domoticz (only Lux possible)=>Influxdb=>Grafana=>.csv of graph data=>MS Excel 2010. After that it is still a lot of work in Excel to store data to clean and fill holes.
The results of yesterday's measurements will look like this after a bit of fitting of the different quantities. It proves that KNMI station Berkhout (Yellow) is not a fully adequate reference for Hoorn.
By now I do have a fairly good start of an algorithm to convert Lux to W/m² global radiation. The line of calculated global irradiance (Blue) fits quite nicely with the total output of the set of solar panels (red) although it still needs some fine-tuning.For the conversion I use the following formula: 88.000/65.535*0.010139. I borrow the last part of the formula from https://www.hoogendoorn.nl/wp-content/u ... 312090.pdf

The alternation of the red and the blue line can partly be explained by the fact that there are more panels on the west than on the eastside of the roof. The jump around 1.30 pm because 4 west panels will be fully exposed to the sun at that time. What I really need to be able to further test and analyze properly is a full clear sky day :D .
Attachments
Schermafbeelding 2021-07-23 002645.jpg
Schermafbeelding 2021-07-23 002645.jpg (346.23 KiB) Viewed 512 times

TD-er
Core team member
Posts: 5094
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: CJMCU-101 Light Analog Light Intensity Sensor

#26 Post by TD-er » 24 Jul 2021, 00:22

Do you have the "Cache controller" in the build you're running?
This one can log the data to flash and you can use a piece of JavaScript to decode it into CSV.
See: https://github.com/letscontrolit/ESPEas ... Controller

Copitano
Normal user
Posts: 17
Joined: 18 Oct 2019, 21:11
Location: NL

Re: CJMCU-101 Light Analog Light Intensity Sensor

#27 Post by Copitano » 24 Jul 2021, 15:04

I didn't add anything to the build you sent me in dropbox. It may sound very stupid, but I don't know if that's where the cash controller is. How do I find out?
The link you send to a cash controller for the ESP32. In my case it runs on a Wemos D1 mini in both cases. Does it work on Wemos as well?
Other than uploading a full build, I've never uploaded any additional stuff. What steps do I have to take to upload?
I see these possibilities:
Attachments
Schermafbeelding 2021-07-24 150338.jpg
Schermafbeelding 2021-07-24 150338.jpg (73.73 KiB) Viewed 428 times

TD-er
Core team member
Posts: 5094
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: CJMCU-101 Light Analog Light Intensity Sensor

#28 Post by TD-er » 24 Jul 2021, 21:24

Well just to temper your hopes and/or expectations... it is a "cache" controller, not a "cash" controller ;)
I don't have a lot of cash, that needs a specific controller ;)

The "cache controller" is maybe also not the best descriptive name.
Its initial use case was to cache the data untill we got a (lost) connection, like in a moving vehicle which gets out of range of the network connection.

But most use cases will be about storing the data to a binary blob on the file system until you can fetch it.

It is probably included in the "custom" build.
But I guess for the next few days you won't hit the > 65'000 Lux.

Copitano
Normal user
Posts: 17
Joined: 18 Oct 2019, 21:11
Location: NL

Re: CJMCU-101 Light Analog Light Intensity Sensor

#29 Post by Copitano » 25 Jul 2021, 01:34

Hahaha, okay "cache" :lol: . The misspelling may have distracted attention too much from the question how I know if it's included and if not what steps I take to upload ;) . Sorry, in this field i am Noob :oops: .
And as the weather forecast looks like now, the maximum value will indeed not be reached in the next days. Not in the least because the test set-up is again on the kitchen table instead of on the chimney. As soon as a nice stable day comes for testing, I want to have everything ready :ugeek: .

Copitano
Normal user
Posts: 17
Joined: 18 Oct 2019, 21:11
Location: NL

Re: CJMCU-101 Light Analog Light Intensity Sensor

#30 Post by Copitano » 29 Jul 2021, 13:34

@TD-er: please think about my questions from my previous post. I've googled quite a bit, but can't really find a clear instruction/manual for it.
1) How do I check if it's there in the costumbuild? If I understand well, there should be e extra tab in ESPEasy? It's not there at the moment and I can not find anything that looks like it in "Tools"
2) If not how do I ad/upload the plugin to existing build on the Wemos D1 mini?
3) How do I activate logging of all measurements?
Thanks in advance

TD-er
Core team member
Posts: 5094
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: CJMCU-101 Light Analog Light Intensity Sensor

#31 Post by TD-er » 29 Jul 2021, 14:33

The cache controller is a controller, just like "Domoticz HTTP" and "OpenHAB MQTT"
If it isn't in your list of controllers (on the controller tab) you need another build.

Can you give a list of plugins and controllers you need, then we can make a build for you.

Copitano
Normal user
Posts: 17
Joined: 18 Oct 2019, 21:11
Location: NL

Re: CJMCU-101 Light Analog Light Intensity Sensor

#32 Post by Copitano » 29 Jul 2021, 18:20

@TD-er: As you advised viewtopic.php?p=53973#p53973I would like to install this plugin: https://github.com/letscontrolit/ESPEas ... Controller
I am now running build: on the Wemos D1 mini: ESP_Easy_mega_20210721_test_A_ESP8266_4M1M
With this controllers included:
Attachments
Controllers.PNG
Controllers.PNG (27.09 KiB) Viewed 3 times

Post Reply

Who is online

Users browsing this forum: No registered users and 25 guests