Ce Lab Project
Ce Lab Project
ME – 339
DE 40 – ME-A
PROJECT REPORT
TITLE: MOVEMENT CONTROL OF AUTONOMOUS VEHICLE USING
COLOUR SENSORS
GROUP MEMBERS:
M ALI FAHAD REG # 280803
UMAR SHERAZ REG # 280807
SUBMITTED TO:
LE HASSAN MEHMOOD
INTRODUCTION
In this project we will control the movement of autonomous vehicle using colour sensors. Motion of car will be
controlled by use of colour sensors to decide whether it has to stop or move. Here, we will use 2 colours RED
and GREEN. If sensor detects red colour then car will stop automatically and if it detects green colour then it
will start moving and third case if there is no colour detection it will continue its previous state either moving
or stop. We will be using arduino for the processing purpose that will take input from the sensors and then
according to the installed program it will take decisions as above mentioned.
COMPONENTS REQUIRED
Arduino Mega
DC Motors
L298N Motor Driver Module
TCS3200 (RGB + Clear) Color Sensor Module
Breadboard
Power supply
Connecting wires
SCHEMATIC DIAGRAM
CALCULATIONS
In schematic diagram we have used signal generator instead of tcs3200 colour sensor due to unavailability of
libraries of sensor. This signal generator will produce the corresponding frequencies of the lights which will be
acting as an input for microcontroller and processed further for motor controls.
The below frequencies are the actual frequencies ranges of the light colours but our controller is 8-bit so it will
be converted into 0 – 255 during data logging.
RED LIGHT
GREEN LIGHT
Wavelength: 534–545 nm
PINOUT DIAGRAM
FEATURES & SPECIFICATIONS
Microcontroller ATmega2560
Operating Voltage 5V
SRAM 8 KB
EEPROM 4 KB
LED_BUILTIN 13
Length 101.52 mm
Width 53.3 mm
Weight 37 g
This L298N Motor Driver Module is a high power motor driver module for driving DC and Stepper Motors. This
module consists of an L298 motor driver IC and a 78M05 5V regulator. L298N Module can control up to 4 DC
IN1 & IN2 Motor A input pins. Used to control the spinning direction of Motor A
IN3 & IN4 Motor B input pins. Used to control the spinning direction of Motor B
The L298N Motor Driver module consists of an L298 Motor Driver IC, 78M05 Voltage Regulator, resistors,
or equal to 12V, then the internal circuitry will be powered by the voltage regulator and the 5V pin can be
used as an output pin to power the microcontroller. The jumper should not be placed when the power supply
is greater than 12V and separate 5V should be given through 5V terminal to power the internal circuitry.
ENA & ENB pins are speed control pins for Motor A and Motor B while IN1& IN2 and IN3 & IN4 are direction
control pins for Motor A and Motor B.
Internal circuit diagram of L298N Motor Driver module is given below:
Drive DC motors.
Drive stepping motors
In Robotics
TCS3200 COLOR SENSOR MODULE
This Arduino compatible TCS3200 color sensor module consist of a TAOS TCS3200 RGB sensor chip and 4 white
LEDs. The main part of the module is the TCS3200 chip which is a Color Light-to-Frequency Converter. The
white LEDs are used for providing proper lighting for the sensor to detect the object colour correctly. This chip
can sense a wide variety of colours and it gives the output in the form of corresponding frequency. This
module can be used for making colour sorting robots, test strip reading, colour matching tests etc.
The TCS3200 chip consists of an 8 x 8 array of photodiodes. Each photodiode have either a red, green, or blue
filter, or no filter. The filters of each color are distributed evenly throughout the array to eliminate location
bias among the colors. An internal circuit includes an oscillator which produces a square-wave output whose
frequency is proportional to the intensity of the chosen color.
PIN CONFIGURATION
PIN PIN
NAME NUMBER DESCRIPTION
GND 4 Power supply ground. All voltages are reference to the ground.
WORKING (We will be using only red and green colour lights)
The sensor has four different types of filter covered diodes. In the 8 x 8 array of photodiodes, 16 photodiodes
have Red filters, 16 have Blue filters, 16 have Green filters and the rest 16 photodiodes are clear with no
filters. Each type can be activated using the S2, S3 selection inputs. Since each photodiodes are coated with
different filters each of them can detect the corresponding colours. For example, when choosing the red filter,
only red incident light can get through, blue and green will be prevented. By measuring the frequency, we get
the red light intensity. Similarly, when choose other filters we can get blue or green light.
We can also set the frequency scaling option by using the S0, S1 select lines. Normally, in Arduino 20%
frequency scaling is used.
L L Power down
L H 2%
H L 20%
H H 100%
S2 S3 PHOTODIODE TYPE
L L RED
L H BLUE
H H GREEN
FEATURES AND SPECIFICATIONS
e.g.:
digitalWrite(S2, LOW);
digitalWrite(S3, LOW); //Activating photodiode with red filter
red = pulseIn(outpin, LOW);
Here we get the value corresponding to the red color component of the object color.
Similarly, we’ve to activate each photodiodes by changing the S2 and S3 states and read the corresponding
values of green and blue colour components of the object colour.
For a Red object we get an approximate value of red=16, green=53 and blue=45. This may vary from ambient
light and experiment setup. For good results, it’s better to cover the object and sensor from ambient light.
Programming Logic
First set the input pins as input and output pins as output. No need to use analog pins.
Set S0 and S1 to high or low to set desired frequency scaling.
In loop, activate each filters by setting S2 and S3 to HIGH or LOW and measure output frequency ‘fo’
from 6th pin to get corresponding colour intensity. Compare frequencies of each colour to determine the
colour of the object.
CODE
/*
Initialize the variables
for colour sensor
*/
int red;
int green;
String sensedColour = "none";
int delayTime = 0;
/*
Initialize the variables
for motor driver
*/
int leftMotorForward = 9;
int leftMotorBackward = 10;
int rightMotorForward = 11;
int rightMotorBackward = 12;
/*
Set pin 9, 10, 11
and 12 as output
*/
for (int i = 9; i < 13; i = i + 1) {
pinMode(i, OUTPUT);
void loop() {
readColour();
checkColour();
delayTime = 2000;
delay(delayTime);
stop(); //A function to stop the car
sensedColour = "none"; //Sets the sensed colour as ‘None’
delayTime = 2000;
delay(delayTime);
front(); //Function to move the car
sensedColour = "none"; //Sets the sensed colour as ‘None’
else
sensedColour = "none"; //Sets the sensed colour as ‘None’
}
//function to stop the car
void stop() {
digitalWrite(leftMotorForward, LOW);
digitalWrite(rightMotorForward, LOW);
delay(delayTime);
}
void front() {
digitalWrite(leftMotorForward, HIGH);
digitalWrite(rightMotorForward, HIGH);
delay(delayTime);
}
if (red > green and red > 8) { //If the colour is red......
else if (green > red and green > 8) { //If the colour is green......
else
sensedColour = "none";
}
Videos Links:
https://drive.google.com/file/d/1jQYAjZev3v51XJWsCZtDBYd8_JdW6zSv/view?usp=sharing
https://drive.google.com/file/d/1VZ3YN9MN2b2orc-iajPcIXylmWISNnfo/view?usp=sharing
References
https://components101.com/tcs3200-color-sensor-module
https://www.everythingrf.com/rf-calculators/wavelength-to-frequency
https://www.google.com/search?sxsrf=ALeKk00VeZf9z0EWDbhhhY9sajWfI959ag
%3A1611237509808&ei=hYgJYN7rMOXA8gKYqre4Dw&q=red+and+green+light+frequencies+for+colour+senso
r&oq=red+and+green+light+frequencies+for+colour+sensor&gs_lcp=CgZwc3ktYWIQAzIECAAQRzIECAAQRzIEC
AAQRzIECAAQRzIECAAQRzIECAAQRzIECAAQRzIECAAQR1DZ8wNYw7IEYJm5BGgAcAN4AIABAIgBAJIBAJgBAKAB
AaoBB2d3cy13aXrIAQjAAQE&sclient=psy-ab&ved=0ahUKEwiewq67l63uAhVloFwKHRjVDfcQ4dUDCA0&uact=5
https://www.hackster.io/shreyas_arbatti/color-controlled-car-using-tcs3200-color-sensor-64fd35