OPT3001 Digital Ambient Light Sensor and Microbit example

The OPT3001 is a sensor that measures the intensity of visible light. The spectral response of the sensor tightly matches the photopic response of the human eye and includes significant infrared rejection.

The OPT3001 is a single-chip lux meter, measuring the intensity of light as visible by the human eye. The precision spectral response and strong IR rejection of the device enables the OPT3001 to accurately meter the intensity of light as seen by the human eye regardless of light source. The strong IR rejection also aids in maintaining high accuracy when industrial design calls for mounting the sensor under dark glass for aesthetics. The OPT3001 is designed for systems that create light-based experiences for humans, and an ideal preferred replacement for photodiodes, photoresistors, or other ambient light sensors with less human eye matching and IR rejection.

Measurements can be made from 0.01 lux up to 83k lux without manually selecting full-scale ranges by using the built-in, full-scale setting feature. This capability allows light measurement over a 23-bit effective dynamic range.

The digital operation is flexible for system integration. Measurements can be either continuous or single-shot. The control and interrupt system features autonomous operation, allowing the processor to sleep while the sensor searches for appropriate wake-up events to report via the interrupt pin. The digital output is reported over an I2C- and SMBus-compatible, two-wire serial interface.

The low power consumption and low power-supply voltage capability of the OPT3001 enhance the battery life of battery-powered systems.

Features

  • Precision Optical Filtering to Match Human Eye:
    • Rejects > 99% (typ) of IR
  • Automatic Full-Scale Setting Feature Simplifies Software and Ensures Proper Configuration
  • Measurements: 0.01 lux to 83 k lux
  • 23-Bit Effective Dynamic Range With
    Automatic Gain Ranging
  • 12 Binary-Weighted Full-Scale Range Settings:
    < 0.2% (typ) Matching Between Ranges
  • Low Operating Current: 1.8 µA (typ)
  • Operating Temperature Range: –40°C to +85°C
  • Wide Power-Supply Range: 1.6 V to 3.6 V
  • 5.5-V Tolerant I/O

Connection

Microbit CJMCU-3001
3.3v Vcc
Gnd Gnd
SDA – 20 SDA
SCL – 19 SCL

Code

This example uses the following library https://github.com/closedcube/ClosedCube_OPT3001_Arduino

/*
 
This is example for ClosedCube OPT3001 Digital Ambient Light Sensor breakout board 
 
Initial Date: 02-Dec-2015
 
Hardware connections for Arduino Uno:
VDD to 3.3V DC
SDA to A4
SCL to A5
GND to common ground
 
Written by AA for ClosedCube
 
MIT License
 
*/
 
#include <Wire.h>
#include <ClosedCube_OPT3001.h>
 
ClosedCube_OPT3001 opt3001;
 
#define OPT3001_ADDRESS 0x44
 
void setup()
{
	Serial.begin(9600);
	Serial.println("ClosedCube OPT3001 Arduino Test");
 
	opt3001.begin(OPT3001_ADDRESS);
	Serial.print("OPT3001 Manufacturer ID");
	Serial.println(opt3001.readManufacturerID());
	Serial.print("OPT3001 Device ID");
	Serial.println(opt3001.readDeviceID());
 
	configureSensor();
	printResult("High-Limit", opt3001.readHighLimit());
	printResult("Low-Limit", opt3001.readLowLimit());
	Serial.println("----");
}
 
void loop()
{
	OPT3001 result = opt3001.readResult();
	printResult("OPT3001", result);
	delay(500);
}
 
