Cov txheej txheem:

Lub Teeb Sensor (Photoresistor) Nrog Arduino hauv Tinkercad: 5 Kauj Ruam (nrog Duab)
Lub Teeb Sensor (Photoresistor) Nrog Arduino hauv Tinkercad: 5 Kauj Ruam (nrog Duab)

Video: Lub Teeb Sensor (Photoresistor) Nrog Arduino hauv Tinkercad: 5 Kauj Ruam (nrog Duab)

Video: Lub Teeb Sensor (Photoresistor) Nrog Arduino hauv Tinkercad: 5 Kauj Ruam (nrog Duab)
Video: LDR Project | How To Make Simple Automatic Night Led #ldr 2024, Hlis ntuj nqeg
Anonim
Lub teeb Sensor (Photoresistor) Nrog Arduino hauv Tinkercad
Lub teeb Sensor (Photoresistor) Nrog Arduino hauv Tinkercad

Tinkercad Cov Haujlwm »

Cia peb kawm yuav ua li cas nyeem tus photoresistor, lub teeb pom kev zoo ntawm qhov sib txawv resistor, siv Arduino's Analog Input. Nws kuj tseem hu ua LDR (lub teeb nyob ntawm tus tiv thaiv).

Txog tam sim no koj twb tau kawm los tswj LEDs nrog Arduino's analog output, thiab los nyeem lub hwj chim, uas yog lwm hom kev sib txawv resistor, yog li peb yuav tsim cov txuj ci hauv zaj lus qhia no. Nco ntsoov tias Arduino's analog inputs (pins cim A0-A6) tuaj yeem tshawb pom qhov hloov pauv hluav taws xob maj mam, thiab txhais cov teeb liab ntawd mus rau tus lej nruab nrab ntawm 0 thiab 1023.

Duab
Duab

Tshawb xyuas cov qauv piv txwv ntawm no hauv lub dav hlau ua haujlwm los ntawm txhaj Start Simulation thiab nyem rau ntawm lub tshuab photoresistor (lub ntsej muag xim av nrog kab kab ntsais hauv nruab nrab), tom qab ntawd rub lub teeb ci ci los kho qhov teeb pom kev simulated.

Hauv zaj lus qhia no, koj yuav tsim qhov simulated Circuit no koj tus kheej nyob ib sab ntawm tus qauv. Txhawm rau xaiv tsim lub cev kev sib tw, sib sau ua ke koj li Arduino Uno board, USB cable, tsis siv lub khob cij, ib qho LED, resistors (220 ohm thiab 4.7k ohm), photoresistor, thiab cov xov tooj cua.

Koj tuaj yeem ua raws nrog kev siv Tinkercad Circuits. Koj tseem tuaj yeem saib cov lus qhia no los ntawm hauv Tinkercad (yuav tsum tau nkag nkag dawb)! Tshawb xyuas cov qauv hluav taws xob thiab tsim koj tus kheej txoj cai ib sab ntawm nws. Tinkercad Circuits yog qhov browser pub dawb uas tso cai rau koj tsim thiab sim ua cov kab hluav taws xob. Nws zoo meej rau kev kawm, kev qhia, thiab kev tsim qauv.

Kauj ruam 1: Tsim Circuit Court

Tsim Circuit Court
Tsim Circuit Court
Tsim Circuit Court
Tsim Circuit Court

Ua tibzoo saib ntawm daim duab qhia chaw ntawm daim duab. Nws tuaj yeem muaj txiaj ntsig zoo los saib cov kab xaim dawb ntawm cov qauv siv hluav taws xob no rau kev sib piv, daim duab. Hauv cov kauj ruam no, koj yuav tsim koj tus kheej qhov hloov pauv ntawm lub voj voog no ib sab ntawm tus qauv hauv lub dav hlau ua haujlwm.

Txhawm rau ua raws, ntsaws qhov tshiab Tinkercad Circuits qhov rai thiab tsim koj tus kheej ntawm qhov kev sib tw no nrog rau ib sab ntawm cov qauv.

Txheeb xyuas tus photoresistor, LED, tus tiv thaiv, thiab cov xov txuas nrog rau Arduino hauv Tinkercad Circuits workplane.

