Wemos 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.

 

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 Wemos Pin
 Vin 5v
 Gnd Gnd
 SCL  D1
SDA  D2

 

Code

[codesyntax lang=”cpp”]

#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);
}

[/codesyntax]

 

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

2 COMMENTS

  1. If the sensor has 2 Address Options – 1001 010x and 1001 011x, please explain how you can connect 2 light sensors to one Arduino?

    • You would need to remove the blob of solder at the GND pin on the sensor and put another one to the pad which has no solder on the sensor (move it) – this should give the other I2C address. You would then need to create a duplicate in the code called Addr1 for example. So an Addr and Addr1.

      Or you could try a library like https://github.com/RobTillaart/Arduino/tree/master/libraries/Max44009 – which allows you to set the I2C address in the code – you would still need to have 2 copies though

LEAVE A REPLY

Please enter your comment!
Please enter your name here