void configureSensor() {
	OPT3001_Config newConfig;
 
	newConfig.RangeNumber = B1100;	
	newConfig.ConvertionTime = B0;
	newConfig.Latch = B1;
	newConfig.ModeOfConversionOperation = B11;
 
	OPT3001_ErrorCode errorConfig = opt3001.writeConfig(newConfig);
	if (errorConfig != NO_ERROR)
		printError("OPT3001 configuration", errorConfig);
	else {
		OPT3001_Config sensorConfig = opt3001.readConfig();
		Serial.println("OPT3001 Current Config:");
		Serial.println("------------------------------");
 
		Serial.print("Conversion ready (R):");
		Serial.println(sensorConfig.ConversionReady,HEX);
 
		Serial.print("Conversion time (R/W):");
		Serial.println(sensorConfig.ConvertionTime, HEX);
 
		Serial.print("Fault count field (R/W):");
		Serial.println(sensorConfig.FaultCount, HEX);
 
		Serial.print("Flag high field (R-only):");
		Serial.println(sensorConfig.FlagHigh, HEX);
 
		Serial.print("Flag low field (R-only):");
		Serial.println(sensorConfig.FlagLow, HEX);
 
		Serial.print("Latch field (R/W):");
		Serial.println(sensorConfig.Latch, HEX);
 
		Serial.print("Mask exponent field (R/W):");
		Serial.println(sensorConfig.MaskExponent, HEX);
 
		Serial.print("Mode of conversion operation (R/W):");
		Serial.println(sensorConfig.ModeOfConversionOperation, HEX);
 
		Serial.print("Polarity field (R/W):");
		Serial.println(sensorConfig.Polarity, HEX);
 
		Serial.print("Overflow flag (R-only):");
		Serial.println(sensorConfig.OverflowFlag, HEX);
 
		Serial.print("Range number (R/W):");
		Serial.println(sensorConfig.RangeNumber, HEX);
 
		Serial.println("------------------------------");
	}
 
}
 
void printResult(String text, OPT3001 result) {
	if (result.error == NO_ERROR) {
		Serial.print(text);
		Serial.print(": ");
		Serial.print(result.lux);
		Serial.println(" lux");
	}
	else {
		printError(text,result.error);
	}
}
 
void printError(String text, OPT3001_ErrorCode error) {
	Serial.print(text);
	Serial.print(": [ERROR] Code #");
	Serial.println(error);
}

Output

Here is a sample of the output from the Serial Monitor

OPT3001: 7910.40 lux
OPT3001: 8017.92 lux
OPT3001: 7969.28 lux
OPT3001: 454.40 lux
OPT3001: 125.28 lux
OPT3001: 192.88 lux
OPT3001: 247.76 lux
OPT3001: 252.56 lux
OPT3001: 256.48 lux
OPT3001: 256.80 lux
OPT3001: 5.44 lux
OPT3001: 6.09 lux
OPT3001: 6.81 lux
OPT3001: 38.48 lux
OPT3001: 229.84 lux
OPT3001: 233.68 lux

 

Link

OPT3001 CJMCU-3001 ambient light sensor eye like measurement light intensity single chip illumination meter

Micro:bit and TEMT6000 ambient light sensor example

TEMT6000X01 ambient light sensor is a silicon NPN epitaxial planar phototransistor in a miniature transparent 1206 package for surface mounting. It is sensitive to visible light much like the human eye and has peak sensitivity at 570 nm.

Here is a picture of a module

Here is a schematic of the module

APPLICATIONS

Ambient light sensor for control of display backlight dimming in LCD displays and keypad backlighting of mobile devices and in industrial on/off-lighting operation.

• Automotive sensors
• Mobile phones
• Notebook computers
• PDA’s
• Cameras
• Dashboards

Connection

Code

#define LIGHTSENSORPIN A1 //Ambient light sensor reading
void setup()
{
pinMode(LIGHTSENSORPIN, INPUT);
Serial.begin(9600);
}
void loop()
{
float reading = analogRead(LIGHTSENSORPIN); //Read light level
float square_ratio = reading / 1023.0; //Get percent of maximum value (1023)
square_ratio = pow(square_ratio, 2.0);
Serial.println(reading);
delay(1000);
}

 

Output

Open the serial monitor and you should see something like this

41.00
42.00
4.00
1.00
21.00
38.00
41.00
41.00
40.00

 

Links

TEMT6000 Light Sensor

https://www.vishay.com/docs/81579/temt6000.pdf

micro:bit and MAX44009 ambient light sensor example

The MAX44009 ambient light sensor features an I²C digital output that is ideal for a number of portable applications such as smartphones, notebooks, and industrial sensors. At less than 1µA operating current, it is the lowest power ambient light sensor in the industry and features an ultra-wide 22-bit dynamic range from 0.045 lux to 188,000 lux.

