Cov txheej txheem:

Siv Qhov Kub, Dej Dej, thiab Kev Ruaj Ntseg ntawm Arduino los Tiv Thaiv Kev Tsheb nqaj hlau: 8 Kauj Ruam (nrog Duab)
Siv Qhov Kub, Dej Dej, thiab Kev Ruaj Ntseg ntawm Arduino los Tiv Thaiv Kev Tsheb nqaj hlau: 8 Kauj Ruam (nrog Duab)

Video: Siv Qhov Kub, Dej Dej, thiab Kev Ruaj Ntseg ntawm Arduino los Tiv Thaiv Kev Tsheb nqaj hlau: 8 Kauj Ruam (nrog Duab)

Video: Siv Qhov Kub, Dej Dej, thiab Kev Ruaj Ntseg ntawm Arduino los Tiv Thaiv Kev Tsheb nqaj hlau: 8 Kauj Ruam (nrog Duab)
Video: HMONG World Mosquito Destroyer 2024, Kaum ib hlis
Anonim
Siv Qhov Kub, Dej Dej, thiab Kev Ruaj Ntseg ntawm Arduino los tiv thaiv kev tsheb nqaj hlau
Siv Qhov Kub, Dej Dej, thiab Kev Ruaj Ntseg ntawm Arduino los tiv thaiv kev tsheb nqaj hlau

Hauv zej zog niaj hnub no, kev nce hauv cov neeg caij tsheb ciav hlau txhais tau tias cov tuam txhab tsheb nqaj hlau yuav tsum ua ntau ntxiv txhawm rau txhim kho cov kev sib txuas kom ua tau raws li qhov xav tau. Hauv qhov haujlwm no peb yuav qhia me me seb qhov kub thiab txias, dej nag, thiab kev co lub zog ntawm lub rooj tsav xwm arduino tuaj yeem pab txhawb kev nyab xeeb ntawm cov neeg caij tsheb.

Cov Lus Qhia no yuav qhia ib qib zuj zus qhia cov kab hluav taws xob rau qhov ntsuas kub, dej nag, thiab kev ntsuas kev co ntawm lub arduino nrog rau qhia MATLAB cov cai uas yuav tsum tau ua los ntsuas cov ntsuas no.

Kauj Ruam 1: Cov Khoom thiab Cov Khoom

1. Lub khoos phis tawj nrog kho qhov tseeb ntawm MATLAB tau teeb tsa

2. Pawg Tswj Xyuas Arduino

3. Kub Sensor

4. Dej nag Sensor

5. Kev co kev co

6. Liab LED Teeb

7. Xiav LED Teeb

8. Ntsuab LED Teeb

9. RBG LED Teeb

10. Buzzer

11. 18 Txiv neej-Txiv neej Hluav Taws Xob

12. 3 Poj niam-Txiv neej Hluav Taws Xob

13. 2 Poj Niam-Poj Niam Hluav Taws Xob

14. 6 330 ohm resistors

15. 1 100 ohm resistor

Kauj Ruam 2: Kev ntsuas qhov ntsuas kub

Kub Sensor thaiv
Kub Sensor thaiv
Kub Sensor thaiv
Kub Sensor thaiv

Saum toj no yog cov xov hlau thiab MATLAB tus lej rau qhov ntsuas qhov ntsuas kub ib yam nkaus.

Cov xov hlau los ntawm hauv av thiab 5V tsuas yog yuav tsum tau khiav mus rau qhov tsis zoo thiab zoo ib feem ib zaug rau tag nrho pawg thawj coj saib. Los ntawm no tawm, ib qho kev sib txuas hauv av yuav los ntawm kab ntawv tsis zoo thiab ib qho 5V kev sib txuas yuav los ntawm kab ntawv zoo.

Cov cai hauv qab no tuaj yeem luam tawm thiab muab tso rau qhov ntsuas kub.

%% TEMPERATURE SENSOR % Rau qhov ntsuas kub peb siv cov hauv qab no nrog rau

% EF230 lub vev xaib cov khoom siv los hloov peb lub ntsuas kub kom tso cai rau cov neeg siv

% cov tswv yim thiab 3 LED teeb pom kev zoo nrog lub teeb.

%Cov duab no tau sau los ntawm SparkFun Electronics, %nrog ntau qhov kev pab los ntawm zej zog Arduino.

%Hloov kho rau MATLAB los ntawm Eric Davishahl.

%Mus ntsib https://learn.sparkfun.com/products/2 rau SIK cov ntaub ntawv.

tshem txhua, clc

tempPin = 'A0'; Tshaj tawm qhov tus pin analog txuas nrog lub ntsuas kub

a = arduino ('/dev/tty.usbserial-DA017PNO', 'uno');

% Txhais cov haujlwm tsis qhia npe uas hloov qhov hluav taws xob mus rau qhov kub thiab txias

tempCfromVolts = @(volts) (volts-0.5)*100;

samplingDuration = 30;

samplingInterval = 2; % Cov vib nas this ntawm qhov ntsuas kub

