Home Code Raspberry Pi and MAX44009 ambient light sensor example

Raspberry Pi and MAX44009 ambient light sensor example

by shedboy71

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.



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


Module Pin Raspberry Pi Pin
 Vin 3v3
 Gnd Gnd



Thanks goes out controleverything – they have many examples written in python for many devices, even if they dont have the one you need they are excellent for learning and you can figure out how to write your own version relatively quickly

# Distributed with a free-will license.
# Use it any way you want, profit or free, provided it fits in the licenses of its associated works.
# MAX44009
# This code is designed to work with the MAX44009_I2CS I2C Mini Module available from ControlEverything.com.
# https://www.controleverything.com/products

import smbus
import time

# Get I2C bus
bus = smbus.SMBus(1)

# I2C address of the device

# MAX44009 Register Map
MAX44009_REG_INTR_STATUS = 0x00 # Interrupt Status Register
MAX44009_REG_INTR_ENABLE = 0x01 # Interrupt Enable Register
MAX44009_REG_CONFIG = 0x02 # Configuration Register
MAX44009_REG_LUX_HIGH = 0x03 # Lux High Byte
MAX44009_REG_LUX_LOW = 0x04 # Lux Low Byte
MAX44009_REG_THRES_UP_HI = 0x05 # Upper Threshold High Byte
MAX44009_REG_THRES_LO_HI = 0x06 # Upper Threshold Low Byte
MAX44009_REG_THRES_TIMER = 0x07 # Threshold Timer

MAX44009_REG_INTR_ENABLE_NO_ASSRT = 0x00 # The INT pin and the INTS bit are not asserted even if an interrupt event has occurred
MAX44009_REG_INTR_ENABLE_TRIGGER = 0x01 # Detection of an interrupt event triggers a hardware interrupt

MAX44009_REG_CONFIG_CONTMODE_DEFAULT = 0x00 # Default mode
MAX44009_REG_CONFIG_CONTMODE_CONTIN = 0x80 # Continuous mode
MAX44009_REG_CONFIG_MANUAL_DEFAULT = 0x00 # Default mode of configuration is used for the IC
MAX44009_REG_CONFIG_MANUAL_MODEON = 0x40 # Manual mode of configuration is used for the IC
MAX44009_REG_CONFIG_CDR_NODIVIDED = 0x00 # Current not divided. All of the photodiode current goes to the ADC
MAX44009_REG_CONFIG_CDR_DIVIDED = 0x08 # Current divided by 8
MAX44009_REG_CONFIG_INTRTIMER_800 = 0x00 # Integration Time = 800ms, This is a preferred mode for boosting low-light sensitivity
MAX44009_REG_CONFIG_INTRTIMER_400 = 0x01 # Integration Time = 400ms
MAX44009_REG_CONFIG_INTRTIMER_200 = 0x02 # Integration Time = 200ms
MAX44009_REG_CONFIG_INTRTIMER_100 = 0x03 # Integration Time = 100ms, This is a preferred mode for high-brightness applications
MAX44009_REG_CONFIG_INTRTIMER_50 = 0x04 # Integration Time = 50ms, Manual Mode only
MAX44009_REG_CONFIG_INTRTIMER_25 = 0x05 # Integration Time = 25ms, Manual Mode only
MAX44009_REG_CONFIG_INTRTIMER_12_5 = 0x06 # Integration Time = 12.5ms, Manual Mode only
MAX44009_REG_CONFIG_INTRTIMER_6_25 = 0x07 # Integration Time = 6.25ms, Manual Mode only

class MAX44009():
def __init__(self):

def write_config(self):
“””Select the configuration register data from the given provided values”””
bus.write_byte_data(MAX44009_DEFAULT_ADDRESS, MAX44009_REG_CONFIG, CONFIG)

def read_lumninance(self):
“””Read data back from MAX44009_REG_LUX_HIGH(0x03), 2 bytes, luminance MSB, luminance LSB”””
data = bus.read_i2c_block_data(MAX44009_DEFAULT_ADDRESS, MAX44009_REG_LUX_HIGH, 2)

# Convert the data to lux
exponent = (data[0] & 0xF0) >> 4
mantissa = ((data[0] & 0x0F) << 4) | (data[1] & 0x0F)
luminance = ((2 ** exponent) * mantissa) * 0.045

return {‘l’ : luminance}

from MAX44009 import MAX44009
max44009 = MAX44009()

while True:
lum = max44009.read_lumninance()
print “Ambient Light luminance : %d lux” %(lum[‘l’])
print ” ***************************************** ”




max44009 output

max44009 output




MAX44009 Ambient Light Sensor Module with 4P Pin Header

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More