Home of RF and Wireless Vendors and Resources

One Stop For Your RF and Wireless Need

Arduino Interfacing with Color sensor diagram,working,code

This app note covers Arduino Interfacing with Color sensor diagram and its working. It describes Color sensor used and mentions arduino code.

About Color sensor

color sensor detector

The color sensor is used to detect RGB coordinates of a color. The color sensor works by emitting a white light on object and recording reflected light using photodiode. Using color filters, photodiode converts amount of light to current.

We will use TCS3200 color sensor for interfacing with arduino uno board for our explaination. The IC TCS3200 consists of current to frequency converter.

These RGB values are processed to find exact color combination. Refer advantages and disadvantages of color sensor for more information.

Following are the pin designations of a color sensor.
GND - Power supply ground
OE - Enable for output frequency (active low)
OUT - Output frequency
S0, S1 - Output frequency scaling selection inputs
S2, S3 - Photodiode type selection inputs
VDD - Voltage Supply

To select color read by photodiode, one can use control pins S2/S3 combination. S2/S3 -> Low/Low selects Red filter
S2/S3 -> Low/High selects Blue filter
S2/S3 -> High/High selects Green filter
S2/S3 -> High/Low refers to no filter

About Arduino board

Arduino board

• Arduino Uno houses ATmega328 microcontroller from ATMEL. This microcontroller contains flash memory (32 KB), RAM (2 KB), 8 bit wide CPU and 1 KB EEPROM.
• It also supports 6 analog pins which reads voltage and not current. Inside, it converts analog measurement to digital for various purposes. It supports digital pins (0 to 13) which can function either as input or output.
• It has various interfaces viz. I2C, digital pins, analog pins, serial communication, USB etc.
• It also has reset pin, power port, crystal oscillator and Tx/Rx LEDs.
• This open source prototype board can be easily programmed using easy to use arduino IDE and USB interfaced between laptop PC and arduino board.
• IDE uses simplified C++ program.
• Board requires 5V DC which can be powered using AC/DC adapter or battery.

Arduino Interfacing with Color sensor diagram and its working

The figure depicts interfacing of color sensor with arduino uno board.

Arduino Interfacing with Color sensor

Both arduino and color sensor are interfaced as per following table.

Color sensor TCS3200 Arduino board
S0 Pin 4
S1 Pin 5
Vcc +5V
S2 Pin 7
S3 Pin 6
OUT Pin 8
GND GND

Arduino Color sensor interface code

Following is the arduino code compiled and uploaded to the arduino board using Arduino IDE.

// TCS3200 pins connections with arduino board
#define S0 4
#define S1 5
#define S2 6
#define S3 7
#define sensorOut 8

// frequency read by the photo-diodes are stored in following variables
int redFrequency = 0;
int greenFrequency = 0;
int blueFrequency = 0;

void setup() {

pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
pinMode(S3, OUTPUT);

pinMode(sensorOut, INPUT);

digitalWrite(S0,HIGH);
digitalWrite(S1,LOW);

Serial.begin(9600);
}
void loop() {
digitalWrite(S2,LOW);
digitalWrite(S3,LOW);

// Reading the output frequency
redFrequency = pulseIn(sensorOut, LOW);

Serial.print("R = ");
Serial.print(redFrequency);
delay(100);

digitalWrite(S2,HIGH);
digitalWrite(S3,HIGH);

// Reading the output frequency
greenFrequency = pulseIn(sensorOut, LOW);

Serial.print(" G = ");
Serial.print(greenFrequency);
delay(100);

// Setting BLUE (B) filtered photodiodes to be read
digitalWrite(S2,LOW);
digitalWrite(S3,HIGH);

blueFrequency = pulseIn(sensorOut, LOW);

Serial.print(" B = ");
Serial.println(blueFrequency);
delay(100);v }

if (mqtt.connected())
{
colour_value.publish(Red_value);
colour_value.publish(Green_value);
colour_value.publish(Blue_value);
}

Conclusion: In this application note we have seen Color sensor interfacing with Arduino Uno board. Arduino board is also used for interfacing different types of sensors for applications. The typical sensors interfaced with arduino are sound sensor, gyro sensor, LDR sensor, GPS sensor, heartbeat sensor, pH sensor etc.

IoT system on chip tutorial Related Links

This tutorial section on IoT (Internet of Things) covers following sub topics:
Main tutorial  IoT section  IoT article  Cellular IoT  Components  Sensors  INDIAN companies  Antenna Types  Wireless technologies  IoT transceiver  SoC 


RF and Wireless Terminologies


Share this page

Translate this page