<< return to Pixycam.com

Pixy cam Line Follow

hey what’s up guys, i’ve a projet with a team and my part is the “PixyCam” and i want to know where can i find help on the pixycam lin follower , so can you help me plz

Sry for bad anglish, i’m french

Thx, have a nice day

A line following robot? You might check out this page:



Hi thx for help, but how can we do without the Zumo robot, we use a robot base

If you want to use a different base (other than Zumo) but still use the PIxy2 Arduino sketches (e.g. line_zumo_demo), you will need to modify the parts of the sketch set the wheel velocities to work with the base that you choose (and not Zumo).


Hi sorry but i m a beginer so i don’t understand verry well
And i have a question, is it possible to take the barcode information from the serial monitor, and then make "if barcode 0=1 then do …( something with the speed of our motor )
Is there a program witch the pixycam follow a line with 3 ways, 1 for the left way and the right way and the way forward

thx for answers

I foudn the program the take the informations from the barcode :
// If barcode, acknowledge with beep, and set left or right turn accordingly.
// When calling setNextTurn(), Pixy will “execute” the turn upon the next intersection,
// making the left or right branch in the intersection the new main vector, depending on
// the angle passed to setNextTurn(). The robot will then follow the branch.
// If the turn is not set, Pixy will choose the straight(est) path by default, but
// the default turn can be changed too by calling setDefaultTurn(). The default turn
// is normally 0 (straight).
buzzer.playFrequency(2000, 100, 15);
// code==0 is our left-turn sign
if (pixy.line.barcodes->m_code==0)
pixy.line.setNextTurn(90); // 90 degrees is a left turn
// code==5 is our right-turn sign
else if (pixy.line.barcodes->m_code==5)
pixy.line.setNextTurn(-90); // -90 is a right turn

Execpt that i will use a motor witch work on pwm so i will see that with my mates

And thx a lot u helped me a lot

Hello Renzo,
That is a good section of code to be looking at. If you are just starting out, the best way to get something working is to start with the example code and make small changes. In other words, experiment :slight_smile:

Your changes to the code may result in something no longer working – the robot may no longer move, or it may no longer follow the line, but you can always go back to the last set of changes that did work. You won’t break anything permanently by writing code that doesn’t work. We guarantee no smoke or fire :slight_smile:

Here is a the line tracking API, which is a good reference, in case you haven’t seen:



1 Like

Hi thx for answer, i try the pixy and i try to do a “when barcode0 turn on the led on the arduino” but it doesn’t work, i don’t understand why, and i see this doc but i dont’t understand everything verry well

Hi, I have a project in which I must use the line pixy program and the color blocks as well. Is there any way I can ‘combine’ the settings of both to track the line and see color objects?

Hi Daniela,

unfortunately you can’t use both modes at the same time.


Hi there, i try to make a led on the arduino turn on and turn off when she see a differente barcode and it doesn t work
like when barcode ==1 turn on the arduino led and when barcode==2 turn off the arduino led

plz help

Here there programme ( it s an extract from zumo robot )

#include <Pixy2.h>
#include <PIDLoop.h>

Pixy2 pixy;

PIDLoop headingLoop(5000, 0, 0, false);

void setup()

// change to the line_tracking program. Note, changeProg can use partial strings, so for example,
// you can change to the line_tracking program by calling changeProg(“line”) instead of the whole
// string changeProg(“line_tracking”)


void loop()
int8_t res;
int32_t error;
int left, right;
char buf[96];

// Get latest data from Pixy, including main vector, new intersections and new barcodes.
res = pixy.line.getMainFeatures();

// If error or nothing detected, stop motors
if (res<=0)

Serial.print("stop ");


// We found the vector…
if (res&LINE_VECTOR)
// Calculate heading error with respect to m_x1, which is the far-end of the vector,
// the part of the vector we’re heading toward.

// code==0 is our left-turn sign
if (pixy.line.barcodes->m_code==0)
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (H
// code==1 is our right-turn sign
else if (pixy.line.barcodes->m_code==1)
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the


Is it possible to make the arduino led turn on when the pixy cam detect the barcode 1 and turn off when it see the barcode 2 ?

You are so sad Vernil72 I have also faced the same problem as you

Bear in mind that getMainFeatures will report each barcode only once when it sees it for the first time. Perhaps you want getAllFeatures(), which reports barcodes, etc for each frame, regardless of whether it’s seen them before.

Here’s an example that will get you up and running.


Hi Edward,

will it be possible to update the pixy (first version) to implement a line follower robot?

best regards,


I think it’s possible in theory, but there are some limitations with the Pixy1 imaging chip that make it challenging (from what I’ve been told.) :frowning:


1 Like

today the new cameras Pixy2 arrived! The Line-Following function works perfect :), I will try to implement the Line-Following on the old cameras, it will take a while …


… and thank you very much for your linux support!

Sure thing, we’re big fans of Linux here. :slight_smile:


Hello, the "Pixy " can track lines? **no the pixy2

And if is posible you have codes?