%teeb tsa vector ntawm sijhawm piv txwv

samplingTimes = 0: samplingInterval: samplingDuration;

%xam tus naj npawb ntawm cov qauv raws li lub sijhawm thiab ntu

numSamples = ntev (samplingTimes);

%preallocate temp hloov pauv thiab hloov pauv rau tus lej nyeem nws yuav khaws cia

tempC = zeros (numSamples, 1);

tempF = tempC;

% siv lub thawv sib tham los khaws qhov kub thiab txias tsheb nqaj hlau

dlg_prompts = {'Sau Max Temp', 'Sau Min Temp'};

dlg_title = 'Lub Sijhawm Kub Npav Rail';

N = 22;

dlg_ans = inputdlg (dlg_prompts, dlg_title, [1, ntev (dlg_title)+N]);

% Khaws cov tswv yim nkag los ntawm tus neeg siv thiab tso tawm tias cov ntaub ntawv tau sau tseg

max_temp = str2double (dlg_ans {1})

min_temp = str2double (dlg_ans {2})

txt = sprintf ('Koj lub tswv yim tau raug kaw');

h = msgbox (txt);

tos rau (h);

% Rau lub voj los nyeem qhov kub tshwj xeeb pes tsawg zaus.

rau qhov ntsuas = 1: numSamples

% Nyeem qhov hluav taws xob ntawm tempPin thiab khaws cia raws li qhov sib txawv volts

volts = readVoltage (a, tempPin);

tempC (ntsuas) = tempCfromVolts (volts);

tempF (index) = tempC (index)*9/5+32; % Hloov los ntawm Celsius mus Fahrenheit

% Yog tias cov lus hais kom ua tshwj xeeb teeb LED ntsais muag nyob ntawm seb qhov xwm txheej tau ntsib

yog tempF (index)> = max_temp % Liab LED

writeDigitalPin (a, 'D13', 0);

ncua (0.5);

writeDigitalPin (a, 'D13', 1);

ncua (0.5);

writeDigitalPin (a, 'D13', 0);

elseif tempF (index)> = min_temp && tempF (index) <max_temp % Ntsuab LED

writeDigitalPin (a, 'D11', 0);

ncua (0.5);

writeDigitalPin (a, 'D11', 1);

ncua (0.5);

writeDigitalPin (a, 'D11', 0);

elseif tempF (qhov ntsuas) <= min_temp % Blue LED

writeDigitalPin (a, 'D12', 0);

ncua (0.5);

writeDigitalPin (a, 'D12', 1);

ncua (0.5);

writeDigitalPin (a, 'D12', 0);

kawg

% Muab cov ntsuas kub raws li lawv tau ntsuas

fprintf ('Kub ntawm %d vib nas this yog %5.2f C lossis %5.2f F. / n', …

samplingTimes (ntsuas), tempC (ntsuas), tempF (ntsuas));

ncua (samplingInterval) %ncua mus txog rau qhov piv txwv tom ntej

kawg

Plotting qhov ntsuas kub

daim duab (1)

phiaj (samplingTimes, tempF, 'r-*')

xlabel ('Sijhawm (Thib Ob)'))

ylabel ('Kub (F)')

lub npe ('Kev Ntsuas Kub los ntawm RedBoard')

Kauj Ruam 3: Kub Sensor Tso Tawm

Kub Sensor Tso Tawm
Kub Sensor Tso Tawm
Kub Sensor Tso Tawm
Kub Sensor Tso Tawm

Saum toj no yog cov xov hlau thiab MATLAB code rau qhov ntsuas qhov ntsuas kub.

Rau qhov haujlwm no peb siv peb lub teeb ci LED rau qhov tso tawm ntawm peb qhov ntsuas kub. Peb siv liab rau yog tias cov ciav hlau kub dhau, xiav yog tias lawv txias dhau, thiab ntsuab yog tias lawv nyob nruab nrab.

Kauj Ruam 4: Cov Dej Dej Dej Dej Dej Dej

Dej Dej Dej Dej Sensor
Dej Dej Dej Dej Sensor
Dej Dej Dej Dej Sensor
Dej Dej Dej Dej Sensor

Saum toj no yog qhov txuas rau lub ntsuas dej nag thiab MATLAB cov cai tau tshaj tawm hauv qab no.

%% Dej ntsuas dej

tshem txhua, clc

a = arduino ('/dev/tty.usbserial-DA017PNO', 'uno');

waterPin = 'A1';

vDry = 4.80; % Voltage thaum tsis muaj dej tam sim no

samplingDuration = 60;

samplingInterval = 2;

samplingTimes = 0: samplingInterval: samplingDuration;

numSamples = ntev (samplingTimes);

% Rau lub voj los nyeem qhov hluav taws xob rau lub sijhawm tshwj xeeb (60 vib nas this)

rau qhov ntsuas = 1: numSamples

volt2 = nyeemVoltage (a, waterPin); % Nyeem qhov ntsuas hluav taws xob los ntawm tus pin dej sib piv

