Colour Tracking Mobile Robot (PIXY)


Hi everyone, it seems that everyone nowadays love to make a line following robot. Why don’t we try something new and adventure? Why don’t we try to make a robot that follow the colour that we want?  It can be red, orange, yellow, blue, green, light blue and violet. By using a Pixy CMUcam5 and CT-UNO you can make all this happen. Below is the step by step instruction to make this Colour Tracking Mobile Robot comes true!! 



All this 8 component is needed to make this robot.



This latest CMUcam version of embedded camera is an image sensor with a powerful processor that you can program by only send the information you’re looking for so your microcontroller isn’t overwhelmed by data from the image sensor. The Pixy CMUCam also exports its information in a variety of useful ways – UART serial, SPI, I2C, digital out, or analog out – so your microcontroller can communicate easily while still doing other tasks. It’s so unobtrusive that you can even hook up multiple Pixy CMUCams to one microcontroller! Superb!
The Pixy CMUCam5 also uses hue and saturation as its primary means of image detection – rather than the normal RGB. This means that lighting or exposure won’t affect the Pixy CMUCam’s detection of an item – which is a frustrating problem with many image sensors. It’s also a vast improvement over previous versions of the Pixy CMUCam, adding increased flexibility when it comes to lighting and exposure changes.
It can also remember seven different color signatures, find hundreds of objects at the same time, and is super fast – processing at 50 frames a second.
Finally, the Pixy CMUCam is also teachable so you can set it up to only send you images that you’ve specifically told it to look for. It’s easy and fast and has an open source application called PixyMon.
Each Pixy CMUcam5 Sensor comes with a 6-pin-to-10-pin IDC cable and mounting tabs and screws.



1. Firstly, you have to setup the tires, motors, DC Jack (Male) and Battery holder to the

Alluminium robot chassis as shown in the Figure below.



2. Then, you can attach the CT-UNO to the alluminium robot chassis.


This is the wiring for the CT-UNO and Pixy CMUcam5.

3. Then, you can stack the 2Amp Motor Driver Shield to CT-UNO.

4. Put the 3.7V 1100mAh Li-Ion battery to the batery holder. 

5. Lastly, attach the Pixy CMUcam5 sensor to the robot. Now we are finished setup the

robot hardware. 



1. Firstly, we have to teach the Pixy the colour that we want it to remember. Run PixyMon after it’s connected to the computer by using USB cable. Click Action and choose Set signature. (I choose Set signature 2 for my orange colour)


2. Now the video camera will stop and show the capture image. From this image you can teach the camera the colour that you want by choose the region that you want. 


3. Now Pixy already memorize the colour and will recognize it as s=2 because we set it to signature 2. 


4. We have to tune the colour so that Pixy will only capture the colour that we want. This can be done by clicking on the gear icon. Just slide it to the left if we want it to be less inclusive and to the right if we want it to be more inclusive.



5. After tuning the Pixy, now we can proceed with arduino. Please make sure that the library file is added to the arduino library. We can try the sample code hello_world by Pixy after we added the library. Just click on File -> Example -> Pixy -> hello_world. Then, just upload the source code. After that, click on serial monitor and you will see the image below. On the serial monitor, it will print the height, width and signature.


This source code will do scan() function for 5 seconds. You can change the time by changing the 5000 to the value that you want.

area = width * height; //calculate the object area
maxArea = area + 1000;
minArea = area - 1000;

Below shows the coding for scan() function as mentioned in while loop above. 

void scan()
uint16_t blocks;
blocks = pixy.getBlocks(); //receive data from pixy
signature = pixy.blocks[i].signature; //get object's signature
x = pixy.blocks[i].x; //get x position
y = pixy.blocks[i].y; //get y position
width = pixy.blocks[i].width; //get width
height = pixy.blocks[i].height; //get height

In the void loop() function, there is mention

(signature == 2)

You can change the number of signature that you have set by changing the number.



, , , ,

Related Post

How to Make your Line Following Robot Faster?

Raspberry Pi: Line Following Robot

Raspberry Pi: Control DC Motor using MDDS10

Line following robot CT-ARM

Line Following Robot with CT-ARM

16 thoughts on “Colour Tracking Mobile Robot (PIXY)

  1. hi suadanwar. im really interested in this project. i want to ask some questions.
    1) can i use l293d because i dont have ct-uno
    2) as you can see pixy can recognise more than1 colour. it is posibble that if we try to program 2 colour or more and every colour have it own instruction??

  2. Hi adam4667,

    Sorry for late reply. Based on your questions,
    (1). L293D is a motor driver which in this robot I use 2Amp Motor Driver Shield as my motor driver. Motor driver and CT-UNO is two different things. CT-UNO is a microcontroller and it controls the robot. If you want to use L293D instead of CT-UNO, then the answer is NO. But if you want to use L293D instead of 2Amp Motor Driver Shield, then the answer is YES.

    (2). Yes. You can program for more than one colour. Just make sure that the colour is Red,Orange,Yellow,Green,Cyan (light blue),Blue and Violet. Then you can just program it based on the number of the signature.

    Hope you do understand my explaination. 🙂

  3. hi suadanwar,
    thanks for relpy my message.. i really need your help. now my project successful using your exactly your instruction and program. thank you so much suadanwar.

    now i really want your help about add another 1 or 2 colour and every colour have its own instruction and modified the instruction using the program that you attach at source code..


  4. hi adam4667.

    it’s good to hear that your project is successful by using the tutorial provided. 🙂 But you have to try it out yourself, I did this during my Intern 🙂 Now I am doing my own FYP and I do it myself and have no extra time to try it out for you. All the best to you 🙂

  5. Hi, if at all I used an l293d motor shield instead of the one you used, will there be any change in the code that you have provided?

  6. Hi kafs,

    You mean l293d ic right? You can still use the same coding, but you have to make sure that the pwm pin and motor pin of the l293d is similar with the coding.

  7. 1). hi, thank you for that insight… for the same project, have you attempted to use the pan and tilt servo mechanism as a camera stand..
    2). as the robot approaches the object being tracked, is there a threshold distance to which the robot should not cross between it and the object or it goes all the way until it touches the robot?

  8. Hi Kafs,
    1. I didnt try to use the pan and tilt servo mechanism as a camera stand.
    2. I just try and error with the threshold of the distance value.

  9. Hi…I buy this project rdy…but I don’t how to do programming to Arduino…pls help me…pls send me code…..

Leave a Reply

Your email address will not be published. Required fields are marked *