Color Sensor Module

From Wiki

Jump to: navigation, search

Contents

Introduction

The Color sensor module base on TCS3200 which is a programmable color light-to-frequency converter, it could filter RGB data from source light and convert it to a square wave(50% duty cycle) with frequency directly proportional to light intensity (irradiance). The full-scale output frequency can be scaled by one of three preset values via two control input pins(SO, S1 Selectable Options 2%, 20%, 100% frequency),and pin S2, S3 control the filter of RGB. Digital inputs and digital output allow interface to a microcontroller or other logic circuitry directly. Output enable (OE) places the output in the high-impedance state for multiple-unit sharing of a microcontroller input line. At last, user ​​can calculate the color of the light by RGB values.
Model: SCO010
TSC230.jpg

Feature

Cautions

Schematic

TSC230-7.jpg

Specification

Pin definition and Rating

TSC230-6.jpg

Mechanic Dimensions

Usage

Hardware Installation

The module works at 5V, you can use Arduino for power supply directly. The White Color Sensor has shorted LED to GND by a short circuit Block Cap. The four white highlight LEDs in the surrounding are providing a source constant light.

The Demo pins to Arduino as below:

GND & LED – GND , OE – GND, VCC – VCC, S0 – D6, S1 – D5, S2 – D4, S3 – D3, OUT – D2


Here OE connects to GND that means the module was always enable. The OUT(Signal pin) is output of a square wave (50% duty cycle) with frequency directly proportional to light intensity (irradiance). Most Arduino boards have two external interrupts: numbers 0 (on digital pin 2) and 1 (on digital pin 3). So we connect OUT to D2 for counting the square wave frequency using external interrupt 0.

So you need an other timer library which is a collection of routines for configuring the 16 bit hardware timer called Timer1 on the ATmega168/328 . Get the Timer1 Library.

Programming

Includes important code snippet. Demo code like :

/*********************************************************************
**  Device: TSC230                                                  **
**  File:   EF-TSC230.c                                             **
**								    **
**  Created by ElecFreaks Robi.W /6 Sep 2011                        **
**                                                                  **
**  Description:                                                    **
**  This file is a sample code for your reference.Just a demo for   **
**  TSC230 Programmable Color Light-to-Frequency Converter Module.  **
**                                                                  **
**  This demo code is free software; you can redistribute it and/or **
**  modify it under the terms of the GNU Lesser General Public	    **
**  License as published by the Free Software Foundation; either    **	
**  version 2.1 of the License, or (at your option)   		    **
**  any later version.						    **
**                                                                  **
**  Copyright (C) 2011 ElecFreaks Corp.                     	    **
**                                                                  **
**                                                                  **
**  http://www.elecfreaks.com                                       **
*********************************************************************/
 
#include <TimerOne.h>

#define S0     6
#define S1     5
#define S2     4
#define S3     3
#define OUT    2

int   g_count = 0;    // count the frequecy
int   g_array[3];     // store the RGB value
int   g_flag = 0;     // filter of RGB queue
float g_SF[3];        // save the RGB Scale factor
 
 
// Init TSC230 and setting Frequency.
void TSC_Init()
{
  pinMode(S0, OUTPUT);
  pinMode(S1, OUTPUT);
  pinMode(S2, OUTPUT);
  pinMode(S3, OUTPUT);
  pinMode(OUT, INPUT);
 
  digitalWrite(S0, LOW);  // OUTPUT FREQUENCY SCALING 2%
  digitalWrite(S1, HIGH); 
}
 
// Select the filter color 
void TSC_FilterColor(int Level01, int Level02)
{
  if(Level01 != 0)
    Level01 = HIGH;
 
  if(Level02 != 0)
    Level02 = HIGH;
 
  digitalWrite(S2, Level01); 
  digitalWrite(S3, Level02); 
}
 
void TSC_Count()
{
  g_count ++ ;
}
 
void TSC_Callback()
{
  switch(g_flag)
  {
    case 0: 
         Serial.println("->WB Start");
         TSC_WB(LOW, LOW);              //Filter without Red
         break;
    case 1:
         Serial.print("->Frequency R=");
         Serial.println(g_count);
         g_array[0] = g_count;
         TSC_WB(HIGH, HIGH);            //Filter without Green
         break;
    case 2:
         Serial.print("->Frequency G=");
         Serial.println(g_count);
         g_array[1] = g_count;
         TSC_WB(LOW, HIGH);             //Filter without Blue
         break;
 
    case 3:
         Serial.print("->Frequency B=");
         Serial.println(g_count);
         Serial.println("->WB End");
         g_array[2] = g_count;
         TSC_WB(HIGH, LOW);             //Clear(no filter)   
         break;
   default:
         g_count = 0;
         break;
  }
}
 
void TSC_WB(int Level0, int Level1)      //White Balance
{
  g_count = 0;
  g_flag ++;
  TSC_FilterColor(Level0, Level1);
  Timer1.setPeriod(1000000);             // set 1s period
}
 
void setup()
{
  TSC_Init();
  Serial.begin(9600);
  Timer1.initialize();             // defaulte is 1s
  Timer1.attachInterrupt(TSC_Callback);  
  attachInterrupt(0, TSC_Count, RISING);  
 
  delay(4000);
 
  for(int i=0; i<3; i++)
    Serial.println(g_array[i]);
 
  g_SF[0] = 255.0/ g_array[0];     //R Scale factor
  g_SF[1] = 255.0/ g_array[1] ;    //G Scale factor
  g_SF[2] = 255.0/ g_array[2] ;    //B Scale factor
 
  Serial.println(g_SF[0]);
  Serial.println(g_SF[1]);
  Serial.println(g_SF[2]);
 
}
 
void loop()
{
   g_flag = 0;
   for(int i=0; i<3; i++)
    Serial.println(int(g_array[i] * g_SF[i]));
   delay(4000);
 
}

Example

The projects and application examples.

FAQ

Please list your question here:

Support

If you have questions or other better design ideas,

Version Tracker

Revision Descriptions Release
v1.0b Initial public release date

Bug Tracker

Bug Tracker is the place you can publish any bugs you think you might have found during use. Please write down what you have to say, your answers will help us improve our

products.

Resources

How to buy

Click here to buy: http://www.elecfreaks.com/estore/color-sensor-module-colsen01.html

See Also

Other related products and resources.

Licensing

This documentation is licensed under the Creative Commons Attribution-ShareAlike License 3.0 Source code and libraries are

licensed under GPL/LGPL, see source code files for details.

External Links

Links to external webpages which provide more application ideas, documents/datasheet or software libraries

Personal tools
Namespaces
Variants
Actions
Navigation
Support
Toolbox