30 min

Elevate comfort and efficiency through precise ambient light control based on BH1726NUC and PIC18LF45K42

Sensors that shine: Ambient light detection for a brighter tomorrow

Ambient 16 Click with EasyPIC v8

Published Sep 24, 2023

Click board™

Ambient 16 Click

Development board

EasyPIC v8


NECTO Studio



Simplify your life with our ambient light sensor, which adapts to changing light conditions effortlessly



Hardware Overview

How does it work?

Ambient 16 Click is based on the BH1726NUC, a 16-bit digital-output ambient light sensor from Rohm Semiconductor. The BH1726NUC can detect a wide range of illuminance up to 30klx and provides excellent responsivity close to the response of human eyes. It also has stable performance over a wide temperature range and a voltage range suitable to measure the amount of the present ambient light. The BH1726NUC is designed to control the brightness in various applications based on ambient light availability, brightness for optimum visibility, and energy efficiency. This IC can change its ambient light

sensitivity to compensate for the effect of attenuation by the optical window. Adjustment is made by changing the measurement time. For example, when the transmission rate of the optical window is 1/n (measurement result becomes 1/n times if the optical window is set), the effect of the optical window is compensated by changing sensor sensitivity from default to n times. Ambient 16 Click communicates with MCU using the standard I2C 2-Wire interface to read data and configure settings, supporting Standard Mode operation with a clock frequency of 100kHz and Fast Mode up to 400kHz. Besides, the BH1726NUC

allows choosing the least significant bit (LSB) of its I2C slave address using the SMD jumper labeled ADDR SEL. It also possesses an additional interrupt signal, routed on the INT pin of the mikroBUS™ socket labeled as INT, indicating when a specific interrupt event occurs. This Click board™ can be operated only with a 3.3V logic voltage level. The board must perform appropriate logic voltage level conversion before using MCUs with different logic levels. Also, it comes equipped with a library containing functions and an example code that can be used as a reference for further development.

Ambient 16 Click top side image
Ambient 16 Click bottom side image

Features overview

Development board

EasyPIC v8 is a development board specially designed for the needs of rapid development of embedded applications. It supports many high pin count 8-bit PIC microcontrollers from Microchip, regardless of their number of pins, and a broad set of unique functions, such as the first-ever embedded debugger/programmer. The development board is well organized and designed so that the end-user has all the necessary elements, such as switches, buttons, indicators, connectors, and others, in one place. Thanks to innovative manufacturing technology, EasyPIC v8 provides a fluid and immersive working experience, allowing access anywhere and under any

circumstances at any time. Each part of the EasyPIC v8 development board contains the components necessary for the most efficient operation of the same board. In addition to the advanced integrated CODEGRIP programmer/debugger module, which offers many valuable programming/debugging options and seamless integration with the Mikroe software environment, the board also includes a clean and regulated power supply module for the development board. It can use a wide range of external power sources, including a battery, an external 12V power supply, and a power source via the USB Type-C (USB-C) connector.

Communication options such as USB-UART, USB DEVICE, and CAN are also included, including the well-established mikroBUS™ standard, two display options (graphical and character-based LCD), and several different DIP sockets. These sockets cover a wide range of 8-bit PIC MCUs, from the smallest PIC MCU devices with only eight up to forty pins. EasyPIC v8 is an integral part of the Mikroe ecosystem for rapid development. Natively supported by Mikroe software tools, it covers many aspects of prototyping and development thanks to a considerable number of different Click boards™ (over a thousand boards), the number of which is growing every day.

EasyPIC v8 horizontal image

Microcontroller Overview

MCU Card / MCU




MCU Memory (KB)


Silicon Vendor


Pin count


RAM (Bytes)


Used MCU Pins

mikroBUS™ mapper

Power Supply
I2C Clock
I2C Data

Take a closer look


Ambient 16 Click Schematic schematic

Step by step

Project assembly

EasyPIC v8 front image hardware assembly

Start by selecting your development board and Click board™. Begin with the EasyPIC v8 as your development board.

EasyPIC v8 front image hardware assembly
Buck 22 Click front image hardware assembly
MCU DIP 40 hardware assembly
EasyPIC v8 DIP MB 1 - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
NECTO Compiler Selection Step Image hardware assembly
NECTO Output Selection Step Image hardware assembly
Necto image step 6 hardware assembly
Necto DIP image step 7 hardware assembly
Necto image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Necto PreFlash Image hardware assembly

