Example Code for Arduino-Read Ambient Light

Last revision 2025/12/26

This article provides a comprehensive guide on using an Arduino with the VEML7700 ambient light sensor, including necessary hardware and software preparation, wiring diagrams, and sample code for accurately measuring ambient light levels.

Hardware Preparation

  • DFRduino UNO (or similar) x 1
  • Gravity: I2C VEML7700 Ambient Light Sensor x1
  • M-M/F-M/F-F Jumper wires

Software Preparation

Wiring Diagram

SEN0228

Other Preparation Work

Download VEML7700 Arduino Library
How to install Libraries in Arduino IDE

Sample Code

/*!
 * @file readVEML7700.ino
 * @brief DFRobot's VEML7700 ambient light sensor
 * @n     High Accuracy Ambient Light Sensor
 * @copyright  Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
 * @license  The MIT License (MIT)
 * @author  [yangyang]([email protected])
 * @version  V1.0
 * @date  2016-12-08
 * @url  https://github.com/DFRobot/DFRobot_VEML7700
  */

#include "DFRobot_VEML7700.h"
#include <Wire.h>

/*
 * Instantiate an object to drive the sensor
 */
DFRobot_VEML7700 als;

void setup()
{
  Serial.begin(9600);
  als.begin();   // Init
}

void loop()
{
  float lux;
  
  als.getALSLux(lux);   // Get the measured ambient light value
  Serial.print("Lux:");
  Serial.print(lux);
  Serial.println(" lx");
  
  delay(200);
}

Result

Result

Was this article helpful?

TOP