Community project

AI Vision Machine

ESP32
Photo of AI Vision Machine

Ahmed Rami

Published August 28, 2026

This project builds a face recognition system using the ESP32 microcontroller and DFRobot HUSKYLENS 2 AI Vision Sensor. The HUSKYLENS handles all the computer vision processing on its own, making it easy to add machine learning capabilities without complex algorithms or training pipelines.

The guide provides a complete parts list, wiring diagram showing power and I2C signal connections, and ready-to-use firmware that recognizes faces and reports their position on screen. After assembly, teach the camera a face by following the on-device prompts, then point it at that person to see real-time recognition results streamed over serial.

Wiring diagram

Wiring diagram for AI Vision Machine

Gather all the parts

QtyComponent
1

DFRobot HUSKYLENS 2 AI Vision Sensor

HUSKYLENS 2

A small smart camera that recognizes faces locally and sends the results to the ESP32.

Assemble it in 4 steps

1. Place the two modules

Put the ESP32 DevKit v1 and the HUSKYLENS 2 where you can reach both sets of header pins. Leave the ESP32 unplugged while you add wires, so a loose wire cannot accidentally touch the wrong pin.

  • Keep the labels on both boards facing upward so you can read VCC, GND, SDA, and SCL.
  • Do not power either board while moving jumper wires; a misplaced power wire can damage a module.

2. Connect power and ground

Use one red jumper wire from the HUSKYLENS 2 VCC pin to the ESP32 3V3 pin (power). Use one black jumper wire from HUSKYLENS 2 GND to an ESP32 GND pin (ground). These wires give the camera safe 3.3-volt power and a shared return path.

  • Make sure VCC and GND are not swapped — the printed labels, not the header position, are what matter.
  • Swapped power wires can permanently damage the HUSKYLENS camera.

3. Connect the two signal wires

Connect HUSKYLENS 2 SDA to ESP32 GPIO21 (data), then connect HUSKYLENS 2 SCL to ESP32 GPIO22 (clock). These two wires let the camera send recognition results to the ESP32.

  • Use two different wire colors for SDA and SCL so a crossed pair is easy to spot later.
  • Do not connect the HUSKYLENS signal pins to 5V; the ESP32 uses 3.3-volt signals.

4. Teach a face to the camera

After the firmware is deployed, use the HUSKYLENS 2 screen controls to select Face Recognition and learn a face. Hold the person’s face clearly in the camera view while teaching it. The learned number is the ID that the ESP32 prints when it recognizes that person.

  • Use even lighting and keep the camera steady while teaching for more reliable recognition.
  • Only enroll people who have agreed to be recognized, and do not use the device for security-critical identity decisions.

Review all connections

1. Connections between "huskylens_1" and "ESP32"

Functionhuskylens_1ESP32
powerVCC3V3
groundGNDGND
i2cSDAGPIO 21
i2cSCLGPIO 22

Deploy the firmware

#include <Arduino.h>
#include <Wire.h>
#include <DFRobot_HuskylensV2.h>


// Forward declarations
void printIfChanged(const String &message);

constexpr uint8_t HUSKYLENS_SDA = 21;
constexpr uint8_t HUSKYLENS_SCL = 22;
constexpr uint32_t REPORT_INTERVAL_MS = 250;

DFRobot_HuskylensV2 huskylens;
String lastMessage;
uint32_t lastReportMs = 0;

void printIfChanged(const String &message) {
  if (message != lastMessage) {
    Serial.println(message);
    lastMessage = message;
  }
}

void setup() {
  Serial.begin(115200);
  Wire.begin(HUSKYLENS_SDA, HUSKYLENS_SCL);

  Serial.println("AI camera starting...");
  while (!huskylens.begin(Wire)) {
    Serial.println("HUSKYLENS not found. Check VCC, GND, SDA, and SCL.");
    delay(1000);
  }

  huskylens.switchAlgorithm(ALGORITHM_FACE_RECOGNITION);
  Serial.println("Ready. Teach a face on the HUSKYLENS screen, then point it at that person.");
}

void loop() {
  if (millis() - lastReportMs < REPORT_INTERVAL_MS) {
    return;
  }
  lastReportMs = millis();

  if (huskylens.getResult(ALGORITHM_FACE_RECOGNITION) != 0) {
    printIfChanged("Camera is connected, but no face result is available.");
    return;
  }

  FaceResult result = huskylens.readFaceResult();
  if (result.ID > 0) {
    String message = "Recognized face ID " + String(result.ID) +
                     " at x=" + String(result.xCenter) +
                     ", y=" + String(result.yCenter) +
                     ", size=" + String(result.width) + "x" + String(result.height);
    printIfChanged(message);
  } else {
    printIfChanged("Face detected, but it has not been taught a name or ID yet.");
  }
}

Remix this project

Make it yours in one click

Open a full copy of this project in your own Schematik workspace — diagram, code, parts, and assembly steps included. Swap the sensor, add features, or redesign the whole thing with AI. The author's original stays untouched.

Open in Schematik