Cov txheej txheem:

Xim Hloov LED: 13 Kauj Ruam
Xim Hloov LED: 13 Kauj Ruam

Video: Xim Hloov LED: 13 Kauj Ruam

Video: Xim Hloov LED: 13 Kauj Ruam
Video: Cas Tsis Xaiv Koj - R-Lin Thoj New Song Original By Zaj Dub [Official MV] 2023 2024, Lub Xya hli ntuj
Anonim
Xim Hloov LED
Xim Hloov LED
Xim Hloov LED
Xim Hloov LED
Xim Hloov LED
Xim Hloov LED

Kuv tau ua lub luag haujlwm los tsim cov qauv uas siv qee qhov kev ntsuas los tsim cov zis. Kuv txiav txim siab siv lub photocell, uas ntsuas qhov pom kev ntawm lub teeb nyob ib puag ncig, thiab RGB LED ua qhov tso tawm. Kuv paub kuv xav koom nrog LED lub peev xwm los tso tawm ntau yam xim, vim tias kuv xav tias nws yuav muaj kev lom zem. Yog tias kuv tuaj yeem tsim yam khoom twg kuv xav tau, kuv xav tias kuv yuav zoo li nws muaj xim zoo li ua tau.

Kwv yees Tus Nqi:

$ 37 - Elegoo Super Starter kit (suav nrog txhua yam khoom siv)

$ 53 - Yuav kom yuav txhua yam khoom siv ib tus zuj zus

Kev Pab Txuas:

RGB LED - Cov

create.arduino.cc/projecthub/muhammad-aqib…

Photocell - Cov

create.arduino.cc/projecthub/MisterBotBreak/how-to-use-a-photoresistor-46c5eb

Arduino Software - NPE

www.arduino.cc/en/software

Elegoo Super Start cov khoom siv -

www.amazon.com/gp/product/B01D8KOZF4/ref=p…

Khoom siv

- 1 RGB LED

- 1 photocell (aka photoresistor)

- 1 Arduino UNO pawg thawj coj

- 1 daim ntawv qhia zaub mov

- 1 USB cable rau Arduino

- 7 jumper xov hlau

-3 220 ohm resistors

-11 10k ohm resistor

- Arduino software (rub tawm dawb)

Yeem yeem

- khub ntawm rab koob lub qhov ntswg

Kauj Ruam 1: Teeb LED ntawm Breadboard

Teeb LED ntawm Breadboard
Teeb LED ntawm Breadboard
Teeb LED ntawm Breadboard
Teeb LED ntawm Breadboard
Teeb LED ntawm Breadboard
Teeb LED ntawm Breadboard

Ua ntej RGB LED yuav tsum tau teeb tsa kom raug ntawm lub khob cij

Tso lub LED nrog txhua ntawm plaub ceg hauv cais qhov ntawm tib kab (qhia los ntawm cov ntawv). Cov ceg ntev tshaj plaws yuav tsum yog ob txhais ceg los ntawm sab saud.

Hauv kab (qhia los ntawm tus lej) ntawm ceg ntev tshaj plaws, ntsaws rau hauv ib qho kawg ntawm cov xov hlau jumper.

Rau txhua ntawm peb tus ceg luv dua, tso ib qho 220 ohm resistor. Txhua tus tiv thaiv yuav tsum muaj ob txhais ceg nyob hauv kab ib yam li LED ob txhais ceg. Nov yog qhov uas kuv yuav siv rab rab qhov ntswg, vim tias ob txhais ceg ntawm cov neeg tawm tsam tuaj yeem nyuaj rau ntsaws los ntawm txhais tes.

Txuas peb lub xov hlau jumper ntawm ib sab ntawm tus tiv thaiv rov qab rau LED. Rau peb kab no, yuav tsum muaj ib lub xaim xaim hluav taws xob, ib tus tiv thaiv, thiab ib sab ntawm LED.

Kauj Ruam 2: Teeb LED ntawm Arduino

Teeb LED ntawm Arduino
Teeb LED ntawm Arduino
Teeb LED ntawm Arduino
Teeb LED ntawm Arduino
Teeb LED ntawm Arduino
Teeb LED ntawm Arduino
Teeb LED ntawm Arduino
Teeb LED ntawm Arduino

Tam sim no tias LED tau teeb tsa kom raug ntawm lub khob cij, nws yuav tsum tau txuas nrog Arduino.

Thawj jumper xaim txuas nrog cov ceg ntev tshaj plaws (yuav tsum yog kab thib ob ntawm LED) xav tau txuas nrog hauv av, qhia los ntawm "GND" ntawm Arduino.

