Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Arduino Nano and TSC230 color sensor

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-ARDUINO
View previous topic :: View next topic  
Author Message
bzijlstra

Bascom Ambassador



Joined: 30 Dec 2004
Posts: 1179
Location: Tilburg - Netherlands

netherlands.gif
PostPosted: Fri Sep 05, 2014 10:43 am    Post subject: Arduino Nano and TSC230 color sensor Reply with quote

TSC230 - Color Sensor



Single-supply operation 2.7 to 5.5 volt
High-resolution conversion of light intensity to frequency
Programmable color and full-scale output frequency
Output frequency: 5 volt
Duty cycle: 50%
Distance to object: max 10 mm

Value of RGB between 1200 and 3500, with this Bascom-AVR program.

S0 and S1: Output frequency scaling selection inputs
S2 and S3: photodiode type selection inputs
Out: Output frequency
OE pin: Output frequency enable pin (active low)

TSC230 has four photodiode types. Red, Blue, Green and Clear.
We can choose the different type of photodiode by different combinations of S2 and S3.

Connection to the Arduino Nano:

S0 = D6 = Portd.6
S1 = D5 = Portd.5
S2 = D4 = Portd.4
S3 = D3 = Portd.3
Out = D2 = Portd.2 = INT0
OE connect to GND
VCC to 5 volt
GND to GND

During 100 mSec the frequency is measured of Red, Green and Blue. This is done by counting the interrupts on INT0 which is connected to the OUT of the TSC230. The value is send to the serial port.
This is done in a do loop cycle for all three colors RGB.


Picture of Arduino Nano and TSC230 module


With a scope checking the frequency of OUT


Terminal output with RGB values

Code:


'Arduino Nano with TSC230 color sensor

$regfile "m328pdef.dat"
$crystal = 16000000
$baud = 9600

$hwstack = 48
$swstack = 48
$framesize = 48

$loadersize = &H800

S0 Alias Portd.6
S1 Alias Portd.5
S2 Alias Portd.4
S3 Alias Portd.3
S_out Alias Portd.2

Config S0 = Output
Config S1 = Output
Config S2 = Output
Config S3 = Output
Config S_out = Input

Dim Count As Word
Dim Count_r As Word
Dim Count_g As Word
Dim Count_b As Word

Set S1
Set S0
Reset S2
Reset S3

Config Int0 = Falling
On Int0 Myisr
Enable Int0
Enable Interrupts

Do
   Count_r = Count
   Print "Red = " ; Count_r
   Set S2
   Set S3
   Count = 0
   Waitms 100

   Count_g = Count
   Print "Green = " ; Count_g
   Reset S2
   Set S3
   Count = 0
   Waitms 100

   Count_b = Count
   Print "Blue = " ; Count_b
   Reset S2
   Reset S3
   Count = 0
   Waitms 100

   Print Chr(27) ; "[2J"; 'ANSI CLS goto 0/0
Loop

End

Myisr:
Incr Count
Return


 


Have fun
Ben Zijlstra
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 4798
Location: Holland

blank.gif
PostPosted: Fri Sep 05, 2014 10:53 pm    Post subject: Reply with quote

hi Ben

Thanks for sharing. Nice and simple code. I need to get myself such a sensor too. Always have been intrigued by them. Dont have a practical use for it yet. I do know you and Theo had a great project for such a sensor.
Hope to see that project some day.

_________________
Mark
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-ARDUINO All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum