Category Archives: Designers logbook

Designers logbook: measuring the light level on a Raspberry Pi

Designers logbook day x – lost track of days already spent on the design. There are four types of people. People who can dream and envision products. People who can actually design these products. People who can build the designs and people who just buy the product.

There aren’t many people how can dream and envision a new product or concept. In the Design Thinking world, these are the people how hire guys like me, to help them with the ideation and conceptualization of their dreams. For guys like me these types of people are really the ultimate customers. Since they already have a vision, the money, and they just want their vision to be made.

There are many people who are able to design products, but it’s questionable if – in every situation – the right designers are hired. Especially when it comes to the design of smart devices. In this case, you’ll need designers that have knowledge of electronics, material experts, casing designers, software designers e.t.c. For me, this is were I’m like a fish in the water. I love to design and create within boundaries and other limitations.

For a project I’ve been working on for a long time, I wanted to be able to adjust the brightness of a display depending on the current light level of the surroundings. Since I’m using a Raspberry Pi to prototype this project. I wanted to be able the measure the surroundings light level to be more precise. That turned out to be a difficult task, because it turned out that the Pi’s GPIO pins just aren’t capable of handling analog values.

Now of course you could just use a simple breakout board, that you can buy on aliexpress or ebay. They transform the analog light level to a digital value, based upon the value of the trimmer pot.  Those breakout boards serve their purpose well on a breadboard.

But mounting them in a final product is always a pain in the ass. You’ll end up with a lot of dupont cables connecting all of the breakout boards – which is not a good idea. And if you’re unlucky the designer of the breakout board put an led on the board so that you can see that the board is powered on. The latest is truly a nightmare. If I have one of those nights, in which sleep isn’t happening for me, I sometimes just get out of bed and go downstairs. That’s where I keep most of the In Progress Projects. Whenever I enter the living room I’m always wondering why all of the electronics have so many leds? Honestly whether it is a breakout board, an Arduino a raspberry Pi, my Wifi router, e.t.c. I just seem to have many leds that light up all day.

Another restriction I’m having is that I need to design a custom PCB for mounting the final product in it’s case. At this point I had two routes I could take. One is using an AtTiny85 – which is a small version of the Arduino – as an i2c slave. And the second is redesigning a cheap Chinese breakout board. Which at this points makes me a type three person – those who use other peoples designs. But let’s be honest. The Chinese suppliers copied this design from companies like Philips. So it’s merely a case of standing on the shoulders of Giants.

Creating an AtTin85 i2cslave was much harder than I’d thought. Besides the whole circuitry consumed a couple of milli amps. Which is something I didn’t like. The Raspberry Pi 3.3V power supply is really limited. Besides it didn’t made any sense to use a custom made ic for doing light level monitoring only.

So I had no other option than the redesign a chines breakout board. After some online research I discovered that the circuits of those boards are really simple. On most of this type of breakout boards an LM393 comparator chip is used, to determine the transition point of much light (digital high) or almost no or none light (digital low).

I really had a hard time finding the right circuit online. Since most of the examples didn’t contain a trimmer pot. But I finally stumbled upon the next circuit:

The article in which the circuit was posted explains the circuitry quiet well. The only problem I’m having with this circuitry is the leds. There are two of them. One indicating power and the other representing the digital value – which is actually useful during development.

But stripping out both leds out of the circuitry is very easy. And since I have no use for the Analog output I was able to simply-fie the circuitry.

I measured the power consumption which is a 1mA. And connected it to my Pi. I powered the circuit with the 3.3V of the Pi and hooked the D1 to GPIO pin 16. By using the 3.3V I don’t need a level converter between the Raspberry Pi and the D1 pin of the light sensor circuitry. The second capacitor (C2) is probably not needed. But it doesn’t harm.

So first design problem solved. Now it’s up to the next, reading the value in a Raspberry Pi script. Which really is simple. Here’s a code snippet.

import RPi.GPIO as gpio

# Setup GPIO
gpio.setmode(gpio.BCM)
gpio.setup( 16, gpio.IN )
print gpio.input( 16 )

As always I test these kind of circuits on a breadboard for a long time. After two months I consider it a success. Since I have some other challenges before I can start designing the PCB, I’ll leave this part for now.

As said before there are four types of people, but most of us can alternate between them. It just depends on where you’re standing and what it is that you want.