Low-light operation allows easy operation in dark-glass applications.

The on-chip photodiode’s spectral response is optimized to mimic the human eye’s perception of ambient light and incorporates IR and UV blocking capability. The adaptive gain block automatically selects the correct lux range to optimize the counts/lux.

max44009 module

max44009 module

Features

Wide 0.045 Lux to 188,000 Lux Range
VCC = 1.7V to 3.6V
ICC = 0.65µA Operating Current
-40°C to +85°C Temperature Range
Device Address Options – 1001 010x and 1001 011x

 

Connection

 

Module Pin micro:bit Pin
 Vin 3v3
 Gnd Gnd
 SCL  P19
SDA  P20

 

Code

#include<Wire.h>
 
#define Addr 0x4A
 
void setup()
{
 
Wire.begin();
// Initialise serial communication
Serial.begin(9600);
 
Wire.beginTransmission(Addr);
Wire.write(0x02);
Wire.write(0x40);
Wire.endTransmission();
delay(300);
}
 
void loop()
{
unsigned int data[2];
Wire.beginTransmission(Addr);
Wire.write(0x03);
Wire.endTransmission();
 
// Request 2 bytes of data
Wire.requestFrom(Addr, 2);
 
// Read 2 bytes of data luminance msb, luminance lsb
if (Wire.available() == 2)
{
data[0] = Wire.read();
data[1] = Wire.read();
}
 
// Convert the data to lux
int exponent = (data[0] & 0xF0) >> 4;
int mantissa = ((data[0] & 0x0F) << 4) | (data[1] & 0x0F);
float luminance = pow(2, exponent) * mantissa * 0.045;
 
Serial.print("Ambient Light luminance :");
Serial.print(luminance);
Serial.println(" lux");
delay(500);
}

 

Output

Open the serial monitor and change the light intensity on the sensor, here is an example

Ambient Light luminance :4.59 lux
Ambient Light luminance :6.12 lux
Ambient Light luminance :6.12 lux
Ambient Light luminance :36.72 lux
Ambient Light luminance :36.72 lux
Ambient Light luminance :36.72 lux
Ambient Light luminance :73.44 lux
Ambient Light luminance :73.44 lux
Ambient Light luminance :73.44 lux
Ambient Light luminance :9.95 lux
Ambient Light luminance :9.95 lux
Ambient Light luminance :12.24 lux

 
Link

https://datasheets.maximintegrated.com/en/ds/MAX44009.pdf

MAX44009 Ambient Light Sensor Module with 4P Pin Header

micro:bit and BH1750FVI Ambient Light Sensor example

The BH1750FVI is an digital Ambient Light Sensor IC for I2C bus interface. This IC is the most suitable to obtain the ambient light data for adjusting LCD and Keypad backlight power of Mobile phone. It is possible to detect wide range at High resolution.

This is the module I used

For those that are interested I found this schematic online for the module

 

Connection

A fairly standard connection being an I2C device.

VCC  –  Micro:bit 3.3v
GND – Micro:bit  Gnd
SCL – Micro:bit P19
SDA – Micro:bit P20

 

Code

You will need this modified library, I could not get the original Arduino one to work – BH1750-master

#include <Wire.h>
#include <BH1750.h>
 
 
BH1750 lightMeter;
 
 
void setup(){
  Serial.begin(9600);
  lightMeter.begin();
  Serial.println("Running...");
}
 
 
void loop() {
  uint16_t lux = lightMeter.readLightLevel();
  Serial.print("Light: ");
  Serial.print(lux);
  Serial.println(" lx");
  delay(1000);
}

 

Output

Open the serial monitor and cover the sensor, shine some light on it and so on. You should see the lux value change

Light: 19 lx
Light: 22 lx
Light: 17 lx
Light: 9 lx
Light: 2 lx
Light: 8 lx
Light: 9 lx

 

 

Links
You can pick these sensors up for about $4 a piece
BH1750FVI light intensity illumination module for arduino 3V-5V