Skip to content

Commit 51c99d4

Browse files
committed
TCS3200 colour sensor Schematic and code
1 parent 874d066 commit 51c99d4

File tree

4 files changed

+126
-0
lines changed

4 files changed

+126
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# [Interfacing 16x2 LCD with Arduino](https://circuitdigest.com/microcontroller-projects/interfacing-16x2-lcd-with-arduino)
2+
3+
<img src="https://github.com/Circuit-Digest/Basic-Arduino-Tutorials-for-Beginners-/blob/d72d720d083c663016516b760d49e7d76e152fe6/Interfacing%2016x2%20LCD%20with%20Arduino/Image/16x2-LCD_Title-image.jpg" width="" alt="alt_text" title="image_tooltip">
4+
<br>
5+
6+
<br>
7+
<a href="https://circuitdigest.com/tags/arduino"><img src="https://img.shields.io/static/v1?label=&labelColor=505050&message=Arduino Basic Tutorials Circuit Digest&color=%230076D6&style=social&logo=google-chrome&logoColor=%230076D6" alt="circuitdigest"/></a>
8+
<br>
9+
10+
[<h1>Click here](https://circuitdigest.com/tags/arduino) for the complete tutorials on Arduino basics.</h1>
11+
12+
13+
<br>
14+
<br>
15+
<br>
16+
In this digital age, we come across LCDs all around us from simple calculators to smartphones, computers and television sets etc. The LCDs use liquid crystals to produce images or texts. The LCDs are categorized into different categories based on different criteria like type of manufacturing, monochrome or colour, and weather Graphical or character LCD. In this tutorial, we will be talking about the 16X2 character LCD Modules.
17+
<br>
18+
The 16x2 LCDs are very popular among the DIY community. Not only that you can also find them in many laboratory and industrial equipment. It can display up to 32 characters at a time. Each character segment is made up of 40 pixels that are arranged in a 5x8 matrix. We can create alphanumeric characters and customs characters by activating the corresponding pixels. Here is a vector representation of a 16x2 LCD, in which you can see those individual pixels.
19+
<br>
20+
[Note: As this projects are very simple we are only providing the code, schemaitic, and a few essential images if you want to get the images or code explanations do check out the Circuit Digest website.
21+
<br>
22+
<br>
23+
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
2+
/*
3+
Sensor Pin S0 -> Arduino Pin D8
4+
Sensor Pin S1 -> Arduino Pin D7
5+
Sensor Pin S2 -> Arduino Pin D6
6+
Sensor Pin S3 -> Arduino Pin D5
7+
Sensor Pin OUT -> Arduino Pin D4
8+
*/
9+
10+
#define S0_PIN 5
11+
#define S1_PIN 4
12+
#define S2_PIN 7
13+
#define S3_PIN 6
14+
#define OUT_PIN 8
15+
16+
17+
18+
void setup()
19+
{
20+
// Set the S0, S1, S2, S3 Pins as Output
21+
pinMode(S0_PIN, OUTPUT);
22+
pinMode(S1_PIN, OUTPUT);
23+
pinMode(S2_PIN, OUTPUT);
24+
pinMode(S3_PIN, OUTPUT);
25+
26+
//Set OUT_PIN as Input
27+
pinMode(OUT_PIN, INPUT);
28+
29+
// Set Pulse Width scaling to 20%
30+
digitalWrite(S0_PIN, HIGH);
31+
digitalWrite(S1_PIN, LOW);
32+
33+
// Enabl UART for Debugging
34+
Serial.begin(9600);
35+
}
36+
37+
void loop()
38+
{
39+
int r, g, b;
40+
41+
r = process_red_value();
42+
delay(200);
43+
g = process_green_value();
44+
delay(200);
45+
b = process_blue_value();
46+
delay(200);
47+
48+
Serial.print("r = ");
49+
Serial.print(r);
50+
Serial.print(" ");
51+
Serial.print("g = ");
52+
Serial.print(g);
53+
Serial.print(" ");
54+
Serial.print("b = ");
55+
Serial.print(b);
56+
Serial.print(" ");
57+
Serial.println();
58+
59+
if (r < 42)
60+
{
61+
Serial.println("Colour Pink");
62+
}
63+
else if (g < 63)
64+
{
65+
Serial.println("Colour Green");
66+
}
67+
68+
else if (r < 64)
69+
{
70+
Serial.println("Colour Red");
71+
}
72+
73+
74+
}
75+
76+
77+
int process_red_value()
78+
{
79+
digitalWrite(S2_PIN, LOW);
80+
digitalWrite(S3_PIN, LOW);
81+
82+
int pulse_length = pulseIn(OUT_PIN, LOW);
83+
return pulse_length;
84+
}
85+
86+
int process_green_value()
87+
{
88+
digitalWrite(S2_PIN, HIGH);
89+
digitalWrite(S3_PIN, HIGH);
90+
91+
int pulse_length = pulseIn(OUT_PIN, LOW);
92+
return pulse_length;
93+
94+
}
95+
96+
int process_blue_value()
97+
{
98+
digitalWrite(S2_PIN, LOW);
99+
digitalWrite(S3_PIN, HIGH);
100+
101+
int pulse_length = pulseIn(OUT_PIN, LOW);
102+
return pulse_length;
103+
}
Loading
Loading

0 commit comments

Comments
 (0)