Color Sensor Machine 顏色感應器

Description

Description

作者:9B 陳綮民

 

簡介

使用TSC 3200 以及LCD螢幕,使其偵測到的顏色顯示在LCD螢幕上。

 

改作來源

https://howtomechatronics.com/projects/arduino-color-sorter-project/

 

修改內容

1.我將原本需要SERVO的程式改為連接到LCD螢幕,並些微修改顏色評斷方式。

2. 將原本偵測6個顏色改為三個。

3.將Arduino、麵包版、行動電源裝在盒子內,方便揮動不會扯到線。

 

程式碼

/* Arduino Project – Color Sorting Machine
*
* by Dejan Nedelkovski, www.HowToMechatronics.com
*
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// For these LCD controls to work you MUST replace the standard LCD library from…
// https://github.com/marcoschwartz/LiquidCrystal_I2C
// Direct download https://github.com/marcoschwartz/LiquidCrystal_I2C/archive/master.zip
// Your project will not compile until this is done.
//
LiquidCrystal_I2C lcd_I2C_3F(0x3F,16,2);
//增加 LiquidCrystal_I2C 模組 //改

#include <Servo.h>

#define S0 2
#define S1 3
#define S2 4
#define S3 5
#define sensorOut 9

int frequency = 0;
int color=0;

void setup()
{
lcd_I2C_3F.init ();
lcd_I2C_3F.backlight();

pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
pinMode(S3, OUTPUT);
pinMode(sensorOut, INPUT);
// Setting frequency-scaling to 20%
digitalWrite(S0, HIGH);
digitalWrite(S1, LOW);
}

void loop()
{
circle:
color = readColor();
lcd_I2C_3F.clear();

if (( (color ) == ( 1 ) ))
{
lcd_I2C_3F.setCursor(0.0 , 0.0) ;
lcd_I2C_3F.print( “Red” );
}
if (( (color ) == ( 3 ) ))
{
lcd_I2C_3F.setCursor(0.0 , 0.0) ;
lcd_I2C_3F.print( “Green” );
}
if (( (color ) == ( 6 ) ))
{
lcd_I2C_3F.setCursor(0.0 , 0.0) ;
lcd_I2C_3F.print( “Blue” );
}
delay(1000);
goto circle;
} //改
// Custom Function – readColor()
int readColor() {
//Setting red filtered photodiodes to be read
// digitalWrite(S2, LOW);
//digitalWrite(S3, LOW);
// Reading the output frequency
frequency = pulseIn(sensorOut, LOW);
int R = frequency;
// Printing the value on the serial monitor
Serial.print(“R= “);//printing name
Serial.print(frequency);//printing RED color frequency
Serial.print(” “);
delay(50);
// Setting Green filtered photodiodes to be read
digitalWrite(S2, HIGH);
digitalWrite(S3, HIGH);
// Reading the output frequency
frequency = pulseIn(sensorOut, LOW);
int G = frequency;
// Printing the value on the serial monitor
Serial.print(“G= “);//printing name
Serial.print(frequency);//printing GREEN color frequency
Serial.print(” “);
delay(50);
// Setting Blue filtered photodiodes to be read
digitalWrite(S2, LOW);
digitalWrite(S3, HIGH);
// Reading the output frequency
frequency = pulseIn(sensorOut, LOW);
int B = frequency;
// Printing the value on the serial monitor
Serial.print(“B= “);//printing name
Serial.print(frequency);//printing BLUE color frequency
Serial.println(” “);
delay(50);
if(R<B && R<G){ //(R<45 & R>32 & G<65 & G>55){
color = 1; // Red 改
}
/*if(G<55 & G>43 & B<47 &B>35){
color = 2; // Orange
}*/
if(G<R && G<B){ //(R<53 & R>40 & G<53 & G>40){
color = 3; // Green 改
}
/*if(R<56 & R>46 & G<65 & G>55){
color = 5; // Brown
}*/
if(B<R && B<G){ //(G<58 & G>45 & B<40 &B>26){
color = 6; // Blue 改
}
return color;
}

程式碼 Link:

https://create.arduino.cc/editor/Dabfortako/d0b7dc75-486e-46dd-ace0-8aa020d42d88/preview

 

材料清單

1.Arduino Loenardo

2. TSC 3200

3. LCD I2C

4. 線

5. 紙箱

6. 膠帶

7. 美工刀

8.剪刀

 

製作步驟

1.購買所有材料

2.將所有電路組裝好

3.拿一個盒子將其包裝好

4.挖兩個符合LCD I2C & TSC 3200 的洞

5.將盒子裝飾

 

成果展示

Latest posts by Chen Kevin (see all)

    Contact

    Contact
    • Category
      康橋國際學校
    • Tags
      #KangChiaoGang, #Kevin Chen, #LCD I2C, #TSC 3200 Color sensor

    Project簡述

    Project簡述
    • 簡述
      使用TSC 3200 以及LCD螢幕,使其偵測到的顏色顯示在LCD螢幕上。
    • 作者
      9B 陳綮民

    您的姓名 〈需填寫〉

    您的電子郵件信箱 〈需填寫〉

    主旨

    您的信件內容