0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫(xiě)文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

構(gòu)建一個(gè)帶Arduino代碼的顏色檢測(cè)器電路

科技觀察員 ? 來(lái)源:homemade-circuits ? 作者:homemade-circuits ? 2023-07-27 11:23 ? 次閱讀

在這篇文章中,我們將構(gòu)建一個(gè)可以檢測(cè)顏色并觸發(fā)相應(yīng)分配繼電器的電路。該項(xiàng)目是使用 TCS3200 顏色傳感器Arduino 板完成的。

通過(guò) TCS3200 進(jìn)行顏色感應(yīng)

如果您希望電路根據(jù)顏色采取行動(dòng),則建議的項(xiàng)目可能會(huì)很有用。在各種工業(yè)領(lǐng)域,基于顏色檢測(cè)的應(yīng)用海量很大。

該項(xiàng)目將深入了解我們?nèi)绾螌?duì)顏色傳感器進(jìn)行編程以檢測(cè)不同的顏色并觸發(fā)繼電器。

我們將考慮該項(xiàng)目的原色:紅色、綠色和藍(lán)色。該項(xiàng)目可以區(qū)分這三種顏色并觸發(fā)繼電器,每個(gè)繼電器代表每種顏色。

TCS3200 可以檢測(cè)任意數(shù)量的顏色,但為了使項(xiàng)目易于理解并保持程序代碼簡(jiǎn)單,我們只關(guān)注原色。

電路圖:

interfacing the Arduino and TCS3200 colour sensor

以上原理圖用于連接Arduino和TCS3200顏色傳感器。

繼電器連接:

relay connections the Arduino and TCS3200 colour sensor

使用至少 9mA 的 500V 適配器為 Arduino
供電。晶體管充當(dāng)繼電器的放大器,因?yàn)锳rduino的GPIO引腳不能提供足夠的電流來(lái)繼電器。

二極管 1N4007 將吸收繼電器線圈的高壓尖峰,保護(hù)其余半導(dǎo)體元件。

硬件到此結(jié)束。

現(xiàn)在讓我們看看如何上傳代碼并根據(jù)您的要求校準(zhǔn)傳感器。

顏色靈敏度可能因模塊而異,環(huán)境光會(huì)極大地改變顏色靈敏度。

所有TCS3200傳感器在制造時(shí)都有一些變化,您必須測(cè)量當(dāng)前擁有的傳感器的顏色參數(shù),以便可以在代碼中使用這些參數(shù)來(lái)更準(zhǔn)確地檢測(cè)顏色。

要校準(zhǔn)和優(yōu)化傳感器的讀數(shù),請(qǐng)精確執(zhí)行以下步驟:

步驟 1:上傳以下代碼并完成硬件設(shè)置。

//--------Program Developed by R.GIRISH-------//

const int s0 = 4;

const int s1 = 5;

const int s2 = 6;

const int s3 = 7;

const int out = 8;

int frequency1 = 0;

int frequency2 = 0;

int frequency3 = 0;

int state = LOW;

int state1 = LOW;

int state2 = HIGH;

void setup()

{

Serial.begin(9600);

pinMode(s0, OUTPUT);

pinMode(s1, OUTPUT);

pinMode(s2, OUTPUT);

pinMode(s3, OUTPUT);

pinMode(out, INPUT);

//----Scaling Frequency 20%-----//

digitalWrite(s0, state2);

digitalWrite(s1, state1);

//-----------------------------//

}

void loop()

{

//-----Sensing RED colour-----//

digitalWrite(s2, state1);

digitalWrite(s3, state1);

frequency1 = pulseIn(out, state);

Serial.print(“RED = ”);

Serial.print(frequency1);

Serial.print(“ |”);

delay(100);

//------Sensing Green colour----//

digitalWrite(s2, state2);

digitalWrite(s3, state2);

frequency2 = pulseIn(out, state);

Serial.print(“ Green = ”);

Serial.print(frequency2);

Serial.print(“ |”);

delay(100);

//------Sensing Blue colour----//

digitalWrite(s2, state1);

digitalWrite(s3, state2);

frequency3 = pulseIn(out, state);

Serial.print(“ Blue = ”);

Serial.println(frequency3);

delay(100);

Serial.println(“-----------------------------”);

delay(400);

}

//---------Program Developed by R.GIRISH---------//

Step 2: Open the serial monitor, you will find the color parameters like
this:

Bring the color object (colored paper is preferred) red, blue and
green.

Step 3:

? Place the red colored paper close to the TCS3200 sensor.

? Note down the R, G, B readings (all three colours) while you place the
red colour paper.

? Similarly note down the R, G, B reading for green and blue color
papers.

? NOTE: when you place any of the 3 colors in front of the TCS3200 note
down all the red, blue and green readings for each color paper, which you need
to enter in the main color detection program.

