You are on page 1of 10

10/5/2019 TCS230 RGB color sensor operation and Code

 ravi@valetron.com (mailto:ravi@valetron.com)
(/)  

TCS230 RGB color sensor operation and Code


 Ravi Pujar  21 March 2015

The TAOS TCS230 is the most widely used color sensor by hobbyists and embedded system
practitioners. TCS230 is a RGB color sensor which provides the intensity value of Red, Green
and Blue colors detected at its input lens. The output is available on a single pin in the form
of a square wave.

Here is the image and the block diagram of the TCS230 color sensor,

The first block that comes into picture is the Photodiode array. The photodiode array consists
of three sets of diodes each for sensing Red, Green and Blue color respectively. So, when you
are measuring the intensity of Red light you need to enable only the Red photodiode array
and disable the other two photo diode arrays.

The output enable pin is generic output enable pin which turns the square wave output
ON/OFF.

Detecting the color: The TCS230 color sensor is having only one output pin on which a 50%
duty cycle square wave is output continuously.

https://www.raviyp.com/embedded/135-taos-tcs230-color-sensor

1/10
10/5/2019 TCS230 RGB color sensor operation and Code

First we need to make the OE pin low to enable the sensor output, and then make the S0 = 1,
(/)scaled squarewave output.
S1 = 0 to select a 20%  
When we are measuring the color of any object in front of the sensor, we need to perform
the measurement in three steps,

1. Measure the Red color: To enable only the Red photo diode array by making S2=0, S3=0.
Wait for sometime and measure the time period of the square wave on the output
pin by enabling only Red photodiode array. 
2. Measure the Blue color: To enable only the Blue photo diode array by making S2=0,
S3=1. Wait for sometime and measure the time period of the square wave on the output
pin by enabling only Blue photodiode array. 
3. Measure the Green color: To enable only the Green photo diode array by making S2=1,
S3=1. Wait for sometime and measure the time period of the square wave on the output
pin by enabling only Green photodiode array. 

After you get the values of the Red, Green and Blue components, you can get the name of the
color from any RGB color table. You can also measure the light intensity on the sensor by
disabling color filters. To measure the light iintensity disbale the color filters by making S2=1,
S3=0. Wait for sometime and measure the time period of the square wave on the output pin.

Code for Color sensor TCS230 using PIC16F877A:

Here i have configured the PIC's timer module in capture mode where i measure the square
waves time period. The color sensors output is connected to the timers capture input pin. To
measure RED color, i enable only the Red color receptors and measure the count in the timer
registers after a delay which gives me the pulse width. 

Here is the piece of code i wrote for PIC16F877A microcontroller. If you want i can share the
libraries code. 

Download the code for TCS230 color sensor with PIC16F877A microcontroller
(/Colour%20sensor_PIC16F877A_CompleteProject.zip)

https://www.raviyp.com/embedded/135-taos-tcs230-color-sensor

2/10
10/5/2019 TCS230 RGB color sensor operation and Code

TCS 230 PIC16F877A code