Lwm peb lub xov hlau txuas, nyob rau qhov kev txiav txim qis, yuav tsum tau ntsaws rau hauv cov chaw nres nkoj 11, 10, thiab 9. Cov xaim nyob rau kab saum toj kawg nkaus yuav tsum txuas nrog 11, cov xaim txuas tom ntej (yuav tsum yog kab thib peb) txuas rau 10, thiab cov xaim kawg txuas mus rau 9. Cov xov hlau no peb yuav tsum khiav mus ib txhis thiab tsis txhob sib tshooj.

Kauj Ruam 3: Teeb Duab Photocell ntawm Breadboard

Teeb Photocell ntawm Breadboard
Teeb Photocell ntawm Breadboard
Teeb Photocell ntawm Breadboard
Teeb Photocell ntawm Breadboard
Teeb Photocell ntawm Breadboard
Teeb Photocell ntawm Breadboard

Txhawm rau kom LED hnov mob rau ib puag ncig qhov ci ntsa iab, nws yuav tsum tau txais cov ntaub ntawv los ntawm lub ntsuas cua.

Plug lub photocell rau hauv lub khob cij nrog ob txhais ceg hauv tib kab ntawv, zoo ib yam li LED tau ntsaws rau hauv.

Txuas lub 10k ohm resistor nrog ib txhais ceg hauv kab ib yam li hauv qab ceg ntawm daim duab. Txuas ob txhais ceg ntawm tus tiv thaiv kom deb dua hauv tib kab ntawv.

Kauj Ruam 4: Txuas Photocell rau Arduino

Txuas Photocell rau Arduino
Txuas Photocell rau Arduino
Txuas Photocell rau Arduino
Txuas Photocell rau Arduino
Txuas Photocell rau Arduino
Txuas Photocell rau Arduino
Txuas Photocell rau Arduino
Txuas Photocell rau Arduino

Plug rau hauv ib lub xaim hlau nyob hauv kab ib yam li 10k ohm resistor, tab sis tsis nyob hauv tib kab kab ntawv photocell.

Txuas lwm qhov kawg ntawm cov xov hlau txuas rau hauv av (GND) ntawm Arduino.

Plug rau hauv ob lub xov hlau sib txawv, ib qho hauv kab ib yam li txhua tus ntawm cov duab photocell.

Txuas cov xaim hluav taws xob mus rau qhov siab tshaj plaws rau hauv 5V chaw nres nkoj ntawm Arduino.

Txuas cov xaim hluav taws xob mus deb tshaj plaws hauv qab mus rau A0 chaw nres nkoj ntawm Arduino.

Kauj Ruam 5: Txuas rau Arduino

Txuas rau Arduino
Txuas rau Arduino
Txuas rau Arduino
Txuas rau Arduino
Txuas rau Arduino
Txuas rau Arduino
Txuas rau Arduino
Txuas rau Arduino

Tam sim no tias daim ntawv qhia zaub mov tau teeb tsa thiab txuas nrog Arduino, siv USB txuas los txuas Arduino rau koj lub khoos phis tawj.

Kauj Ruam 6: Pib Koj Li Code

Pib Koj Txoj Cai
Pib Koj Txoj Cai
Pib Koj Txoj Cai
Pib Koj Txoj Cai

Siv Arduino program, tsim cov duab kos tshiab.

Hauv kev tawm lus, sau koj lub npe, qee cov ntsiab lus hais txog daim duab, thiab txuas ib qho peev txheej uas koj tau siv.

Saum toj no qhov tsis muaj teeb tsa, tsim kom muaj kev hloov pauv thoob ntiaj teb. Xav tias dawb los theej thiab paste cov cai hauv qab no. Thaum koj sau cov cai, qee qhov yuav dhau los ua xim sib txawv. Qhov no yuav tsum tshwm sim.

int red_light_pin = 11; int ntsuab_light_pin = 10; int blue_light_pin = 9; int photocellReading = 0; int photocell = 5;

Yog tias koj pom, cov lej uas tau muab rau cov kev hloov pauv no sib haum nrog qhov twg cov xov hlau tau txuas rau ntawm Arduino board.

Kauj Ruam 7: Teeb Meem

Teeb Meem
Teeb Meem

Tsim kom muaj RGB LED raws li qhov tso tawm.

pinMode (red_light_pin, OUTPUT); pinMode (ntsuab_light_pin, OUTPUT); pinMode (blue_light_pin, OUTPUT);

Pib ua tus saib xyuas txuas ntxiv txhawm rau saib qhov nyeem ntawm lub photocell.

Serial.begin (9600); Serial.println ("Serial saib tau pib"); ncua (500); Serial.println ("."); ncua (500); Serial.println ("."); ncua (500); Serial.println ("."); ncua (500);

Xyuas kom tseeb tias qhov tsis muaj teeb meem teeb tsa muaj nyob hauv ib khub ntawm cov zawm hniav {}

Kauj Ruam 8: Void Loop

Void Loop
Void Loop
Void Loop
Void Loop

Sau cov cai rau qhov khoob khoob ntu.

