Site icon AranaCorp

Computer vision with Arduino and the Pixy2 camera


The Pixy2 camera is a computer-aided visual recognition system. It allows your microcontroller to detect colors or lines to create a line-following robot for example or to catch colored objects.


Operating principle

The Pixy2 camera is a complete vision system with an image sensor and a microprocessor. It includes learning algorithms and detection of colour, line, intersection and small barcode. It includes all the technology necessary for visual recognition.

Technical specifications


The Pixy2 camera can easily communicate with a microcontroller using its communication interfaces (UART, SPI, I2C, USB). It connects to the ICSP port of the Arduino board.

Configuration of the Pixy2 camera

Download pixymon software

Open the PixyMon v2 software

Learning to recognize

Before being able to use the Pixy2, we will have to teach it to recognize the objects we are interested in and assign them a signature (identifier). It is possible to save up to 7 signatures.

Once the learning is done, we can see that the object is surrounded by a rectangle with the signature written in its center.

If you have problems to recognize the learned object it is possible to configure the sensitivity of recognition in the settings – go to file -> configure under the tuning tab and play with the settings to get the desired result.

Some objects are not easily recognizable. Try to find objects with particular shapes and bright, distinct colors.


Install the Arduino Pixy2 library. The most important function is getBlocks() which returns the number of detected blocks and information like their signatures (identifier after learning) and dimensions.

#include <Pixy2.h>//

Pixy2 pixy;

void setup() {
  //Init Serial USB
  Serial.println(F("Initialize System"));
  //Init Pixy2

void loop() {

void testPixy() { /* function testPixy */
  //// Get blocks from Pixy2
  // grab blocks!

  // If there are detect blocks, print them!
  if (pixy.ccc.numBlocks) {
    Serial.print("Detected ");
    for (int i = 0; i < pixy.ccc.numBlocks; i++) {
      Serial.print("  block ");
      Serial.print(": ");

If you encounter compilation problems, you can delete the zumobuzzzer and zumomotor files (.h and .cpp) in the Documents library folder\Arduino\libraries\Pixy2


Once the code is uploaded, the camera sends messages to the Arduino as soon as the object appears in its field of view. You then have access to the signature of the object, its dimensions and its position.



Retrouvez nos tutoriels et d’autres exemples dans notre générateur automatique de code
La Programmerie

How useful was this post?

Click on a star to rate it!

Average rating 4 / 5. Vote count: 6

No votes so far! Be the first to rate this post.

Exit mobile version