Luag ib qho Arduino Uno thiab daim ntawv qhia zaub mov los ntawm cov khoom vaj huam sib luag mus rau lub dav hlau ua haujlwm, ib sab ntawm lub voj voog uas twb muaj lawm.

Txuas lub hwj huam mov (+) thiab hauv av (-) txoj kab mus rau Arduino 5V thiab hauv av (GND), feem, los ntawm txhaj rau tsim cov xov hlau.

Txuas lub zog thiab cov tsheb hauv av mus rau lawv cov tsheb npav sib txawv ntawm ntug ntawm lub khob cij (xaiv tau rau hauv Circuit Court tab sis kev coj ua zoo ib yam).

Txuas lub LED rau hauv ob kab sib txawv ntawm kab sib chaws kom lub cathode (tsis zoo, luv dua ceg) txuas rau ib ceg ntawm tus tiv thaiv (nyob qhov twg los ntawm 100-1K ohms zoo). Tus tiv thaiv tuaj yeem mus rau hauv ib qho kev taw qhia vim tias cov neeg tawm tsam tsis muaj qhov sib txawv, tsis zoo li LEDs, uas yuav tsum tau txuas nrog hauv qee txoj hauv kev los ua haujlwm.

Txuas lwm tus tiv thaiv ceg rau hauv av.

Hlau txuas tus LED anode (zoo, ntev dua ceg) rau Arduino tus pin 9.

Luag lub photoresistor los ntawm cov khoom vaj huam sib luag rau koj lub rooj noj mov, yog li nws ob txhais ceg ntsaws rau hauv ob kab sib txawv.

Nyem los tsim cov xaim txuas ib tus photoresistor ceg rau lub zog.

Txuas lwm ceg mus rau Arduino analog pin A0.

Luag tus tiv thaiv los ntawm cov khoom vaj huam sib luag txhawm rau txuas lub photoresistor ceg txuas nrog A0 nrog hauv av, thiab kho nws tus nqi rau 4.7k ohms.

Kauj ruam 2: Code Nrog Blocks

Code Nrog Thaiv
Code Nrog Thaiv

Cia peb siv tus lej ntsuas tus lej txhawm rau mloog lub xeev ntawm tus kws yees duab, tom qab ntawd teeb tsa LED kom pom kev sib txheeb raws li lub teeb pom kev pom ntau npaum li cas. Koj tuaj yeem xav rov ua kom koj lub cim xeeb ntawm LED sib piv tso tawm hauv Fading LED zaj lus qhia.

Nyem rau "Code" khawm kom qhib tus khoos phis tawj. Cov ntawv ceeb toom grey yog cov lus pom rau kev sau cia ntawm yam koj xav tau rau koj li kev cai ua, tab sis cov ntawv no tsis ua tiav raws li ib feem ntawm txoj haujlwm.

Nyem rau ntawm Pawg Variables hauv tus kho qhov chaws.

Txhawm rau khaws qhov tsis kam ntawm tus photoresistor, tsim qhov sib txawv hu ua "sensorValue".

Luag tawm ib qho "set" block. Peb yuav khaws lub xeev ntawm peb tus photoresistor hauv qhov sib txawv

sensorValue

Nyem rau ntawm Pawg nkag thiab rub tawm qhov "analog read pin" block, thiab muab tso rau hauv "teeb" thaiv tom qab lo lus "rau"

Txij li peb lub zog ntsuas tau txuas nrog Arduino ntawm tus pin A0, hloov qhov poob qis mus rau A0.

Nyem rau ntu Output thiab rub tawm ib qho "luam rau serial monitor" thaiv.

Nkag mus rau qeb sib txawv thiab rub koj qhov sib txawv sensorValue mus rau "luam tawm mus rau tus saib xyuas ib ntus", thiab xyuas kom tseeb tias qhov poob qis tau teeb tsa los luam nrog kab tshiab. Optionally pib qhov simulation thiab qhib lub ntsuas saib xyuas kom paub tseeb tias kev nyeem tau nkag los thiab hloov pauv thaum koj kho lub ntsuas. Analog input qhov tseem ceeb ntawm 0-1023.

Txij li thaum peb xav sau mus rau LED nrog tus lej nruab nrab ntawm 0 (tawm) thiab 255 (puv ci ci), peb yuav siv "daim ntawv qhia" thaiv ua qee qhov hla kev sib npaug rau peb. Nkag mus rau qeb lej thiab rub tawm "daim duab qhia chaw" thaiv.