Step 4: Read Step 5 and upload the main below code (color detection
program)

//-----Program Developed by R.GIRISH-----//

const int Red_relay = 9;

const int Green_relay = 10;

const int Blue_relay = 11;

const int s0 = 4;

const int s1 = 5;

const int s2 = 6;

const int s3 = 7;

const int out = 8;

int var = 25;

int red = 0;

int green = 0;

int blue = 0;

int state = LOW;

int state1 = LOW;

int state2 = HIGH;

//-----------Enter Values--------//

//For RED Colour:

int Rx1 = 92;

int Gx1 = 240;

int Bx1 = 53;

//For GREEN Colour:

int Rx2 = 228;

int Gx2 = 163;

int Bx2 = 64;

//For BLUE Colour:

int Rx3 = 300;

int Gx3 = 144;

int Bx3 = 45;

//----------------------------//

void setup()

{

Serial.begin(9600);

pinMode(Red_relay, OUTPUT);

pinMode(Green_relay, OUTPUT);

pinMode(Blue_relay, OUTPUT);

digitalWrite(Red_relay, LOW);

digitalWrite(Green_relay, LOW);

digitalWrite(Blue_relay, LOW);

pinMode(s0, OUTPUT);

pinMode(s1, OUTPUT);

pinMode(s2, OUTPUT);

pinMode(s3, OUTPUT);

pinMode(out, INPUT);

//----Scaling Frequency 20%-----//

digitalWrite(s0, state2);

digitalWrite(s1, state1);

//-----------------------------//

}

void loop()

{

int redH1 = Rx1 + var;

int redL1 = Rx1 - var;

int redH2 = Rx2 + var;

int redL2 = Rx2 - var;

int redH3 = Rx3 + var;

int redL3 = Rx3 - var;

int blueH1 = Bx1 + var;

int blueL1 = Bx1 - var;

int blueH2 = Bx2 + var;

int blueL2 = Bx2 - var;

int blueH3 = Bx3 + var;

int blueL3 = Bx3 - var;

int greenH1 = Gx1 + var;

int greenL1 = Gx1 - var;

int greenH2 = Gx2 + var;

int greenL2 = Gx2 - var;

int greenH3 = Gx3 + var;

int greenL3 = Gx3 - var;

//-----Sensing RED colour-----//

digitalWrite(s2, state1);

digitalWrite(s3, state1);

red = pulseIn(out, state);

delay(100);

//------Sensing Green colour----//

digitalWrite(s2, state2);

digitalWrite(s3, state2);

green = pulseIn(out, state); ;

delay(100);

//------Sensing Blue colour----//

digitalWrite(s2, state1);

digitalWrite(s3, state2);

blue = pulseIn(out, state);

delay(400);

if(red 《= redH1 && red 》= redL1)

{

if(green 《= greenH1 && green 》= greenL1)

{

if(blue 《= blueH1 && blue 》= blueL1)

{

Serial.println(“Detected Colour: RED”);

Serial.println(“”);

digitalWrite(Red_relay, HIGH);

delay(1000);

}

}

}

if(red 《= redH2 && red 》= redL2)

{

if(green 《= greenH2 && green 》= greenL2)

{

if(blue 《= blueH2 && blue 》= blueL2)

{

Serial.println(“Detected Colour: Green”);

Serial.println(“”);

digitalWrite(Green_relay, HIGH);

delay(1000);

}

}

}

if(red 《= redH3 && red 》= redL3)

{

if(green 《= greenH3 && green 》= greenL3)

{

if(blue 《= blueH3 && blue 》= blueL3)

{

Serial.println(“Detected Colour: Blue”);

Serial.println(“”);

digitalWrite(Blue_relay, HIGH);

delay(1000);

}

}

}

}

//------Program Developed by R.GIRISH--------//

第 5 步: 在上面的代碼中,將值替換為您最近記下的值:

//-- -- -- -- Enter Values-- -- --//

//For RED Colour:

int Rx1 = 92;

int Gx1 = 240;

int Bx1 = 53;

//For GREEN Colour:

int Rx2 = 228;

int Gx2 = 163;

int Bx2 = 64;

//For BLUE Colour:

int Rx3 = 300;

int Gx3 = 144;

int Bx3 = 45;

//-- -- -- -- -- -- -- -- -- -- -- //

當(dāng)您將紅色紙放在傳感器上時(shí),您將獲得三個(gè)讀數(shù),例如R = 56 |G = 78 |B = 38。

按如下所示放置值 56、78、38:

對(duì)于紅色:

int Rx1 = 56;

int Gx1 = 78;

int Bx1 = 38;

同樣,對(duì)于其他兩種顏色并上傳代碼。

步驟6:

