Cov txheej txheem:

Arduino Led/Strips RGB Bluetooth (Arduino + App Inventor): 5 Kauj Ruam
Arduino Led/Strips RGB Bluetooth (Arduino + App Inventor): 5 Kauj Ruam

Video: Arduino Led/Strips RGB Bluetooth (Arduino + App Inventor): 5 Kauj Ruam

Video: Arduino Led/Strips RGB Bluetooth (Arduino + App Inventor): 5 Kauj Ruam
Video: (Demo) Arduino RGB LED Control Android App with MIT App Inventor 2024, Hlis ntuj nqeg
Anonim
Arduino Led/Strips RGB Bluetooth (Arduino + App Inventor)
Arduino Led/Strips RGB Bluetooth (Arduino + App Inventor)
Arduino Led/Strips RGB Bluetooth (Arduino + App Inventor)
Arduino Led/Strips RGB Bluetooth (Arduino + App Inventor)
Arduino Led/Strips RGB Bluetooth (Arduino + App Inventor)
Arduino Led/Strips RGB Bluetooth (Arduino + App Inventor)

Hauv qhov kev qhia no kuv yuav qhia siv App Inventor thiab txuas nws nrog arduino siv bluetooth

Kauj Ruam 1: Yam Koj Xav Tau thiab Schematic

Yam Koj Xav Tau thiab Schematic
Yam Koj Xav Tau thiab Schematic
Yam Koj Xav Tau thiab Schematic
Yam Koj Xav Tau thiab Schematic
Yam Koj Xav Tau thiab Schematic
Yam Koj Xav Tau thiab Schematic

Zoo qhov no yog cov npe raws li usuall tsis muaj dab tsi hloov pauv yog tias koj nyob ntawm no rau tsab ntawv tsuas yog scroll nws

  1. Kev sib txuas hauv internet
  2. Xov tooj Android (tau kawg)
  3. Sau npe nws dawb (tsis nce qib) App Inventor
  4. Arduino + Bluetooth module
  5. LED/Sawb RGB
  6. Resistor 100/200/330

Kauj Ruam 2: Arduino Code Tshaj Tawm thiab teeb tsa

Ua ntej tshaj tawm qhov hloov pauv, tus lej chaw nres nkoj, thiab lwm yam (Hloov "nrog <)

#suav nrog "SoftwareSerial.h"

#suav nrog "Wire.h" SoftwareSerial BT (10, 11);

Kuv tab tom siv chaw nres nkoj 7 thiab 8 ua RX TX, nco ntsoov yog tias koj xav txuas lub bluetooth module kom ntseeg tau tus pin RX module txuas rau tus pin TX.

int LED_RED = 3;

int LED_GREEN = 5; int LED_BLUE = 6; Txoj hlua cov ntaub ntawv = ""; Txoj hlua data_Previous = "255.255.255"; Txoj hlua ON = "LON"; Txoj hlua OFF = "LOFF"; boolean state = cuav;

tsab ntawv tom ntej yog kom paub tseeb tias tus pin ntawm RGB LED/Stips mus rau tus pin PWM

void teeb tsa ()

{pinMode (LED_RED, OUTPUT); pinMode (LED_GREEN, pinMode (LED_BLUE, OUTPUT); Serial.begin (9600); BT.begin (9600); data.reserve (30);}

Raws li koj tuaj yeem pom kuv lub npe chaw nres nkoj rau bluetooth li BT yog li tshaj tawm nws zoo li Serial li qub, nco ntsoov tias lub suab nrov zoo ib yam li kev teeb tsa ntawm tus qauv (lub neej ntawd yog 9600).

Kauj Ruam 3: Arduino Code (Txoj Cai Tseem Ceeb)

INSIDE VOID LOOP

thaum (BT.available ())

{char ReadChar = (char) BT.read (); Serial.println ("Txuas"); yog (ReadChar == '+') {xeev = tseeb; } lwm {data += ReadChar; }}

Tsab ntawv rau tshuaj xyuas lub bluetooth module txuas lossis tsis tau, yog txuas nrog nws yuav tau txais cov ntaub ntawv thiab khaws nws rau ReadChar.

yog (xeev)

{Serial.print ("cov ntaub ntawv:"); Serial.print (cov ntaub ntawv); Serial.print ("Predata:"); Serial.print (data_Previous); yog (data == ON) {data = data_Previous; Cov ntaub ntawv_LED (); } lwm yog (cov ntaub ntawv == OFF) {cov ntaub ntawv = "0.0.0"; Cov ntaub ntawv_LED (); } lwm {Data_LED (); data_Previous = cov ntaub ntawv; } cov ntaub ntawv = ""; xeev = cuav; }

qhov no yog ntu kawg ntawm lub voj void, yog tias lub xeev kom ntseeg tau tias cov ntaub ntawv tiav yog tias tsis tau khiav sab hauv nws.

FUNCTION DATA LED

int seperator1 = data.indexOf ('-');

int seperator2 = data.indexOf ('-', seperator1+1); int seperator3 = data.indexOf ('-', seperator2+1);

ib feem no nws yog cov cai tseem ceeb, vim tias tau txais ib txoj hlua nws yuav tsum paub qhov sib cais nyob qhov twg. Nws tsis tuaj yeem pom qhov tseem ceeb ntawm RGB qis dua 50, siv qhov ntsuas tawm ntawm nws nws yuav pom tus naj npawb ntawm cov char peb tshawb nrog qhov no peb tuaj yeem paub tus lej twg los pib ua haujlwm hloov pauv.

Txoj hlua R = data.substring (0, seperator1);

Txoj hlua G = data.substring (seperator1+1, seperator2); Txoj hlua B = data.substring (seperator2+1, seperator3);

Tom qab tau txais qhov zoo ntawm txhua qhov txiaj ntsig, subString muaj nuj nqi yuav ua rau txhua tus lej rau txhua qhov sib txawv, cais cais kom paub tseeb tias tsis tau nyeem tus nqi ua ntej nws.

Kauj ruam 4: App Inventor

App Tus Tsim Tawm
App Tus Tsim Tawm
App Tus Tsim Tawm
App Tus Tsim Tawm

Qhov kev pabcuam no yuav ua rau pib (zoo li kuv) yooj yim dua los ua hauv app tsuas yog xav tau kev xav, ua siab ntev thiab siv internet

Ua ntej ua GUI yooj yim

Pib npaj lossis ntsuas qhov teeb tsa, muaj ob qho uas kuv tau ua dub yog thawj zaug thiab dawb yog thib ob

2nd qhib MIT APP lossis nyem qhov no

  1. Puas yog cov kauj ruam no nyem Tsim cov apps! ntawm kaum kaum
  2. Pib txoj haujlwm tshiab
  3. Ntaus lub npe
  4. Pib tsim

Yog tias koj siv kuv lub hauv paus nyem Cov Haujlwm thiab xaiv ntshuam aia

Taw qhia

Ntawm qhov kev pabcuam no koj xav tau lub laj thawj vim tias rau txhua cov ntsiab lus muaj lawv tus kheej xim thiab piav qhia tsuas yog tshawb yog tias tsis nkag siab, nws tsis nyuaj yog tias koj paub nrog tsab ntawv/coding.

Lub ntsiab yog lub log xim thiab cov neeg siv bluetooth, ntawm no yog qhov kev piav qhia

LOJ LOJ

  1. Lub log xim tau txais tus nqi los ntawm kev ntes tus ntiv tes qhov nws kov
  2. Cursor yuav ua raws tus ntiv tes nco qab tus cursor qee zaum tsis ua tiav nrog cov phiaj
  3. Cursor yuav tau txais tus nqi X thiab Y thiab
  4. Tus nqi no yuav siv los ntawm kev ua haujlwm ntawm getBackgroundPixelColour, ib puag ncig zoo li cov xim xaiv ntawm lwm cov ntawv
  5. Muaj 3 qhov tseem ceeb (Liab, Ntsuab, Xiav) txhua tus nqi sib cais los ntawm cov npe (pib los ntawm 1)
  6. Qhov ntawd yog txoj hauv kev yooj yim los ua xim log

BLUETOOTH

  1. Tom qab tau txais tus nqi thiab xa nws los ntawm kev ntxiv - rau txhua tus cim thiab ntxiv + thaum kawg siv kev lom zem ntawm kev koom nrog
  2. Xa nws mus rau xov tooj

Kauj ruam 5: Kev sib cav

Thov txim rau kuv cov lus Askiv tsis zoo, kuv tau sim thiab pom qhov teeb meem nrog kuv RGB LED (Lub diode liab yuav tsis tshwm rau qhov xwm txheej zoo kuv siv 100R). Kuv yuav ua tus RGB Sawb yog tias muaj, kuv sim 3trd version kuv lub dav hlau los ua kom muaj ntau yam zoo li tog teeb pom kev, teeb pom kev tog thiab txhim kho qee yam.

Yog tias nws ua haujlwm tiag tiag yog tias tsis kho kuv ib yam. Zoo Siab Coding ^^

Pom zoo: