Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Object Tracking with PixyCam
Hello friends. I've been working a project off and on to track blocks of a specific color using the pixy cam, particularly the CMU Pixy Cam 5 ( This camera has been superceded by the Pixy Cam 6, but as far as I can tell all of this material will be applicable to the new camera as well.

A little about the Pixy Cam. It's a super powerful little camera that allows you to identify the location of a color in the frame. My favorite part of the Pixy Cam is that you can select the color you'd like Pixy Cam to track using a small button on the bottom of the camera. Simply place the object in front of the camera and hold the button until the built in LED is the same color as the object, and POOF, you're tracking that color!

The Pixy Cam Arduino library, among other resources, are available at their website ( The Pixy Cam is set up to power it's own pan/tilt system, and the Arduino library leans toward such a system. This isn't great for mimicArm, so I chose to use the x/y position of the centroid of the object.

The Pixy Cam can detect multiple objects, so for the purposes of this experiment I'm only going to detect whichever block the camera has identified as the first block. Pixy Cam can easily return the x and y coordinates of the object using pixy.blocks[0].x and pixy.blocks[0].y

Through a small amount of manipulation of the provided examples mimicArm will follow a block of a defined color using the code below:

#include <SPI.h>  
#include <Pixy.h>
#include <robot.h>

// This is the main Pixy object
Pixy pixy;

void setup()

void loop()
  static int i = 0;
  int j;
  uint16_t blocks;
  char buf[32];
  // grab blocks!
  blocks = pixy.getBlocks();
  // If there are detect blocks, print them!
  if (blocks)
    //Serial.println("got here");
    Serial.print("x is \t");
    Serial.print("\ty is \t");
    robotMove(1, pixy.blocks[0].x);
    robotMove(2, 127);
    robotMove(3, pixy.blocks[0].y);
  //else robotHome();

void robotHome(){
  robotMove(1, 127);
  robotMove(3, 127);
  robotMove(2, 127);

Forum Jump:

Users browsing this thread: 1 Guest(s)