Raspberry PI Based Line Following Robot

A light sensor works by reflecting a bright light onto the object and through IR it reflects the brightness of the colour which in turn is converted to a colour, based on its RGB values. This main aim of this paper is to compare results when detecting colours using the colour sensor (rev-31-1154) and the raspberry pi Camera v2. 

The colour sensor (rev-31-1154) has a built-in IR (optical) and its main feature is that it allows the user to return all the colour and status data in one read command, which makes the process faster and more accurate.  The PICamera is a powerful tool which not only takes still and moving images but also has the capability to detect colour based on RGB filters.

To be able to detect colours using the latter, openCV library will be installed and its functions will be called and modified using python. In order to detect the colours, the same experiment will be set up and tested using the colour sensor and the PI Camera module.

To test this experiment various coloured cubes 3cms x 3cms x 3 cms will be placed in front of different coloured squares 5cms x 5cms.  The result of this experiment is to identify the best option which yields the optimum results vis-à-vis accuracy and efficiency will be integrated into our robot and used for the tournament.


With the advent of Computer and Internet technologies, Human started to find the sophisticated ways to sooth themselves with the aid of modern technologies. For this purpose he started to propose the concepts and ideas where human input can be reduced at its epitome level. These theoretical assumptions came into being existence when Nest Inc.

invented the Nest Learning Thermostat in 2011 as its First product. This thermostat has the capability to learn the behavior of human against its daily usage of Air cooling units Like AC and Fans etc. Automated system requires Computer vision and real-time image processing.

Applications are being Developed and implemented to include detection software, facial Recognition apps, object and colour tracking.  The Aim of  this paper is to detect and identify colours and compare results when detecting colours the raspberry pi Camera v2 and using the colour sensor this paper is to test colour detection in the “Red, Green, Yellow Zones”.

Testing will be carried out using the PI Cam and the colour sensor. Data of both components will be analysed and the most accurate and efficient component will be used for this competition. 

Raspberry Pi Robot
Raspberry Pi Robot


The purpose of colour sensors is to record the intensity of the brightness of the colour through RGB filters. The photodiode converts the amount of light to current and the robot will in turn perform the requested instructions, such as following a particular colour. Carried out an experiment were they used coloured lines and instructed the robot to move along a particular line and detect other colours as “obstacles”. Through continuous data from sensor the robot is capable of correcting itself accordingly to follow the “target” colour.   

Given that the PI camera can capture HD video it can be easily used with OpenCV to detect colours and objects. An experiment to interpret the real world visually through computers and detect objects has been carried out by through OpenCV and Raspberry PI based applications.

As a result, by reading pixel values of frames captured by the RPI camera, objects were detected and traced. Similar hardware and software specifications were used in an experiment carried out by the authors used RPI camera to detect skin colour, store the colour in RGB and convert to HSI. An algorithm was developed to enhance the image in different enhancement degree


The PI Camera was set up OpenCV library includes various methods and algorithms. One of the most useful function in this library is the in Range (image, lower, upper) which accepts three arguments and the range of colours to detect, usually set in RGB.  

The robot was built using the First Global REV Robotics Kit and camera sensors were fixed to the frontal area. The robot awaits start instructions from a tablet and follows a set of commands to detect colour objects. Commands were implemented using Google Blockly software


A game board similar to the one used for the ECER competition has been built. Zones have been set up for testing purposes. The code starts by switching on the camera and allowing a few seconds to warm up.

NumPy and OpenCV library are required to produce the optimum results for colour detection. NumPy creates arrays to hold the lower and upper range and a mask is created for the image. First the algorithm checks for the orange colour.

If an orange colour is found, then the algorithm searches for green, red and yellow colours. Using the OpenCV function rotatedRectangleIntersection(), we print if there is any intersection between the two colours or not. This is done to minimise wrong readings. Through OpenCV a border around the detected colours is drawn for visual readings.

Block diagram of Raspberry Pi
Block diagram of Raspberry Pi

In this proposed system, Raspberry pi is connected with the USB camera where open CV is used for the line follow using the ROI which will help the robot to achieve accuracy accordingly

Raspberry Pi Kit
Raspberry Pi Kit


Line following robot based industrial manufacturing process in Bangladesh can play a vital role in the field of industry. Using this robot in the government organization and Manufacturer Company, especially the RMG sectors in Bangladesh, the cost for the manpower can be reduced.

This line following robot can be used as carrying the load to deliver the goods from one place to another smoothly without any damage. If any type of goods mishandling occurs then that system can stop its routine function and call to the system administrator to check the occurred problem to repair. 

For this purpose, a GSM module can be used to monitor the production process in real time basis. In real time basis, the functional work of any industry can be more efficient for supply chain management so that the industrial sectors of Bangladesh will take a place in international markets.

Over All

In this project By using a camera and colour sensor we will move the robot from one place to another place. For that we will use the Raspberry pi and python language for automation or for giving the commands to the robot. The product should be packed in by parts and shipped to the location of assembly.

the assembled product will require will require large and study container during shipping. This can be thick cardboard with Styrofoam to spread the weight of the robot evenly across the surface of the container, thus decreasing the pressure and possibility of breaking the box