Hauv thawj qhov, rub hauv lub sensorValue nce mus nce los thaiv, tom qab ntawd teeb tsa thaj tsam ntawm 0 txog 255.

Rov qab rau hauv Cov Ntawv Tshaj Tawm, rub tawm qhov sib piv "teeb tus pin" thaiv, uas los ntawm lub neej ntawd hais tias "teeb tus pin 3 rau 0." Kho nws kom teeb tus pin 9.

Luag daim duab qhia chaw uas koj tau ua yav dhau los rau hauv "teeb tus pin" thaiv "rau" teb kom sau tus lej hloov pauv mus rau tus pin LED siv PWM.

Nyem rau Pawg tswj hwm thiab rub tawm qhov tos tos, thiab kho nws kom ncua txoj haujlwm rau.1 vib nas this.

Kauj Ruam 3: Photoresistor Arduino Code Piav Qhia

Thaum tus lej hloov pauv tau qhib, koj tuaj yeem nyem cov ntawv qhia zaub mov nyob rau sab laug thiab xaiv "Thaiv + Ntawv" kom nthuav qhia Arduino code tsim los ntawm cov cai thaiv. Ua raws nrog thaum peb tshawb nrhiav cov cai kom ntxaws.

int sensorValue = 0;

Ua ntej lub

teeb ()

peb tsim qhov sib txawv los khaws tus nqi tam sim no nyeem los ntawm lub hwj chim. Nws hu ua

int ib

vim nws yog tus lej, lossis txhua tus lej.

void teeb tsa ()

{pinMode (A0, INPUT); pinMode (9, NTAWV); Serial.begin (9600); }

Sab hauv teeb, pins tau teeb tsa siv tus

pinMode ()

muaj nuj nqi Tus pin A0 tau teeb tsa ua lub tswv yim, yog li peb tuaj yeem "mloog" rau lub xeev hluav taws xob ntawm lub hwj chim. Tus pin 9 tau teeb tsa ua qhov tso tawm los tswj LED. Yuav kom tuaj yeem xa xov tau, Arduino qhib qhov kev sib txuas lus tshiab nrog rau

Serial.begin ()

uas siv qhov kev sib cav baud tus nqi (dab tsi nrawm los sib txuas lus), hauv qhov no 9600 ntsis ib ob.

void lub voj ()

{// nyeem tus nqi los ntawm lub sensor sensorValue = analogRead (A0); // luam lub sensor nyeem kom koj paub nws ntau yam Serial.println (sensorValue);

Ib yam dab tsi tom qab teeb tsa qhov slashes

//

yog lus tawm tswv yim, uas pab cov tib neeg nkag siab hauv cov lus yooj yim tias qhov haujlwm tau npaj yuav ua, tab sis tsis suav nrog hauv qhov haujlwm koj Arduino ua haujlwm. Hauv lub voj loj, muaj nuj nqi hu ua

analogRead ();

txheeb xyuas lub xeev tus pin A0 (uas yuav yog tus lej tag nrho los ntawm 0-1023), thiab khw muag khoom tus nqi hauv qhov sib txawv

sensorValue

// daim ntawv qhia lub sensor nyeem rau ntau yam rau LED

analogWrite (9, daim ntawv qhia (sensorValue, 0, 1023, 0, 255)); ncua (100); // Tos rau 100 millisecond (s)}

Kab tom qab cov lus pom tom ntej no ua ntau ntau ib zaug. Nco ntsoov

analogWrite ()

siv ob qhov kev sib cav, tus lej tus lej (9 hauv peb qhov xwm txheej), thiab tus nqi sau, uas yuav tsum nyob nruab nrab ntawm 0 thiab 255. Lub luag haujlwm hauv kab

daim ntawv qhia ()

siv tsib qhov kev sib cav: tus lej los tshuaj xyuas (qhov hloov pauv hloov pauv hloov pauv), qhov xav tau yam tsawg kawg thiab xav tau ntau tshaj, thiab qhov xav tau min thiab max. Yog li cov

daim ntawv qhia ()

ua haujlwm hauv peb cov ntaub ntawv yog tshuaj xyuas qhov ntsuas khoom nkag qhov muaj nuj nqis, thiab ua qee qhov hla kev sib npaug los ntsuas qhov tso tawm los ntawm 0-1023 txog 0-255. Cov txiaj ntsig tau xa rov qab mus rau qhov kev sib cav zaum thib ob ntawm

analogWrite ();

teeb qhov ci ci ntawm LED txuas nrog tus pin 9.

Kauj Ruam 4: Tsim Lub Cev Arduino Circuit (xaiv tau)

Tsim kom muaj lub cev Arduino Circuit (xaiv tau)
Tsim kom muaj lub cev Arduino Circuit (xaiv tau)

Txhawm rau teeb tsa koj lub cev Arduino Uno, koj yuav tsum teeb tsa software dawb (lossis txuas rau lub vev xaib khoos phis tawj), tom qab ntawd qhib nws. Ntau lub photocells muaj cov txiaj ntsig sib txawv, yog li yog tias koj lub cev siv hluav taws xob tsis ua haujlwm, koj yuav xav tau hloov tus tiv thaiv uas ua ke nrog nws. Kawm paub ntau ntxiv txog kev faib hluav taws xob hauv Cov Lus Qhia Hauv Chav Kawm Hluav Taws Xob qhia txog kev tiv thaiv.

Hlau txuas rau Arduino Uno Circuit los ntawm kev ntsaws rau hauv cov khoom sib txuas thiab cov xov hlau kom phim cov kev sib txuas uas pom ntawm no hauv Tinkercad Circuits. Yog xav paub ntau ntxiv-taug kev los ntawm kev ua haujlwm nrog koj lub cev Arduino Uno board, txheeb xyuas cov ntawv qhia dawb Arduino.

Luam cov cai los ntawm Tinkercad Circuits code lub qhov rai thiab muab nws tso rau hauv qhov kos duab khoob hauv koj li Arduino software, lossis nyem lub pob rub tawm (nqes mus rau xub xub xub) thiab qhib

qhov ua tiav cov ntaub ntawv siv ArduinoKoj tseem tuaj yeem pom qhov piv txwv no hauv Arduino software los ntawm kev mus rau File -> Piv txwv -> 03. Analog -> AnalogInOutSerial.

Txuas koj lub USB cable thiab xaiv koj lub rooj tsavxwm thiab chaw nres nkoj hauv software cov cuab yeej ntawv qhia zaub mov.

Tshaj tawm cov cai thiab siv koj txhais tes los npog lub sensor los ntawm kev tau txais lub teeb, thiab/lossis ua lub teeb ci ntawm koj lub sensor!

Qhib cov ntawv saib xyuas kom pom koj qhov txiaj ntsig sensor. Nws yuav zoo li lub ntiaj teb qhov tseem ceeb yuav tsis txuas ntxiv mus rau 0 lossis txhua txoj hauv kev rau 1023, nyob ntawm koj qhov teeb pom kev zoo. Xav tias dawb los kho 0-1023 ntau yam rau koj qhov kev pom tsawg kawg thiab pom qhov siab tshaj plaws txhawm rau kom tau txais qhov siab tshaj plaws qhov kev nthuav qhia ntau ntawm LED.

Kauj ruam 5: Tom ntej no, Sim…

Tam sim no koj tau kawm nyeem tus kws yees duab thiab qhia nws cov zis kom tswj tau qhov ci ntawm LED, koj npaj tau los siv cov ntawd thiab lwm yam txuj ci uas koj tau kawm txog tam sim no.

Koj puas tuaj yeem sib pauv tawm LED rau lwm hom kev tso tawm, zoo li lub tshuab servo, thiab tsim qee qhov cai los cuam tshuam rau lub ntsuas hluav taws xob tam sim no lub teeb pom kev zoo raws li qee txoj haujlwm nrog rau qhov ntsuas?

Sim hloov pauv koj tus kws kho qhov muag rau lwm cov tswv yim sib xws xws li lub ntsuas cua nrug deb deb lossis lub zog loj.

Kawm paub ntau ntxiv txog yuav ua li cas saib xyuas koj li Arduino's digital thiab analog inputs los ntawm lub khoos phis tawj siv Serial Monitor.

Pom zoo: