Illum sensor

Use this page with AI

Explore with your favorite AI

Gemini & other AI

Copy this page’s context into your AI to explore how it works and what you can build.

Open Gemini

Copy the prompt, then paste it into Gemini’s message box.

View prompt

Table of contents

Overview

This sample reads the value of the illuminance sensor on the 4-Sensors leaf and displays it on the serial monitor.

Leaf to use

Use the following leaves.

TypeNameQ’ty
AZ62Connector Cover1
AI014-Sensors1
AZ01USB1
AP03STM32 MCU1
AV01CR20321
CR2032 coin cell battery1
M2*15mm screw2

Assembly

Let’s assemble leaves as shown in the figure below.

assemble1

Source code

Write the following program1 in the Arduino IDE.

In order to make this sketch work, you need to install the libraries If you haven’t installed it yet, refer to Environment to install it.

//=====================================================================
//  Illuminance meter
//
//    (c) 2020 Trillion-Node Study Group
//    Released under the MIT license
//    https://opensource.org/licenses/MIT
//
//      Rev.00 2020/05/05  First release
//=====================================================================
#include <Wire.h>
#include <ClosedCube_OPT3001.h>

#define OPT3001_ADDRESS 0x45      // ADDR pin = VCC

ClosedCube_OPT3001 illum;

float dataIllum;

void setup() {
  // initialize serial communication at 115200 second per second:
  Serial.begin(115200);
  // initialize i2c communication with OPT3001:
  Wire.begin();

  delay(10);

  OPT3001_Config illumConfig;
  OPT3001_ErrorCode illumErrorConfig;

  illum.begin(OPT3001_ADDRESS);

  illumConfig.RangeNumber = B1100;               // automatic full scale
  illumConfig.ConvertionTime = B1;               // convertion time = 800ms
  illumConfig.ModeOfConversionOperation = B11;   // continous conversion
  illumConfig.Latch = B0;                        // hysteresis-style

  illumErrorConfig = illum.writeConfig(illumConfig);

  if(illumErrorConfig != NO_ERROR){
    illumErrorConfig = illum.writeConfig(illumConfig);   //retry
  }
}

void loop() {
    OPT3001 result = illum.readResult();

    if(result.error == NO_ERROR){
      dataIllum = result.lux;
    }

    Serial.println("Lum[lx] = " + String(dataIllum));

    delay(1000);

}

Illuminance_Meter.ino

Execution Results

Open the serial monitor of the Arduino IDE and set the baud rate to 115200 bps and you will see the illuminance.

Footnotes

  1. The program is the same as AVR MCU Leaf. ↩

Leaf photo
Search documentation, sample apps, and Q&A