Picoclick-C3
  • Introduction
  • Hardware
  • Extension Port
  • Software
    • Important note
    • Get battery voltage
    • Serial output
    • ESP-NOW
  • Extension Boards
    • Motion sensor
    • Distance sensor
    • PIR sensor
    • Light sensor
    • GPIO expander
    • Encoder
    • OLED 0.49"
    • OLED 0.69"
  • Enclosure
Powered by GitBook
On this page
  • Hardware
  • Overview
  • Technical drawing
  • Schematics
  • Software
  1. Extension Boards

Distance sensor

PreviousMotion sensorNextPIR sensor

Last updated 2 years ago

The distance sensor extension board is based on the VCNL4040 by Vishay Semiconductors. The sensor uses I2C to communicate with the Picoclick (SDA = GPIO2, SCL = GPIO8). It has an ultra low power voltage regulator on board and can be used to activate the Picoclick by firing an interrupt. The interrupt can be configured via software.

Hardware

Overview

Technical drawing

  • PCB: 18mm x 10mm

  • Thickness: 1mm

  • Mounting holes: 3.2mm

  • Corner radius: 2mm

Schematics

Software

#include <Arduino.h>
#include <FastLED.h>
#include <Wire.h>
#include "SparkFun_VCNL4040_Arduino_Library.h"
#include "config.h"

VCNL4040 vcnl;

void setup(){
  pinMode(BUTTON_PIN, INPUT);
  pinMode(ADC_ENABLE_PIN, OUTPUT);
  pinMode(ADC_PIN, INPUT);
  analogReadResolution(12);
  digitalWrite(ADC_ENABLE_PIN, HIGH);

  WiFi.mode(WIFI_OFF);

  FastLED.addLeds<APA102, APA102_SDI_PIN, APA102_CLK_PIN, BGR>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  delay(50);

  set_fastled(CRGB::Blue);
  
  Wire.begin(SDA_PIN, SCL_PIN);

  if(vcnl.begin() == false){
    printf("Device not found. Please check wiring.\r\n");
    set_fastled(CRGB::Red);
    while(1); //Freeze!
  }
}

unsigned long led_timer = millis();
int hue1 = 0, hue2 = 0;
int brightness = 255;
unsigned long t_sensor = 500;

void loop() {
  if(digitalRead(BUTTON_PIN) == 1){
    set_fastled(CRGB::Red);
    delay(1000);
    esp_deep_sleep_start();
  }

  if(millis() >= t_sensor + 100){
    t_sensor = millis();
    unsigned int proxValue = vcnl.getProximity();
    printf("Proximity: %i\r\n", proxValue);
  }

  if(millis() >= led_timer + 15){
    led_timer = millis();
    set_fastled(CHSV(hue1, 255, brightness), CHSV(hue2, 255, brightness));
    hue1 = (hue1 + 1)%255;
    hue2 = (hue1 + 127)%255;
  }
}

Hardwaretest can be found on .

GitHub