Page 1
Welcome! Thank you for purchasing our AZ-Delivery TCS3200 Color Sensor Module. On the following pages, you will be introduced to how to use and set-up this handy device. Have fun!
Page 2
Areas of application Education and teaching: Use in schools, universities and training institutions to teach the basics of electronics, programming and embedded systems. Research and development: Use in research and development projects to create prototypes and experiments in the fields of electronics and computer science. Prototype development: Use in the development and testing of new electronic circuits and devices.
Page 3
consult a doctor. Caution: Keep the product out of the reach of children and pets to avoid accidental contact and swallowing of small parts. Note: Store the product in a safe, closed container when not in use. Attention: Avoid contact of the product with food and drinks.
Page 4
Table of Contents Introduction....................3 Specifications....................4 The pinout.....................5 How to set-up Arduino IDE................7 How to set-up the Raspberry Pi and Python..........11 Connecting the sensor with Atmega328p............12 Sketch example..................13 Connectiong the sensor with Raspberry Pi..........18 Python script....................19 - 2 -...
Page 5
Introduction The TCS3200 color sensor is a RGB color detector, which includes a TAOS TCS3200 RGB sensor chip and 4 white LEDs. The sensor has an 8x8 array of photodiodes and Current-to-Frequency converter integrated in one chip. Each photodiode has a filter for either a red, green, or blue color, or with no filter.
Page 6
Specifications » Operating voltage range: from 2.7V to 5.5V DC » Supply current: Power-on mode 2mA Power-down mode 0.1uA » Operting temperature range: from -40°C to 70°C » Output frequency scaling selection inputs: S0 and S1 » Filter type selection inputs: S2 and S3 »...
Page 7
The pinout The TCS3200 color sensor module has eight pins. The pinout diagram is shown on the following image: The output of the sensor (on the OUT pin) is a square wave with a 50% duty cycle with frequency directly proportional to the light intensity (irradiance).
Page 8
Pins S2 and S3 are used for color filter selection: Color filter HIGH Blue HIGH No filter (clear) HIGH HIGH Green - 6 -...
Page 9
How to set-up Arduino IDE If the Arduino IDE is not installed, follow the link and download the installation file for the operating system of choice. For Windows users, double click on the downloaded .exe file and follow the instructions in the installation window. - 7 -...
Page 10
For Linux users, download a file with the extension .tar.xz, which has to be extracted. When it is extracted, go to the extracted directory and open the terminal in that directory. Two .sh scripts have to be executed, the first called arduino-linux-setup.sh and the second called install.sh.
Page 11
Almost all operating systems come with a text editor preinstalled (for example, Windows comes with Notepad, Linux Ubuntu comes with Gedit, Linux Raspbian comes with Leafpad, etc.). All of these text editors are perfectly fine for the purpose of the eBook. Next thing is to check if your PC can detect an Atmega328p board.
Page 12
If the Arduino IDE is used on Windows, port names are as follows: For Linux users, for example port name is /dev/ttyUSBx, where x represents integer number between 0 and 9. - 10 -...
Page 13
How to set-up the Raspberry Pi and Python For the Raspberry Pi, first the operating system has to be installed, then everything has to be set-up so that it can be used in the Headless mode. The Headless mode enables remote connection to the Raspberry Pi, without the need for a PC screen Monitor, mouse or keyboard.
Page 14
Connecting the sensor with Atmega328p Connect the TCS3200 color sensor with the Atmega328p as shown on the following connection diagram: Sensor pin > Mc pin > 5V Red wire > GND Black wire > GND Black wire > D6 Blue wire >...
Page 15
Sketch example For this sketch example, no external library is used. The following is code for sketch example: #define #define #define #define #define uint16_t frequency = 0; void stop_all() { digitalWrite(S0, LOW); digitalWrite(S1, LOW); digitalWrite(S2, LOW); digitalWrite(S3, LOW); void read_20() { // Setting frequency-scaling to 20% digitalWrite(S0, HIGH);...
Page 17
Upload the sketch to the Atmega328p and open the Serial Monitor (Tools > Serial Monitor). The result should look like on the following image: To get these values, put colored paper with blue, red or green colors in front of the sensor. The values that are not selected are the values when there is no obstacle in front of the sensor.
Page 18
At the beginning of a sketch five macros are created, which represent digital I/O pin numbers of the Atmega328p on which pins of the sensor are connected. After macros the integer variable called frequency is created. This variable represents output frequency on the OUT pin of the sensor. Next, two functions are created.
Page 19
After this the filters for red color are set, with the following lines of code: digitalWrite(S2, LOW); digitalWrite(S3, LOW); Then, the pulsein() function is used to read the pulse length on the OUT pin. The pulsein() function has two arguments and returns an integer value.
Page 20
Connectiong the sensor with Raspberry Pi Connect the TCS3200 color sensor with the Raspberry Pi as shown on the following connection diagram: Sensor pin > Raspberry Pi pin > 3V3 [pin 17] Red wire > GND [pin 9] Black wire >...
Page 21
Python script The following code is modified code from a script which can be found at the following link. import RPi.GPIO GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) NUM_CYCLES GPIO.setup(OUT, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(S0, GPIO.OUT) GPIO.setup(S1, GPIO.OUT) GPIO.setup(S2, GPIO.OUT) GPIO.setup(S3, GPIO.OUT) turn_off(): GPIO.output(S0, GPIO.LOW) GPIO.output(S1, GPIO.LOW) GPIO.output(S2, GPIO.LOW) GPIO.output(S3, GPIO.LOW)
Page 22
print('[Press CTRL + C to end the script!]') try: set_scalers() while True: # setting red filters GPIO.output(S2, GPIO.LOW) GPIO.output(S3, GPIO.LOW) time.sleep(0.3) start time.time() impulse_count range(NUM_CYCLES): GPIO.wait_for_edge(OUT, GPIO.FALLING) duration time.time() start # seconds to run for loop NUM_CYCLES duration # in Hz print('Red value: {}'.format(red)) # setting blue filters...
Page 24
Save the script by the name color.py. To run the scirpt open the terminal in the directory where the script is saved and run the following command: python3 color.py The result should look like the output on the following image: To end the script press CTRL + C on the keyboard.
Page 25
The script starts with importing two libraries, RPi.GPIO and time libraries. Next, the GPIO pin naming is set to BCM and all warnings for using GPIO interfaces are desabled Then, six variables are created, where S0, S1, S2, S3 and OUT variables represent the pins of Raspberry Pi on which pins of sensor are connected.
Page 26
Next, the try-except-finally block of code is created. In the try block of code, first, the set_scalers() function is executed after which the indefinite loop block of code is created (while True:). In the indefinite loop of code the same thing as in loop() function of the Atmega328p is done.
Page 27
If you are looking for the high quality microelectronics and accessories, AZ-Delivery Vertriebs GmbH is the right company to get them from. You will be provided with numerous application examples, full installation guides, eBooks, libraries and assistance from our technical experts.
Need help?
Do you have a question about the TCS3200 and is the answer not in the manual?
Questions and answers