Little_french_kev
Published © GPL3+

Face Tracking Camera

When it sees you, it won't stop following!

IntermediateFull instructions provided47,479
Face Tracking Camera

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
webcam
×1
rubber band
×1
9V 1A Switching Wall Power Supply
9V 1A Switching Wall Power Supply
×1
MG-90s servos
×2
2.1*5.5mm jack plug
×1
Linear Regulator (7805)
Linear Regulator (7805)
×1
M2*10mm self tapping screws
×15
paperclip
×1
Hook Up Wire Kit, 22 AWG
Hook Up Wire Kit, 22 AWG
×1
pin header
×1
5 mm LED: Red
5 mm LED: Red
×1
5 mm LED: Green
5 mm LED: Green
×1
5 mm LED: Yellow
5 mm LED: Yellow
×1
Resistor 220 ohm
Resistor 220 ohm
×3
heat-shrink tubing
×1

Software apps and online services

Windows 10
Microsoft Windows 10

Hand tools and fabrication machines

Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Plier, Long Nose
Plier, Long Nose
Soldering iron (generic)
Soldering iron (generic)
multimeter
screwdriver
3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

face tracking camera parts

all the parts needed to built the face tracking camera mini . You can also find them here : https://www.littlefrenchkev.com/download

Schematics

Wiring diagram

Code

Arduino code

C/C++
This is the code that will be uploaded to the arduino
//Sketch based on work done by Robin2 on the arduino forum
//more info here
//https://forum.arduino.cc/index.php?topic=225329.msg1810764#msg1810764


#include <Servo.h>

Servo panServo;
Servo tiltServo; 

byte redledPin = 2;
byte yellowledPin = 3;
byte greenledPin = 4;

const byte buffSize = 40;
char inputBuffer[buffSize];
const char startMarker = '<';
const char endMarker = '>';
byte bytesRecvd = 0;
boolean readInProgress = false;
boolean newDataFromPC = false;

float panServoAngle = 90.0;
float tiltServoAngle = 90.0;
int LED_state = 0;

//8=============D

void setup() {
  Serial.begin(115200);
  
  panServo.attach(8);
  tiltServo.attach(9);

  pinMode(redledPin, OUTPUT);
  pinMode(yellowledPin, OUTPUT);
  pinMode(greenledPin, OUTPUT);
  
  //moveServo();
  start_sequence();

  delay(200);
  
  Serial.println("<Hasta la vista baby>"); // send message to computer
}

//8=============D

void loop() {
  getDataFromPC();
  replyToPC();
  moveServo();
  setLED();
}

//8=============D

void getDataFromPC() {

    // receive data from PC and save it into inputBuffer
    
  if(Serial.available() > 0) {

    char x = Serial.read();              //read char from serial
      
    if (x == endMarker) {                //look for end marker
      readInProgress = false;            //if found, set read in progress true (will stop adding new byte to buffer)
      newDataFromPC = true;              //let arduino know that new data is available
      inputBuffer[bytesRecvd] = 0;       //clear input buffer
      processData();                      // process data in buffer
    }
    
    if(readInProgress) {
      inputBuffer[bytesRecvd] = x;      //populate input buffer with bytes
      bytesRecvd ++;                    //increment index
      if (bytesRecvd == buffSize) {     //when buffer is full
        bytesRecvd = buffSize - 1;      //keep space for end marker
      }
    }

    if (x == startMarker) {              // look for start maker
      bytesRecvd = 0;                    // if found, set byte received to 0
      readInProgress = true;             // set read in progress true
    }
  }
}

//8=============D

void processData() // for data type "<float, float, int>" 
{
  char * strtokIndx; // this is used by strtok() as an index

   strtokIndx = strtok(inputBuffer,",");      // get the first part
   panServoAngle = atof(strtokIndx);         // convert this part to a float

   strtokIndx = strtok(NULL,",");          // get the second part(this continues where the previous call left off)
   tiltServoAngle = atof(strtokIndx);     // convert this part to a float

   strtokIndx = strtok(NULL, ",");      // get the last part
   LED_state = atoi(strtokIndx);          // convert this part to an integer (string to int)
}

//8=============D

void replyToPC() {

  if (newDataFromPC) {
    newDataFromPC = false;
    Serial.print("<");
    Serial.print(panServo.read());
    Serial.print(",");
    Serial.print(tiltServo.read());
    Serial.println(">");
  }
}

//8=============D

void moveServo() 
{
  panServo.write(panServoAngle);
  tiltServo.write(tiltServoAngle);
}

void setLED()
{
  if(LED_state == 2){
    digitalWrite(redledPin, LOW);
    digitalWrite(yellowledPin, HIGH);
    digitalWrite(greenledPin, LOW);
    }
  else if(LED_state == 1){
    digitalWrite(redledPin, LOW);
    digitalWrite(yellowledPin, LOW);
    digitalWrite(greenledPin, HIGH);    
    }
  else if(LED_state == 0){
    digitalWrite(redledPin, HIGH);
    digitalWrite(yellowledPin, LOW);
    digitalWrite(greenledPin, LOW);  
    }  
  else if(LED_state == 3){
    digitalWrite(redledPin, HIGH);
    digitalWrite(yellowledPin, HIGH);
    digitalWrite(greenledPin, HIGH);  
    }  
  else{
    digitalWrite(redledPin, LOW);
    digitalWrite(yellowledPin, LOW);
    digitalWrite(greenledPin, LOW);    
    }
  
  }

//8=============D

  void start_sequence()
  {
    panServo.write(90);
    tiltServo.write(90);
    delay(300);

  
    digitalWrite(redledPin, HIGH);
    delay(100);
    digitalWrite(redledPin, LOW);
    digitalWrite(yellowledPin, HIGH);
    delay(100);
    digitalWrite(yellowledPin, LOW);
    digitalWrite(greenledPin, HIGH);
    delay(100);
  
    digitalWrite(redledPin, LOW);
    digitalWrite(yellowledPin, LOW);
    digitalWrite(greenledPin, LOW);
    delay(100);
    digitalWrite(redledPin, HIGH);
    digitalWrite(yellowledPin, HIGH);
    digitalWrite(greenledPin, HIGH);
    delay(100);
    digitalWrite(redledPin, LOW);
    digitalWrite(yellowledPin, LOW);
    digitalWrite(greenledPin, LOW);
    }

Face detection software

Here is the repository where you can find the files for the face detection software . You can also find a executable version on my website .

Credits

Little_french_kev

Little_french_kev

4 projects • 126 followers
3D modeller by trade . I got into hardware as a mean to give life to my 3D models . Loving it more and more as I progress!!!!

Comments