Toggle Nav

Interfacing AP3216 Ambient Light And Proximity Sensor with Arduino

Table of Contents

AP3216 Sensor Features

The AP3216C is an integrated ALS & PS module that includes a digital ambient light sensor [ALS], a proximity sensor [PS], and an IR LED in a single package. This module is well suited to applications under clear glass or darkened glass. The proximity function is targeted specifically towards near field application and detects external object with simple configurable zone controlled by registers. 

Note

You need a 220 to 470 ohm resistor to interface this module.

You can download the datasheet of this module here.

AP3216 Sensor Pinout

This sensor has 6 pins:

  • VCC: Module power supply – 3.3 V
  • GND: Ground
  • SCL: I2C clock
  • SDA: I2C data
  • VLED: Turning on the IR LED on module
  • INT: Adjusting I2C Address

You can see pinout of this module in the image below.

Required Materials

Hardware Components

Arduino UNO R3 × 1
AP3216 Ambient Proximity Module × 1
Resistor 470 Ohm × 1
Male to Female jumper wire × 1

Software Apps

Arduino IDE

Interfacing AP3216 Sensor with Arduino

Step 1: Circuit

The following circuit shows how you should connect Arduino to AP3216 sensor. Connect wires accordingly.

Step 2: Code

Tip

If you need more help with installing a library on Arduino, read this tutorial: How to Install an Arduino Library

Upload the following code to your Arduino.

    /*
  modified on Sep 28, 2020
  Modified by MohammedDamirchi from
  https://github.com/igorantolic/ai_ap3216_ambient-light-and-proximity-sensor-library
  https://electropeak.com/learn/
*/



// Hardware wiring:
// Arduino     AP3216
//             VLED --,
// GND ------- GND   |R| 330 Ohm
// 3.3V ------ VCC ---'
// A5 -------- SCL
// A4 -------- SDA
            

#include "Ai_AP3216_AmbientLightAndProximity.h"

Ai_AP3216_AmbientLightAndProximity aps = Ai_AP3216_AmbientLightAndProximity();
//Ai_AP3216_AmbientLightAndProximity aps = Ai_AP3216_AmbientLightAndProximity(D5, D6);//custompins

void setup() {
  Serial.begin(115200);
  aps.begin();
  aps.startAmbientLightAndProximitySensor ();
}

void loop() {
  long alsValue = aps.getAmbientLight();
  long psValue = aps.getProximity();

  Serial.print("Ambient Light: ");
  Serial.print(alsValue);
  Serial.print(", Proximity: ");
  Serial.println(psValue);

  delay(200);
  de  }

After running the code, the output is as follow.

Liked What you see?

Get updates and learn from the best

More To Explore

Leave a Reply

Your email address will not be published. Required fields are marked *