? 打開(kāi)串行監(jiān)視器,將三種顏色中的任何一種放在傳感器前面。

?您將在串行監(jiān)視器上看到顏色檢測(cè);同時(shí)激活相應(yīng)的顏色繼電器。

? 您有 Arduino 板上的重置按鈕來(lái)停用繼電器。

注1:校準(zhǔn)后,如果您放置的紅色,綠色,藍(lán)色物體/紙張的陰影/色調(diào)略有不同,則電路可能無(wú)法檢測(cè)到顏色。換句話說(shuō),您必須使用完全相同顏色的物體/紙張來(lái)檢測(cè)顏色并觸發(fā)中繼。

注2:環(huán)境光會(huì)影響顏色檢測(cè),因此,在校準(zhǔn)和檢測(cè)顏色時(shí),請(qǐng)?jiān)趥鞲衅鞲浇3忠恢碌墓饩€。

聲明:本文內(nèi)容及配圖由入駐作者撰寫(xiě)或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問(wèn)題,請(qǐng)聯(lián)系本站處理。 舉報(bào)投訴
  • 檢測(cè)電路
    +關(guān)注

    關(guān)注

    13

    文章

    304

    瀏覽量

    58078
  • 檢測(cè)器
    +關(guān)注

    關(guān)注

    1

    文章

    856

    瀏覽量

    47600
  • Arduino
    +關(guān)注

    關(guān)注

    187

    文章

    6455

    瀏覽量

    186366
