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