Cov cai nyob hauv thawj daim duab luam tawm cov ntawv nyeem ntawm lub photocell ntawm kab sib cais. Qhov no ua kom yooj yim nyeem.

int tus nqi = analogRead (A0); photocellReading = analogRead (photocell); Serial.println (photocellReading); ncua (40);

Cov cai hauv daim duab thib ob yog qhov sib xws ntawm qee qhov kev nyeem ntawv rau xim dab tsi LED yuav tso tawm.

yog (photocellReading 0) {RGB_color (255, 0, 0); // Liab} yog (photocellReading 99) {RGB_color (255, 255, 0); // Daj} yog (photocellReading 199) {RGB_color (0, 255, 0); // Ntsuab} yog (photocellReading 299) {RGB_color (0, 0, 255); // Xiav} yog (photocellReading 399) {RGB_color (255, 0, 255); // Magenta}

Hloov tus lej tus lej ntawm RGB_color (0s thiab 255s) yuav hloov xim dab tsi. Cov no yog cov xim kuv tau mus nrog, tab sis xav tias hloov pauv lossis hloov lawv ib puag ncig raws li koj xav tau.

Txheeb xyuas ob zaug tias ntu ntu tsis muaj qhov nyob hauv ib khub ntawm cov zawm hniav {}

Kauj Ruam 9: Hloov Xim

Hloov Xim
Hloov Xim

Nov yog qee qhov xim ntxiv los xaiv los ntawm cov kauj ruam dhau los. Kuv siv cov cai no siv rau kuv daim duab.

Kauj Ruam 10: Kawg RGB LED Code

Kawg RGB LED Code
Kawg RGB LED Code

Qhov kawg ntawm daim duab, sab nraum qhov tsis muaj qhov seem ntu, ntxig cov cai no los txiav txim qhov chaw nres nkoj ntawm Arduino sib txuas lus tus nqi teeb liab, tus nqi lub teeb ntsuab, thiab lub teeb ntsuab.

tsis muaj dab tsi RGB_color (int red_light_value, int ntsuab_light_value, int blue_light_value) {analogWrite (red_light_pin, red_light_value); analogWrite (ntsuab_light_pin, ntsuab_light_value); analogWrite (blue_light_pin, blue_light_value); }

Ib yam li nrog qhov tsis muaj teeb tsa teeb tsa thiab tsis muaj seem ntu ntu, nco ntsoov tias ntu no muaj nyob hauv ib khub ntawm cov zawm hniav {}

Kauj Ruam 11: Tshawb Tawm Teeb

Xeem Tawm Teeb!
Xeem Tawm Teeb!
Xeem Tawm Teeb!
Xeem Tawm Teeb!
Xeem Tawm Teeb!
Xeem Tawm Teeb!

Tshaj tawm cov cai rau Arduino board los ntawm nias lub pob upload hauv qhov program. Yog tias koj ua nws raug, LED yuav tsum tso saib xim nyob ntawm seb muaj teeb pom kev ntau npaum li cas nyob ib puag ncig.

Liab yog qhov tsaus ntuj ib puag ncig, qhov qis tshaj ntawm kev nyeem ntawv.

Daj yog qhov ci dua me ntsis ib puag ncig/nyeem ntawv photocell siab dua. Nws zoo li teal hauv daim duab, tab sis nws ci daj rau tus kheej.

Peb xim tom ntej, ntsuab, xiav, thiab magenta, txhua yam sib xws nrog kev nyeem ntawv ntau dua los ntawm daim duab.

Kauj ruam 12: Troubleshooting

Teeb meem
Teeb meem

Yog tias cov xim tsis hloov pauv, lossis nws yuav siv qhov hloov pauv ntau heev rau cov xim hloov pauv, txheeb xyuas cov ntawv nyeem hauv daim duab saib. Txhua qhov ib puag ncig muaj qib sib txawv ntawm lub teeb, yog li nws yog qhov tseem ceeb rau txoj cai los cuam tshuam qhov ntawd.

Nyem rau Cov Cuab Yeej nyob rau sab saum toj ntawm Arduino program -> Nyem rau ntawm Serial Monitor.

Lub qhov rai yuav tsum tshwm tuaj uas qhia txog cov npe tsis tu ncua. Kho cov lej ntawm cov lus yog los ntawm Void Loop kauj ruam.

Kauj Ruam 13: Cov Khoom Kawg

Khoom Kawg
Khoom Kawg

Los ntawm kev ua txhua yam ntawm cov theem no, koj yuav tsum xaus nrog lub teeb uas hloov xim nyob ntawm qhov ci ntawm ib puag ncig.

Rau kuv, nyob rau nruab nrab qhov ci ntawm kuv chav, lub teeb ci ntsuab, tab sis kuv tuaj yeem hloov xim tau yooj yim los ntawm kev npog lub photocell lossis nce ntau npaum li cas lub teeb muaj.

Pom zoo: