吴忠躺衫网络科技有限公司

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

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

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

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

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

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

通過 TCS3200 進行顏色感應

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

該項目將深入了解我們?nèi)绾螌︻伾珎鞲衅鬟M行編程以檢測不同的顏色并觸發(fā)繼電器。

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

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

電路圖:

interfacing the Arduino and TCS3200 colour sensor

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

繼電器連接:

relay connections the Arduino and TCS3200 colour sensor

使用至少 9mA 的 500V 適配器為 Arduino
供電晶體管充當繼電器的放大器,因為Arduino的GPIO引腳不能提供足夠的電流來繼電器。

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

硬件到此結(jié)束。

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

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

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

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

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

//--------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;

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

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

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

對于紅色:

int Rx1 = 56;

int Gx1 = 78;

int Bx1 = 38;

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

步驟6:

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

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

? 您有 Arduino 板上的重置按鈕來停用繼電器。

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

注2:環(huán)境光會影響顏色檢測,因此,在校準和檢測顏色時,請在傳感器附近保持一致的光線。

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

    關(guān)注

    13

    文章

    308

    瀏覽量

    58268
  • 檢測器
    +關(guān)注

    關(guān)注

    1

    文章

    869

    瀏覽量

    47787
  • Arduino
    +關(guān)注

    關(guān)注

    188

    文章

    6477

    瀏覽量

    187834
收藏 人收藏

    評論

    相關(guān)推薦

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

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

    構(gòu)建簡單的空氣流量檢測器電路

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

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

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

    又溫度傳感的過零檢測器電路

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

    材跑偏檢測器測量電路

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

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

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

    分享不錯的顏色檢測器/傳感電路

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

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

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

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

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

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

    對于基本的峰值檢測器電路,我們甚至不需要任何復雜的電子元件。可以使用二極管和電容器構(gòu)建簡單的峰值檢測器電路
    的頭像 發(fā)表于 09-23 15:38 ?4578次閱讀
    使用二極管和電容器<b class='flag-5'>構(gòu)建</b>簡單的峰值<b class='flag-5'>檢測器</b><b class='flag-5'>電路</b>

    Arduino Light Clapper使用聲音檢測器

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

    使用arduino UNO的軸檢測器

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

    使用TCS230 TCS3200顏色傳感制作顏色檢測器

    電子發(fā)燒友網(wǎng)站提供《使用TCS230 TCS3200顏色傳感制作顏色檢測器.zip》資料免費下載
    發(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'>檢測器</b>

    使用Arduino和雨滴傳感的雨量檢測器

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

    LCD的Arduino EMF鬼檢測器

    電子發(fā)燒友網(wǎng)站提供《LCD的Arduino EMF鬼檢測器.zip》資料免費下載
    發(fā)表于 07-05 09:12 ?1次下載
    <b class='flag-5'>帶</b>LCD的<b class='flag-5'>Arduino</b> EMF鬼<b class='flag-5'>檢測器</b>
    24分金| 长春市| 百家乐有几种打法| 百家乐筹码| 百家乐官网发牌盒子| 大发888游戏平台 df888ylc3403 | 百家乐官网有不有作弊| 百家乐游戏唯一官网网站| 百家乐官网庄闲预测| 蜀都棋牌游戏中心| 百家乐投注方法投资法| 百利宫百家乐官网现金网| 大发888游戏破解软件| 网上玩百家乐犯法| 真人百家乐官网作假视频| 大发888客户端| 三国百家乐官网娱乐城| 百家乐官网金币游戏| 威尼斯人娱乐城真钱百家乐| 24山辅星水法分阴阳| 百家乐官网网络视频游戏| 大发888的微博| 百家乐黑牌靴| 重庆百家乐官网团购百嘉乐量贩KTV地址| 冠通网络棋牌世界| 百家乐下注瀛钱法| 赌场百家乐官网赢钱| 正网皇冠开户| 真人百家乐在线玩| 最好的百家乐官网博彩网站 | 墨尔本百家乐官网的玩法技巧和规则 | 百家乐智能系统| 百家乐官网平玩法这样| 百家乐官网五式缆投法| 星空棋牌大厅下载| 网上玩百家乐的玩法技巧和规则 | 大发888官方 截图| 百家乐分路单| 百家乐官网博百家乐官网的玩法技巧和规则| 龙川县| 百家乐平注法规则|