(/)  
(https://www.raviyp.com/plugins/content/highlight_code/highlight/vista_plan
#include "LCD.h"#include "UART.h"#include "I2C.h"#include "Timer.h"unsignedshort Data[20];un
Print("$");if(10000/Brightness <200){ if(Red < Blue && Red < Green) {
TRISB4 =0; // colour s2 s3 TRISDbits.TRISD1=0; TRISDbits.TRISD0=0; // led
InitInterrupts();
InitTimer1();
StartTimer1(); RD2 =1;
RD3 =0; Colour =1;while(1) { switch(Colour) {
Count = CCPR1;
TMR1H =0x00;
TMR1L =0x00; CCP1IF =0; } if(TMR1IF ==1) {
TMR1H =0x00;
TMR1L =0x00;
TMR1IF =0;
over =1;} }

Circuit diagram for interfacing TCS230 RGB color sensor with PIC16F877A
microcontroller :

https://www.raviyp.com/embedded/135-taos-tcs230-color-sensor

3/10
10/5/2019 TCS230 RGB color sensor operation and Code

(/)  

Code for Color sensor TCS230 using 8051/89S52/89C51 microcontroller:

The output of the color sensor is connected to INT0 of 8051 microcontroller. The
microcontroller uses the timer module to measure the time period of the square wave
pulses. The objective of the code is to detect the color as RED,BLUE,GREEN and move a
stepper motor to a particular position.

Here is a piece of code i wrote for interfacing TCS230 color sensor with 89s52/8051
microcontroller. 

Download the code for TCS230 color sensor with 89s52/8051 microcontroller
(/Colour%20sensor_8051_89S52_CompleteProject.zip)

https://www.raviyp.com/embedded/135-taos-tcs230-color-sensor

4/10
10/5/2019 TCS230 RGB color sensor operation and Code

TCS 230 8051 code


(/)  
(https://www.raviyp.com/plugins/content/highlight_code/highlight/vista_plan

ignedshort GapDuration =0;

1;mot2 =0; mot3 =1; mot4 =1; Delay(500); mot1 =0;mot2 =1; mot3 =1; mot4 =1;
DisplayString(LINE4,"250 KG = ",BlueBags,DATA_WRITE);} void SendPacket(void){//GIE = 0; Print

SERV_MOTOR1 =0; SERV_MOTOR2 =0; Delay(40000); SERV_

17 Comments Embedded World 


1 Login

 Recommend t Tweet f Share Sort by Best

Join the discussion…

LOG IN WITH
OR SIGN UP WITH DISQUS ?

Name

Guest • 6 years ago


hi I have conect with dspic30f4011....I need it for my proyect.....Thank you.....the compilator
program is mikro c..........
https://www.raviyp.com/embedded/135-taos-tcs230-color-sensor
 5/10
10/5/2019 TCS230 RGB color sensor operation and Code
3△ ▽ • Reply • Share ›
(/)
Charushila Khandait • 2 months ago
 
there is blank cuvette between tcs230 sensor and red led ....from sensor we get 740khz and
red light wavelength is 640nm means 156 khz ....whats the corelation between 156hz and 740
hz ...why thre is difference after getting output ,as expected result to be 740khz as it is at
output for red led...
even m not getting how to calculate exact number of pulses???? plz ans it
△ ▽ • Reply • Share ›

rinshad s • 3 years ago


hi RAVI PUJAR,
can i get a 7 colors using RGB sensor. can u send me the code for that {PIC}.
My project is color mixing machine so can u please send a program or details of that also.
rinshad837@gmail.com
△ ▽ • Reply • Share ›

Ravi Pujar Mod > rinshad s • 3 years ago


Hi,
You can detect any color combination but there will be errors due to analog nature of
sampling pulse width. And timer precision. This is the only code i have in this blog. Don't
have backup of this code with me.
△ ▽ • Reply • Share ›

Hashan Rashmi Perera • 4 years ago


Hi Ravi Pujar , I m hashan, I m using TC3200 color sensor and PIC16F877A.I downloaded
your code.I opened and built it using by MPLABX IDE,it s shows some errors .I cant solve
these errors ...please help me

△ ▽ • Reply • Share ›
https://www.raviyp.com/embedded/135-taos-tcs230-color-sensor
 6/10
10/5/2019 TCS230 RGB color sensor operation and Code

jp • 4 years ago
(/)  
hello...i am using this colour snsor tcs230 in my projct bt it is unable to detect the colour of
cloths...is there any solution of this problm......
△ ▽ • Reply • Share ›

ria • 4 years ago


which software is the best for running this program... i m getting errors while executing the
program ....plz help
△ ▽ • Reply • Share ›

Ravi Pujar Mod > ria • 4 years ago


This code is written for MPLAB IDE using HITECH C compiler for PIC16F and KEIL IDE
for 8051 version of code. I can help if you share the exact error by email.
1△ ▽ • Reply • Share ›

RAGHUVEER > Ravi Pujar • 4 years ago


Hello Sir, I am Raghu.Currently working on TMD3782 color sensor on
PIC18F2550. While I project the object with RGB colors with a light(LED)
reflection on sensor. I am unable to read the data on Logic analyzer. How to
read RGB values with this sensor. Kindly help me out. My Email ID is
raghuveerv1@gmail.com
1△ ▽ • Reply • Share ›

Yew Tze Ee • 5 years ago


What is the resistance for R7, 510E? thanks for the attention.
△ ▽ • Reply • Share ›

Chathuranga Rajugamuwa • 6 years ago


Thank u occur error code1098,237 mplab HI-TECH C Compiler for PIC10/12/16 MCUs (Lite
Mode) V9.83 pls help for this
△ ▽ • Reply • Share ›

ChuDaiHai • 6 years ago


Ravi Pujar: Please, you give me principle diagram of TCS230 conect with PIC16F877A. I need
it for my Project. Thank much!
△ ▽ • Reply • Share ›

Ravi Pujar Mod > ChuDaiHai • 6 years ago


Hi, I have updated the article with circuit diagram for TCS230 interfaced with
PIC16F877A microcontroller.
△ ▽ • Reply • Share ›


TATIANA • 6 years ago
PLEASE, YOU GIVE ME LIBRARIES CODE. I NEED IT FOR MY PROJECT. THX
https://www.raviyp.com/embedded/135-taos-tcs230-color-sensor 7/10
10/5/2019 TCS230 RGB color sensor operation and Code

△ ▽ • Reply • Share ›
(/)
ChuDaiHai > TATIANA • 6 years ago
 
Please, you give me principle diagram of TCS230 conect with PIC16F877A. I need it for
my Project. Thank much!
△ ▽ • Reply • Share ›

Ravi Pujar Mod > TATIANA • 6 years ago


Hi,
I have uploaded the libraries code for interfacing

TCS230 with 8051/89S52 including code for 20x4 line LCD, stepper motor

TCS230 with PIC16F877A including code for 20x4 line LCD

Look at the article for links to download the code.

Regards,
Ravi
△ ▽ • Reply • Share ›

duster > Ravi Pujar • 4 years ago


Ravi sir plzz do give direct link for library files bcoz i dont know exactly which
article u r talking about..
△ ▽ • Reply • Share ›

Show more replies

ALSO ON EMBEDDED WORLD

Google Speech Recognition HTTP API - How to order components from Digikey to
Tutorial with Live Demo .. ! India without Shipping charges
2 comments • a year ago 1 comment • 2 years ago
Tech Seeker — Thanks for the post. I am trying Achiever — Hey, the above mentioned mail-id's
Avatarto get Google speech to text work and am Avatarno more work.... Their new E-mail is
stuck.I appear to form the JSON correctly.Only pallavi@sourcetechnologi.com

Difference between SIM900 and SIM900A Arduino MQTT Library with Publish and
GSM modems Subscribe example
1 comment • 2 years ago 3 comments • a year ago
anbu — hi , I'm not able to send text sms and Najab Haider —
Avatarmaking call upto 10 numbers , i'm using AvatarSoftSerial.print("AT+CIPMODE=0\r\n");Respons

back to top

 tcs 230 (/component/tags/tag/tcs-230) , color sensor (/component/tags/tag/color-sensor)

https://www.raviyp.com/embedded/135-taos-tcs230-color-sensor
 8/10
10/5/2019 TCS230 RGB color sensor operation and Code

 Facebook (http://www.facebook.com/sharer.php?u=https://www.raviyp.com/embedded/135-
(/) taos-tcs230-color-sensor)  
 Twitter (http://twitter.com/share?url=https://www.raviyp.com/embedded/135-taos-tcs230-color-
sensor&text=TCS230%20RGB%20color%20sensor%20operation%20and%20Code)

 (https://plus.google.com/share?url=https://www.raviyp.com/embedded/135-taos-tcs230-color-
sensor)

 (http://www.linkedin.com/shareArticle?mini=true&url=https://www.raviyp.com/embedded/135-
taos-tcs230-color-sensor)

 

About the Author


Ravi Pujar
(https://plus.google.com/102969188306424582103)
is the author of this blog and is an
Embedded systems design engineer by
profession & Founder @ Valetron
Systems Pvt Ltd
(http://www.valetron.com)

(https://plus.google.com/102969188306424582103)

Email:ravi@valetron.com
(mailto:ravi@valetron.com)

Find us on Google+
(https://plus.google.com/104907583360502363516)
HIRE ME FOR YOUR PROJECT AS A
FREELANCER

https://www.raviyp.com/embedded/135-taos-tcs230-color-sensor

9/10
10/5/2019 TCS230 RGB color sensor operation and Code
Ravi Pujar

YouTube (/)
3k  
 

Enter your Email Address

Subscribe

Embedded World
7.1K likes

Like Page

Be the first of your friends to like this

Embedded World
about a week ago

https://www.raviyp.com/…/250-
don-t-buy-components-for-your-

© 2017 Valetron Systems Pvt Ltd. All Rights Reserved.

https://www.raviyp.com/embedded/135-taos-tcs230-color-sensor

10/10

You might also like