收藏 人收藏

    評(píng)論

    相關(guān)推薦

    構(gòu)建個(gè)基于晶體管的簡(jiǎn)單土壤濕度檢測(cè)器電路

    在這個(gè)項(xiàng)目中,我們將構(gòu)建個(gè)基于晶體管的簡(jiǎn)單土壤濕度檢測(cè)器電路。在本電路中,我們使用NPN晶體管
    的頭像 發(fā)表于 11-22 17:22 ?3544次閱讀
    <b class='flag-5'>構(gòu)建</b><b class='flag-5'>一</b><b class='flag-5'>個(gè)</b>基于晶體管的簡(jiǎn)單土壤濕度<b class='flag-5'>檢測(cè)器</b><b class='flag-5'>電路</b>

    構(gòu)建個(gè)簡(jiǎn)單的空氣流量檢測(cè)器電路

    氣流檢測(cè)在許多項(xiàng)目和應(yīng)用中都很有用。在這里,我們正在構(gòu)建個(gè)非常簡(jiǎn)單的電路來(lái)檢測(cè)氣流的存在。該
    的頭像 發(fā)表于 12-29 11:19 ?2430次閱讀
    <b class='flag-5'>構(gòu)建</b><b class='flag-5'>一</b><b class='flag-5'>個(gè)</b>簡(jiǎn)單的空氣流量<b class='flag-5'>檢測(cè)器</b><b class='flag-5'>電路</b>

    基于物聯(lián)網(wǎng)的LPG氣體泄漏檢測(cè)器

    使用MQ-5傳感、ESP8266和Arduino構(gòu)建個(gè)基于物聯(lián)網(wǎng)的LPG氣體泄漏檢測(cè)器
    發(fā)表于 09-22 06:06

    又溫度傳感的過(guò)零檢測(cè)器電路

    又溫度傳感的過(guò)零檢測(cè)器電路
    的頭像 發(fā)表于 04-14 09:28 ?2973次閱讀
    <b class='flag-5'>帶</b>又溫度傳感<b class='flag-5'>器</b>的過(guò)零<b class='flag-5'>檢測(cè)器</b><b class='flag-5'>電路</b>圖

    材跑偏檢測(cè)器測(cè)量電路

    材跑偏檢測(cè)器測(cè)量電路
    發(fā)表于 11-04 22:51 ?1428次閱讀
    <b class='flag-5'>帶</b>材跑偏<b class='flag-5'>檢測(cè)器</b>測(cè)量<b class='flag-5'>電路</b>

    采用Arduino開(kāi)發(fā)板、火焰?zhèn)鞲?b class='flag-5'>器和蜂鳴器構(gòu)建火感檢測(cè)器系統(tǒng)

    本項(xiàng)目采用Arduino開(kāi)發(fā)板、火焰?zhèn)鞲?b class='flag-5'>器(Flame Sensor)、蜂鳴器,構(gòu)建個(gè)簡(jiǎn)單的火感檢測(cè)
    發(fā)表于 04-19 10:17 ?2474次閱讀
    采用<b class='flag-5'>Arduino</b>開(kāi)發(fā)板、火焰?zhèn)鞲?b class='flag-5'>器</b>和蜂鳴器<b class='flag-5'>構(gòu)建</b>火感<b class='flag-5'>檢測(cè)器</b>系統(tǒng)

    分享個(gè)不錯(cuò)的顏色檢測(cè)器/傳感電路

    這是顏色檢測(cè)器/傳感電路圖。該電路將感應(yīng)八種顏色:綠色、紅色和藍(lán)色(作為原色);洋紅色、青色和
    的頭像 發(fā)表于 06-14 16:55 ?3131次閱讀
    分享<b class='flag-5'>一</b><b class='flag-5'>個(gè)</b>不錯(cuò)的<b class='flag-5'>顏色</b><b class='flag-5'>檢測(cè)器</b>/傳感<b class='flag-5'>器</b><b class='flag-5'>電路</b>圖

    使用霍爾傳感和LED構(gòu)建個(gè)磁極性檢測(cè)器

    在這個(gè)項(xiàng)目中,我們將使用霍爾傳感和 LED構(gòu)建個(gè)磁極性檢測(cè)器。這里使用了兩個(gè)霍爾效應(yīng)傳感
    的頭像 發(fā)表于 08-16 15:28 ?5326次閱讀
    使用霍爾傳感<b class='flag-5'>器</b>和LED<b class='flag-5'>構(gòu)建</b><b class='flag-5'>一</b><b class='flag-5'>個(gè)</b>磁極性<b class='flag-5'>檢測(cè)器</b>

    構(gòu)建個(gè)基于Arduino的貨幣計(jì)數(shù)

    在這個(gè)項(xiàng)目中,我們將研究個(gè)創(chuàng)新的Arduino項(xiàng)目創(chuàng)意,在這里我們可以通過(guò)使用顏色傳感Arduin
    的頭像 發(fā)表于 08-22 15:51 ?2599次閱讀
    <b class='flag-5'>構(gòu)建</b><b class='flag-5'>一</b><b class='flag-5'>個(gè)</b>基于<b class='flag-5'>Arduino</b>的貨幣計(jì)數(shù)<b class='flag-5'>器</b>

    使用二極管和電容器構(gòu)建簡(jiǎn)單的峰值檢測(cè)器電路

    對(duì)于基本的峰值檢測(cè)器電路,我們甚至不需要任何復(fù)雜的電子元件??梢允褂枚O管和電容器構(gòu)建簡(jiǎn)單的峰值檢測(cè)器電路
    的頭像 發(fā)表于 09-23 15:38 ?4074次閱讀
    使用二極管和電容器<b class='flag-5'>構(gòu)建</b>簡(jiǎn)單的峰值<b class='flag-5'>檢測(cè)器</b><b class='flag-5'>電路</b>

    Arduino Light Clapper使用聲音檢測(cè)器

    電子發(fā)燒友網(wǎng)站提供《Arduino Light Clapper使用聲音檢測(cè)器.zip》資料免費(fèi)下載
    發(fā)表于 11-11 14:19 ?0次下載
    <b class='flag-5'>Arduino</b> Light Clapper使用聲音<b class='flag-5'>檢測(cè)器</b>

    使用arduino UNO的軸檢測(cè)器

    電子發(fā)燒友網(wǎng)站提供《使用arduino UNO的軸檢測(cè)器.zip》資料免費(fèi)下載
    發(fā)表于 11-29 11:06 ?0次下載
    使用<b class='flag-5'>arduino</b> UNO的軸<b class='flag-5'>檢測(cè)器</b>

    使用TCS230 TCS3200顏色傳感制作顏色檢測(cè)器

    電子發(fā)燒友網(wǎng)站提供《使用TCS230 TCS3200顏色傳感制作顏色檢測(cè)器.zip》資料免費(fèi)下載
    發(fā)表于 02-13 16:48 ?7次下載
    使用TCS230 TCS3200<b class='flag-5'>顏色</b>傳感<b class='flag-5'>器</b>制作<b class='flag-5'>顏色</b><b class='flag-5'>檢測(cè)器</b>

    使用Arduino和雨滴傳感的雨量檢測(cè)器

    電子發(fā)燒友網(wǎng)站提供《使用Arduino和雨滴傳感的雨量檢測(cè)器.zip》資料免費(fèi)下載
    發(fā)表于 06-28 16:07 ?3次下載
    使用<b class='flag-5'>Arduino</b>和雨滴傳感<b class='flag-5'>器</b>的雨量<b class='flag-5'>檢測(cè)器</b>

    LCD的Arduino EMF鬼檢測(cè)器

    電子發(fā)燒友網(wǎng)站提供《LCD的Arduino EMF鬼檢測(cè)器.zip》資料免費(fèi)下載
    發(fā)表于 07-05 09:12 ?1次下載
    <b class='flag-5'>帶</b>LCD的<b class='flag-5'>Arduino</b> EMF鬼<b class='flag-5'>檢測(cè)器</b>