• Support
  • Cart
Phinalabs Phinalabs
  • Shop
    • STEM Education
    • Makers
    • Components
    • Tools
  • Lab
    • Fabrication
    • Projects
    • Open Source
  • Education
    • Create.Innovate.Invent
    • Resources & Kits
  • Learn
    • STEM
      • Basics
      • Coding
      • Kits
      • DIY
    • Explore
      • Basic Electronics
      • Microcontrollers
      • Displays
      • Modules
      • Actuators
      • Sensors
    • Industrial & IoT
    • Embedded Systems
      • Embedded C
      • Embedded OS
      • Micropython
      • PCB Making
  • Blog
  • Register
  • Login|
LoginRegister
­
Learn/Explore/Color Sensor TCS3200

Close

Color Sensor TCS3200

By Muchiri John

Share this project

Introduction

A color sensor module makes it easy to detect colors in your project application, that is, red, green and blue components. It has 4 white light LEDs to illuminate the surface of interest.

Module

TCS3200 color sensor

This module is based on TCS3200 programmable color light-to-frequency converters that combine configurable silicon photodiodes and a current-to-frequency converter on a single monolithic CMOS integrated circuit. The output is a square wave (50%duty cycle) with frequency directly proportional to light intensity (irradiance).

TCS3200 Pinout

TCS3200 color sensor

Configuration

TCS3200 color sensor

Part List

We’ll learn how to connect the color sensor to Arduino Uno. Part list needed;

– Color sensor module, TCS3200
– Arduino Uno
– Mini breadboard
– Pack of jumper wires

Wiring

we are going to wire the color sensor to Arduino Uno using the following pin assignments;

Sensor Pin Arduino Pin
 S0  3
 S1  4
 S2  5
 S3  6
 OE  Not Connected
 OUT  2
 GND  GND
 VCC  5V

Breadboard Connections

TCS3200 color sensor

Code

Arduino Code
Arduino code for the tutorial

color_sensor_tcs3200.ino
C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* Connections
*  -------------------
*  Sensor  |   Arduino
*    S0    |     3          
*    S1    |     4
*    S2    |     5
*    S3    |     6
*    OUT   |     2
*    VCC   |     5V
*    GND   |     GND
*  -------------------
*  
*/
 
//macro definition pins
#define S0 3
#define S1 4
#define S2 5
#define S3 6
#define output 2
//variables
uint8_t flag = 0;
volatile uint8_t f_counter = 0;
uint8_t frequency_R = 0, frequency_G = 0, frequency_B = 0;
 
//setup
void setup()
{
  Serial.begin(115200);
  pinMode(S0, OUTPUT);
  pinMode(S1, OUTPUT);
  pinMode(S2, OUTPUT);
  pinMode(S3, OUTPUT);
 
}
 
//loop
void loop()
{
  TCS3200_init();
  while (1);
}
 
//initialize
void TCS3200_init()
{
  flag = 0;
  digitalWrite(S1, HIGH);

How The Code Works

In the macro definitions we assign arduino pins connected to the sensor

C
1
2
3
4
5
6
//macro definition pins
#define S0 3
#define S1 4
#define S2 5
#define S3 6
#define output 2

In the setup functions we set the pins, S0, S1, S2, S3 and S6 as OUTPUTS also initializing serial port with a 115200 baudrate

C
1
2
3
4
5
Serial.begin(115200);
pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
pinMode(S3, OUTPUT);

To count the frequency from the sensor, we attach the pin connected to sensor output, Arduino pin 2, to pin change interrupt using ‘attachInterrupt’ function

C
1
attachInterrupt(digitalPinToInterrupt(output), ISR_INTO, CHANGE);

for the readings of Red, Blue and Green components, we use the configuration settings by either setting the S0, S1, S2, S3 HIGH or LOW using ‘digitalWrite’ function. e.g. To read Red color value you use;

C
1
2
digitalWrite(S2, LOW);
digitalWrite(S3, LOW);

And finally we use Timer 2 set at 10 milliseconds overflow interrupt to get and send readings through serial

C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//interrupt, 10ms
ISR(TIMER2_OVF_vect)
{
  TCNT2 = 100;
  flag++;
  //get red component value
  if (flag == 1)
  {
    frequency_R = f_counter;
    Serial.print("red=");
    Serial.println(frequency_R, DEC);
    digitalWrite(S2, HIGH);
    digitalWrite(S3, HIGH);
  }
.......

Running Code
click ‘Run on Arduino’ to upload code to the Arduino board

Serial Monitor
To view the RGB values use the serial monitor below

Resources

– TCS3200 Datasheet
– Arduino Code
– Wiring Diagram

Share this post

Like this project

Tags

accelerometer Arduino breadboard buzzer color sensor digital input jumper jumpers jumper wires kit learn led LED blinking PIR programming prototyping resistors scratch-n-sketch Scratch_n_Sketch sensors tcs3200 touch

Feedback is closed.


Related Projects

  • thumbnail_unda_project_1

    UNDA Project 1: Flashing Light


    By Mercy Ngoiri

    [fullwidth background_color="" background_image="" background_parallax="none" enable_mobile="no" parallax_speed="0.3" background_repeat="no-repeat"...

  • 3D_rotate

    MMA7361LC 3-Axis Accelerometer


    By Muchiri John

    This Module is a 3-axis Xyz accelerometer using Freescale MMA7361L micromachined ±1.5g or ±6g sensitivity. It's great for a motion sensing or stab...

  • pir_motion_02

    PIR Motion Sensor


    By Muchiri John

    A PIR motion sensor, is a small, low power and inexpensive sensor that is used to sense objects emitting low level radiation e.g humans, cats, dogs...

  • touch_sensor

    Touch Sensor


    By Dennis

    If you are interested in adding the ‘magic’ of touch to control your electronics project, a capacitive touch sensor module might be the way to go. ...

  • ard_piezo_image

    Piezo Buzzer


    By Dennis

    This tutorial shows how to hook up a piezo buzzer and an Arduino Uno board to make a simple sound alarm whose volume can be adjusted . The buzzer i...

  • Arduino_Logo

    Arduino : Getting Started


    By Mercy Ngoiri

    In this lesson we will learn how to set up the computer to get started with Arduino, that is, downloading and installing the software and then open...

  • Arduino_Logo

    Arduino : Introduction


    By Muchiri John

    Arduino is an open-source prototyping platform based on easy-to-use hardware and software. Arduino boards are able to read inputs - light on a sens...

Sections

  • Introduction
  • Part List
  • Wiring
  • Code
  • Resources
Paginate View
Feedback
Get Updates

Customer Service

  • Contact Page
  • Support
  • Distributors
  • FAQ Page

Terms of Use

  • Shipping & Returns
  • Terms of Service

About Us

:: Phinalabs designs and manufactures electronics and provides a platform - tools, resources, and content for our partners and community of makers, DIYers, engineers, students, innovators, and inventors to build, learn, connect, inspire, and turn ideas into reality.

"Where there is no vision, there is no hope."
George Washington Carver