% Yog cov lus hais kom nrov lub suab nrov yog tias pom muaj dej. Voltage poob = dej

yog volt2 <vDry

playTone (a, 'D09', 2400) % playTone muaj nuj nqi los ntawm MathWorks

% Tso lus ceeb toom rau cov neeg caij tsheb yog pom muaj dej

tos rau (warndlg ('Koj lub tsheb ciav hlau yuav qeeb vim muaj dej txaus ntshai'));

kawg

% Qhia qhov hluav taws xob raws li nws ntsuas los ntawm cov ntsuas dej

fprintf ('Voltage ntawm %d vib nas this yog %5.4f V. / n', …

samplingTimes (ntsuas), volt2);

ncua (samplingInterval)

kawg

Kauj Ruam 5: Dej Tso Dej Los Dej

Dej Dej Dej Tso Tawm
Dej Dej Dej Tso Tawm

Saum toj no yog qhov txuas rau lub suab nrov uas nrov thaum twg dej ntau dhau los ntawm txoj kev. Cov cai rau lub buzzer tau teeb tsa hauv cov cai rau cov dej nag nkag.

Kauj Ruam 6: Kev Nkag Mus Nkag Siab Sensor

Kev co Sensor Input
Kev co Sensor Input
Kev co Sensor Input
Kev co Sensor Input

Saum toj no yog qhov thaiv rau qhov kev co co. Kev ntsuas kev co tuaj yeem yog qhov tseem ceeb rau kev tsheb nqaj hlau thaum poob pob zeb ntawm txoj kev taug. MATLAB code tau tshaj tawm hauv qab no.

%% Kev Ruaj Ntseg Sensorclear tag nrho, clc

PIEZO_PIN = 'A3'; % Tshaj tawm tus lej sib piv txuas nrog lub ntsuas kev co a = arduino ('/dev/tty.usbserial-DA017PNO', 'uno'); % Pib ua ntej lub sijhawm thiab ncua sijhawm los ntsuas kev ntsuas qhov ntsuas = 30; % Seconds samplingInterval = 1;

samplingTimes = 0: samplingInterval: samplingDuration;

numSamples = ntev (samplingTimes);

% Siv cov cai los ntawm cov hauv qab no peb tau hloov kho nws kom qhib a

% ntshav liab yog tias pom muaj kev vibration.

% SparkFun Tinker Kit, RGB LED, sau los ntawm SparkFun Electronics, % nrog ntau qhov kev pab los ntawm zej zog Arduino

% Hloov kho rau MATLAB los ntawm Eric Davishahl

% Pib ua tus pin RGB

RED_PIN = 'D5';

GREEN_PIN = 'D6';

BLUE_PIN = 'D7';

% Rau lub voj los sau qhov hloov pauv hloov pauv los ntawm qhov ntsuas qhov ntsuas siab dua a

% lub sijhawm tshwj xeeb (30 vib nas this)

rau qhov ntsuas = 1: numSamples

volt3 = readVoltage (a, PIEZO_PIN);

% Yog cov lus hais kom tig lub teeb liab LED rau yog pom tias muaj kev vibration

Yog tias volt3> 0.025

writeDigitalPin (a, RED_PIN, 1);

% Tsim lub teeb ntshav

writeDigitalPin (a, GREEN_PIN, 0);

writeDigitalPin (a, BLUE_PIN, 1);

lwm tus % Tua LED yog tias tsis pom kev co.

writeDigitalPin (a, RED_PIN, 0);

writeDigitalPin (a, GREEN_PIN, 0);

writeDigitalPin (a, BLUE_PIN, 0);

kawg

% Qhia qhov hluav taws xob raws li nws tau ntsuas.

fprintf ('Voltage ntawm %d vib nas this yog %5.4f V. / n', …

samplingTimes (ntsuas), volt3);

ncua (samplingInterval)

kawg

Txiav tawm lub teeb thaum ntsuas kev co ua tiav

writeDigitalPin (a, RED_PIN, 0);

writeDigitalPin (a, GREEN_PIN, 0);

writeDigitalPin (a, BLUE_PIN, 0);

Kauj Ruam 7: Kev Tawm Tsam Sensor

Kev co Sensor tso zis
Kev co Sensor tso zis

Saum toj no yog cov thaiv rau RBG LED teeb siv. Lub teeb yuav ci liab thaum pom kev co. MATLAB cov cai rau cov zis tau kos rau hauv cov cai rau kev nkag mus.

Kauj Ruam 8: Xaus

Tom qab ua raws txhua theem no koj yuav tsum tam sim no muaj arduino nrog lub peev xwm los ntsuas qhov ntsuas kub, dej nag, thiab kev co. Thaum saib yuav ua li cas cov ntsuas hluav taws xob ua haujlwm ntawm qhov ntsuas me me, nws yog qhov yooj yim los xav txog qhov tseem ceeb lawv tuaj yeem yog txoj hauv kev tsheb ciav hlau hauv lub neej niaj hnub!

Pom zoo: