8 Replies Latest reply on Nov 11, 2019 11:10 AM by fmilburn

    Struggling to get a digital sensor to see my indoor ambient light

    suitcase

      I wanted to use a Raspberry Pi to check whether my room's ceiling light was on. I’m an electronics amateur and do not want to solder anything, so I am using a Pi Zero W with presoldered pins, and using female-to-female Dupont cables I bought to connect the GPIO pins to the sensor board.

       

      I bought this cheap little photoresistor board: https://www.aliexpress.com/item/32806322505.html

       

      I set it up successfully (using the digital out, since a regular Pi can't see analog signals). I can easily set it up so that flashing my phone flashlight at it will make it return something different over the digital out.

       

      But with all the adjusting I'm doing of the potentiometer, I just can't get it to reliably trigger when the ambient room light changes. If I am REALLY careful with it, tweaking the potentiometer to the point the “DO-LED” starts flickering on and off, barely turning on, I can get it to work for a few minutes to return 1 or 0 over the digital output based on the room’s light, but it’s very flaky. Right now I just thought I got it right, but after five minutes, find it’s flickering between 0 and 1 again.

       

      What would be a better, more reliable room sensor I could purchase? I bought a similar board that used a photodiode instead, and it's just as bad. Maybe worse, because photodiodes are more directional, I guess. It just seems like these little potentiometer-adjustable sensors have a microscopic “sweet spot” for detecting ambient room light, which doesn’t make sense to me.

       

      One critical thing is that I don’t want to solder anything, or use a breadboard, or anything that seems complicated. I really liked my little setup with the dupont cables and this board, and I’d like something that is just as doable with my hands alone. What should I get?

        • Re: Struggling to get a digital sensor to see my indoor ambient light
          jw0752

          Hi,

          You might want to check to see if you can find a module that has a hysteresis adjustment as well as a sensitivity control. The hysteresis will allow you to adjust the turn on and turn off points to different light levels. Flickering is a sign that the module doesn't have sufficient difference between the turn on and turn off points. The other point is that a module with both adjustments might have a better design. One final observation is that there may be subtle light changes in your room that the sensor can detect that you can't. Our eyes continually adjust to changing light levels and this make it difficult to detect changes that can easily affect a sensor.

           

          John

          7 of 7 people found this helpful
          • Re: Struggling to get a digital sensor to see my indoor ambient light
            fmilburn

            There are more precise sensors like the one by Rohm that is included in the RoadTest here.  Adafruit also sells one that I have used. They should be relatively easy to set up over I2C on the Pi although I haven’t done that.  The measurements are reasonably accurate without calibration and stable. It would be easy to set up hysteresis in software as John describes above. 

            Frank

            5 of 5 people found this helpful
              • Re: Struggling to get a digital sensor to see my indoor ambient light
                suitcase

                Thank you! These two sensors seem to require soldering, which I am hoping to avoid. However, this one seems to have a similar model number to the Adafruit one  (VEML7700), and looks to have a socket I could plug my little individual Dupont cables into. Would you say this seems about right, or is it not going to be readable over the Pi’s GPIO in the same fashion as the Adafruit model?

                  • Re: Struggling to get a digital sensor to see my indoor ambient light
                    shabaz

                    You'll need to use some adaptor cable, because the connector is JST 'PH' which is 2mm pitch, not 2.54mm pitch. Ordinary jumper cables will be too tight, although perhaps you may be able to remove the plastic shells and use thinner heatshrink to fit them but it would be an experiment. Possibly some JST PH to 0.1" header pins cable exists, or you could crimp your own (JST shells and pre-crimped wires exist on ebay etc, so you may only need to crimp the other end yourself).

                    The board uses I2C, so it needs to go to specific pins on the 'Pi, and it won't be readable in the same fashion, since the board you're replacing only has an on/off output.

                    This board  provides light level readings, and I2C code is used to read the digital register containing the light level. So, your code needs to be adapted for that (it's not difficult, there are plenty of examples if you google 'pi i2c'+the language of your choice,  it may require you to either find existing code for that board or chip, or check the datasheet and write your own).

                    Also, although you may not need to solder with this board, you may need to desolder. There's some pull-up resistors on the board that the Pi doesn't need. It may work fine, but if it doesn't, you'll need to remove the resistors (could be clipped off with wire cutters maybe, if you really don't want to touch a soldering iron, but at some point difficulties could be far more easily resolved using a soldering iron (even a cheap $15 one would do)).

                    3 of 3 people found this helpful
                    • Re: Struggling to get a digital sensor to see my indoor ambient light
                      fmilburn

                      The Rohm has 0.1 inch pins soldered on and worked very well with an Arduino: https://www.newark.com/rohm/rpr-0521rs-evk-001/eval-brd-ambient-light-proximity/dp/83AC4200?MER=sy-me-pd-mi-acce It has footprints for pullup resistors but they are not soldered on and it is a 3V3 device so should be good to go for the Pi.  I really liked this chip. The Arduino library was straight forward as I remember.

                      The Adafruit device has pull-up resistors soldered on but they seem to claim it works for the Pi and they provide a Python 3 library that they say works with the Pi.  Like Shabaz, I would not let the soldering stop me even if I did not have much experience.  As clumsy as I am, I have not screwed up 0.1” pins although there is always a first time :-).  Adafruit supplies the pins and has a tutorial on soldering them.

                      3 of 3 people found this helpful
                  • Re: Struggling to get a digital sensor to see my indoor ambient light
                    dougw

                    You could try putting a little cup reflector around the sensor to collect more light onto the sensor surface. something like aluminum foil should work, but be careful not to short out the sensor leads with the foil. A little hot glue or silicone glue would insulate the leads. An alternative is simply a white paper reflector.

                    You can carefully bend the sensor leads so the sensor faces up if that helps.

                    7 of 7 people found this helpful