Track your results in real time

Application Output

After pressing the "FLASH" button on the left-side panel, it is necessary to open the UART terminal to display the achieved results. By clicking on the Tools icon in the right-hand panel, multiple different functions are displayed, among which is the UART Terminal. Click on the offered "UART Terminal" icon.

UART Application Output Step 1

Once the UART terminal is opened, the window takes on a new form. At the top of the tab are two buttons, one for adjusting the parameters of the UART terminal and the other for connecting the UART terminal. The tab's lower part is reserved for displaying the achieved results. Before connecting, the terminal has a Disconnected status, indicating that the terminal is not yet active. Before connecting, it is necessary to check the set parameters of the UART terminal. Click on the "OPTIONS" button.

UART Application Output Step 2

In the newly opened UART Terminal Options field, we check if the terminal settings are correct, such as the set port and the Baud rate of UART communication. If the data is not displayed properly, it is possible that the Baud rate value is not set correctly and needs to be adjusted to 115200. If all the parameters are set correctly, click on "CONFIGURE".

UART Application Output Step 3

The next step is to click on the "CONNECT" button, after which the terminal status changes from Disconnected to Connected in green, and the data is displayed in the Received data field.

UART Application Output Step 4

Software Support

Library Description

This library contains API for Ambient 16 Click driver.

Key functions:

  • ambient16_get_part_id - Ambient 16 get part ID function

  • ambient16_set_gain - Ambient 16 set ADC gain function

  • ambient16_read_data - Ambient 16 get data in lux function

Open Source

Code example

This example can be found in NECTO Studio. Feel free to download the code, or you can copy the code below.

 * @file main.c
 * @brief Ambient16 Click example
 * # Description
 * This is an example that demonstrates the use of the Ambient 16 Click board 
 * by measuring illuminance and displaying the value in Lux.
 * The demo application is composed of two sections :
 * ## Application Init
 * Initializes I2C driver performs software reset and applies default settings.
 * ## Application Task
 * Demonstrates use of Ambient 16 click board by reading data values of DATA0 and DATA1 in Lux
 * every second, and logging it on the UART terminal.
 * @author Stefan Ilic

#include "board.h"
#include "log.h"
#include "ambient16.h"

static ambient16_t ambient16;
static log_t logger;
static float data0;
static float data1;

void application_init ( void ) 
    log_cfg_t log_cfg;  /**< Logger config object. */
    ambient16_cfg_t ambient16_cfg;  /**< Click config object. */

     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, " Application Init " );

    // Click initialization.
    ambient16_cfg_setup( &ambient16_cfg );
    AMBIENT16_MAP_MIKROBUS( ambient16_cfg, MIKROBUS_1 );
    if ( I2C_MASTER_ERROR == ambient16_init( &ambient16, &ambient16_cfg ) ) 
        log_error( &logger, " Communication init." );
        for ( ; ; );
    if ( AMBIENT16_ERROR == ambient16_default_cfg ( &ambient16 ) )
        log_error( &logger, " Default configuration." );
        for ( ; ; );
    uint8_t id;
    ambient16_get_part_id( &ambient16, &id );
    log_printf( &logger, "- - - - - - - - - - - - -\r\n" );
    log_printf( &logger, " Part ID = 0x%.2X \r\n", ( uint16_t ) id );
    log_printf( &logger, "- - - - - - - - - - - - -\r\n" );
    Delay_ms( 500 );
    log_info( &logger, " Application Task " );
    log_printf( &logger, "- - - - - - - - - - - - -\r\n" );

void application_task ( void ) 
    ambient16_read_data( &ambient16, &data0, &data1 );
    log_printf( &logger, " DATA 0 = %.2f lx    \r\n", data0 );
    log_printf( &logger, " DATA 1 = %.2f lx    \r\n", data1 );
    log_printf( &logger, "- - - - - - - - - - -\r\n" );
    Delay_ms( 1000 );

void main ( void ) 
    application_init( );

    for ( ; ; ) 
        application_task( );

// ------------------------------------------------------------------------ END

Additional Support